1
0
forked from VimPlug/jedi

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

This commit is contained in:
Dave Halter
2014-07-21 17:40:25 +02:00
14 changed files with 63 additions and 80 deletions

View File

@@ -15,6 +15,13 @@ from jedi.evaluate.helpers import FakeName
from . import fake
_sep = os.path.sep
if os.path.altsep is not None:
_sep += os.path.altsep
_path_re = re.compile('(?:\.[^{0}]+|[{0}]__init__\.py)$'.format(re.escape(_sep)))
del _sep
class CompiledObject(Base):
# comply with the parser
start_pos = 0, 0
@@ -220,21 +227,27 @@ def dotted_from_fs_path(fs_path, sys_path=None):
compares the path with sys.path and then returns the dotted_path. If the
path is not in the sys.path, just returns None.
"""
sep = os.path.sep
shortest = None
if sys_path is None:
sys_path = get_sys_path()
# prefer
# - UNIX
# /path/to/pythonX.Y/lib-dynload
# /path/to/pythonX.Y/site-packages
# - Windows
# C:\path\to\DLLs
# C:\path\to\Lib\site-packages
# over
# - UNIX
# /path/to/pythonX.Y
# - Windows
# C:\path\to\Lib
path = ''
for s in sys_path:
if fs_path.startswith(s):
path = fs_path[len(s):].strip(sep)
path = re.sub('\.[^%s]*|%s__init__.py$' % (sep, sep), '', path)
dotted = path.split(sep)
dotted = '.'.join(dotted)
# At this point dotted could be both `lib-dynload.datetime` and
# `datetime`. The shorter one is typically the module we want.
if shortest is None or len(shortest) > len(dotted):
shortest = dotted
return shortest
if (fs_path.startswith(s) and
len(path) < len(s)):
path = s
return _path_re.sub('', fs_path[len(path):].lstrip(os.path.sep)).replace(os.path.sep, '.')
def load_module(path, name):

View File

@@ -103,7 +103,8 @@ class ImportWrapper(pr.Base):
names += self._get_module_names([path])
if self._is_relative_import():
rel_path = self._importer.get_relative_path() + '/__init__.py'
rel_path = os.path.join(self._importer.get_relative_path(),
'__init__.py')
if os.path.exists(rel_path):
m = _load_module(rel_path)
names += m.get_defined_names()
@@ -459,7 +460,7 @@ class _Importer(object):
if is_package_directory or current_namespace[0]:
# is a directory module
if is_package_directory:
path += '/__init__.py'
path = os.path.join(path, '__init__.py')
with open(path, 'rb') as f:
source = f.read()
else:

View File

@@ -139,7 +139,7 @@ class IntegrationTestCase(object):
@property
def module_name(self):
return re.sub('.*/|\.py$', '', self.path)
return os.path.splitext(os.path.basename(self.path))[0]
@property
def line_nr_test(self):

View File

@@ -1,10 +0,0 @@
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

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

View File

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

View File

@@ -1,12 +1,12 @@
import os
from ..helpers import cwd_at
from jedi._compatibility import u
from jedi.evaluate.sys_path import (_get_parent_dir_with_file,
_get_buildout_scripts,
_check_module)
from jedi.parser import Parser
from jedi.evaluate.sys_path import (
_get_parent_dir_with_file,
_get_buildout_scripts,
_check_module
)
from ..helpers import cwd_at
@cwd_at('test/test_evaluate/buildout_project/src/proj_name')
@@ -14,7 +14,7 @@ def test_parent_dir_with_file():
parent = _get_parent_dir_with_file(
os.path.abspath(os.curdir), 'buildout.cfg')
assert parent is not None
assert parent.endswith('test/test_evaluate/buildout_project')
assert parent.endswith(os.path.join('test', 'test_evaluate', 'buildout_project'))
@cwd_at('test/test_evaluate/buildout_project/src/proj_name')

View File

@@ -2,41 +2,30 @@
Test compiled module
"""
import os
import platform
import sys
import jedi
from ..helpers import cwd_at
@cwd_at('test/test_evaluate/extensions')
def test_completions():
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
s = jedi.Script('import _ctypes; _ctypes.')
assert len(s.completions()) >= 15
@cwd_at('test/test_evaluate/extensions')
def test_call_signatures_extension():
# with a cython extension
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.Foo(" %
package_name)
defs = s.call_signatures()
for call_def in defs:
for param in call_def.params:
pass
if os.name == 'nt':
func = 'LoadLibrary'
params = 1
else:
func = 'dlopen'
params = 2
s = jedi.Script('import _ctypes; _ctypes.%s(' % (func,))
sigs = s.call_signatures()
assert len(sigs) == 1
assert len(sigs[0].params) == params
def test_call_signatures_stdlib():
code = "import math; math.cos("
s = jedi.Script(code)
defs = s.call_signatures()
for call_def in defs:
assert len(call_def.params) == 1
s = jedi.Script('import math; math.cos(')
sigs = s.call_signatures()
assert len(sigs) == 1
assert len(sigs[0].params) == 1

View File

@@ -1,10 +1,7 @@
from jedi import parser
from jedi._compatibility import u
from jedi import parser
try:
import unittest2 as unittest
except ImportError: # pragma: no cover
import unittest
from ..helpers import unittest
class TokenTest(unittest.TestCase):

View File

@@ -1,10 +1,15 @@
import readline
try:
import readline
except ImportError:
readline = False
from jedi import utils
from .helpers import TestCase, cwd_at
from .helpers import unittest, cwd_at
class TestSetupReadline(TestCase):
@unittest.skipIf(not readline, "readline not found")
class TestSetupReadline(unittest.TestCase):
class NameSpace(object):
pass