1
0
forked from VimPlug/jedi

Merge branch 'master' into typeshed

There were quite a few conflicts, because there were two rewrites of the path
to dotted function.
This commit is contained in:
Dave Halter
2019-03-01 10:03:17 +01:00
12 changed files with 65 additions and 34 deletions

View File

@@ -10,7 +10,8 @@ import pytest
from jedi._compatibility import find_module_py33, find_module
from jedi.evaluate import compiled
from jedi.evaluate import imports
from ..helpers import cwd_at
from jedi.api.project import Project
from ..helpers import cwd_at, get_example_dir
THIS_DIR = os.path.dirname(__file__)
@@ -272,3 +273,18 @@ def test_get_modules_containing_name(evaluator, path, goal):
)
assert input_module is module
assert found_module.string_names == goal
@pytest.mark.parametrize(
'path', ('api/whatever/test_this.py', 'api/whatever/file'))
def test_relative_imports_with_multiple_similar_directories(Script, path):
dir = get_example_dir('issue1209')
script = Script(
"from .",
path=os.path.join(dir, path)
)
# TODO pass this project to the script as a param once that's possible.
script._evaluator.project = Project(dir)
name, import_ = script.completions()
assert import_.name == 'import'
assert name.name == 'api_test1'

View File

@@ -63,17 +63,34 @@ def test_venv_and_pths(venv_path):
assert not set(sys.path).intersection(ETALON)
@pytest.mark.parametrize(('sys_path_', 'path', 'expected'), [
(['/foo'], '/foo/bar.py', ('bar',)),
(['/foo'], '/foo/bar/baz.py', ('bar', 'baz')),
(['/foo'], '/foo/bar/__init__.py', ('bar',)),
(['/foo'], '/foo/bar/baz/__init__.py', ('bar', 'baz')),
_s = ['/a', '/b', '/c/d/']
(['/foo'], '/foo/bar.so', ('bar',)),
(['/foo'], '/foo/bar/__init__.so', ('bar',)),
(['/foo'], '/x/bar.py', None),
(['/foo'], '/foo/bar.xyz', None),
])
def test_calculate_dotted_path_from_sys_path(path, sys_path_, expected):
assert sys_path.calculate_dotted_path_from_sys_path(sys_path_, path) == expected
@pytest.mark.parametrize(
'sys_path_, module_path, result', [
(_s, '/a/b', ('b',)),
(_s, '/a/b/c', ('b', 'c')),
(_s, '/a/b.py', ('b',)),
(_s, '/a/b/c.py', ('b', 'c')),
(_s, '/x/b.py', None),
(_s, '/c/d/x.py', ('x',)),
(_s, '/c/d/x.py', ('x',)),
(_s, '/c/d/x/y.py', ('x', 'y')),
# If dots are in there they also resolve. These are obviously illegal
# in Python, but Jedi can handle them. Give the user a bit more freedom
# that he will have to correct eventually.
(_s, '/a/b.c.py', ('b.c',)),
(_s, '/a/b.d/foo.bar.py', ('b.d', 'foo.bar')),
(_s, '/a/.py', None),
(_s, '/a/c/.py', None),
(['/foo'], '/foo/bar/__init__.py', ('bar',)),
(['/foo'], '/foo/bar/baz/__init__.py', ('bar', 'baz')),
(['/foo'], '/foo/bar.so', ('bar',)),
(['/foo'], '/foo/bar/__init__.so', ('bar',)),
(['/foo'], '/x/bar.py', None),
(['/foo'], '/foo/bar.xyz', ('bar.xyz',)),
])
def test_calculate_dotted_from_path(sys_path_, module_path, result):
assert sys_path.transform_path_to_dotted(sys_path_, module_path) == result