Merge branch 'dev' of github.com:davidhalter/jedi into dev

This commit is contained in:
Dave Halter
2014-02-21 17:52:44 +01:00
11 changed files with 110 additions and 6 deletions

View File

@@ -31,11 +31,18 @@ def find_module_py33(string, path=None):
module_file = None module_file = None
else: else:
module_path = loader.get_filename(string) module_path = loader.get_filename(string)
module_file = open(module_path) mode = 'rb' if module_path.endswith(".pyc") else 'r'
module_file = open(module_path, mode)
except AttributeError:
# ExtensionLoader has not attribute get_filename, instead it has a
# path attribute that we can use to retrieve the module path
try:
module_path = loader.path
module_file = open(loader.path, 'rb')
except AttributeError: except AttributeError:
# is builtin module
module_path = string module_path = string
module_file = None module_file = None
finally:
is_package = False is_package = False
return module_file, module_path, is_package return module_file, module_path, is_package

View File

@@ -2,7 +2,7 @@
addopts = --doctest-modules addopts = --doctest-modules
# Ignore broken files in blackbox test directories # Ignore broken files in blackbox test directories
norecursedirs = .* docs completion refactor absolute_import namespace_package scripts norecursedirs = .* docs completion refactor absolute_import namespace_package scripts extensions
# Activate `clean_jedi_cache` fixture for all tests. This should be # Activate `clean_jedi_cache` fixture for all tests. This should be
# fine as long as we are using `clean_jedi_cache` as a session scoped # fine as long as we are using `clean_jedi_cache` as a session scoped

View File

@@ -0,0 +1,10 @@
This directory contains pre-compiled extensions modules used to test completions
for compiled modules on Travis-CI (Ubuntu 12.04 64bit).
To build the extensions modules, run::
python setup.py build_ext -i
Then move the compiled modules to their testing package ( ./**compiledXX**, where XX is the
python version used to run setup.py).

View File

@@ -0,0 +1,6 @@
cdef class Foo:
pass
cdef class Bar:
pass

View File

Binary file not shown.

View File

Binary file not shown.

6
test/extensions/setup.py Normal file
View File

@@ -0,0 +1,6 @@
from distutils.core import setup
from Cython.Build import cythonize
setup(
ext_modules=cythonize("compiled.pyx")
)

19
test/test_compiled.py Normal file
View File

@@ -0,0 +1,19 @@
"""
Test compiled module
"""
import os
import platform
import sys
import jedi
from .helpers import cwd_at
@cwd_at('test/extensions')
def test_compiled():
if platform.architecture()[0] == '64bit':
package_name = "compiled%s%s" % sys.version_info[:2]
sys.path.insert(0, os.getcwd())
if os.path.exists(package_name):
s = jedi.Script("from %s import compiled; compiled." % package_name)
assert len(s.completions()) >= 2

56
test/test_pyc.py Normal file
View File

@@ -0,0 +1,56 @@
"""
Test completions from *.pyc files:
- generate a dummy python module
- compile the dummy module to generate a *.pyc
- delete the pure python dummy module
- try jedi on the generated *.pyc
"""
import compileall
import os
import shutil
import sys
import jedi
SRC = """class Foo:
pass
class Bar:
pass
"""
def generate_pyc():
os.mkdir("dummy_package")
with open("dummy_package/__init__.py", 'w'):
pass
with open("dummy_package/dummy.py", 'w') as f:
f.write(SRC)
compileall.compile_file("dummy_package/dummy.py")
os.remove("dummy_package/dummy.py")
if sys.version_info[0] == 3:
# Python3 specific:
# To import pyc modules, we must move them out of the __pycache__
# directory and rename them to remove ".cpython-%s%d"
# see: http://stackoverflow.com/questions/11648440/python-does-not-detect-pyc-files
for f in os.listdir("dummy_package/__pycache__"):
dst = f.replace('.cpython-%s%s' % sys.version_info[:2], "")
dst = os.path.join("dummy_package", dst)
shutil.copy(os.path.join("dummy_package/__pycache__", f), dst)
def test_pyc():
"""
The list of completion must be greater than 2.
"""
generate_pyc()
s = jedi.Script("from dummy_package import dummy; dummy.")
assert len(s.completions()) >= 2
shutil.rmtree("dummy_package")
if __name__ == "__main__":
test_pyc()