Merge branch 'master' into relative-import

This commit is contained in:
Dave Halter
2020-12-12 12:15:13 +01:00
24 changed files with 223 additions and 44 deletions

View File

@@ -370,3 +370,35 @@ def test_multi_goto(Script):
y, = script.goto(line=4)
assert x.line == 1
assert y.line == 2
@pytest.mark.parametrize(
'code, column, expected', [
('str() ', 3, 'str'),
('str() ', 4, 'str'),
('str() ', 5, 'str'),
('str() ', 6, None),
('str( ) ', 6, None),
(' 1', 1, None),
('str(1) ', 3, 'str'),
('str(1) ', 4, 'int'),
('str(1) ', 5, 'int'),
('str(1) ', 6, 'str'),
('str(1) ', 7, None),
('str( 1) ', 4, 'str'),
('str( 1) ', 5, 'int'),
('str(+1) ', 4, 'str'),
('str(+1) ', 5, 'int'),
('str(1, 1.) ', 3, 'str'),
('str(1, 1.) ', 4, 'int'),
('str(1, 1.) ', 5, 'int'),
('str(1, 1.) ', 6, None),
('str(1, 1.) ', 7, 'float'),
]
)
def test_infer_after_parentheses(Script, code, column, expected):
completions = Script(code).infer(column=column)
if expected is None:
assert completions == []
else:
assert [c.name for c in completions] == [expected]

View File

@@ -513,10 +513,14 @@ def test_added_equals_to_params(Script):
assert run('foo(bar').name_with_symbols == 'bar='
assert run('foo(bar').complete == '='
assert run('foo(bar').get_completion_prefix_length() == 3
assert run('foo(bar, baz').complete == '='
assert run('foo(bar, baz').get_completion_prefix_length() == 3
assert run(' bar').name_with_symbols == 'bar'
assert run(' bar').complete == ''
assert run(' bar').get_completion_prefix_length() == 3
x = run('foo(bar=isins').name_with_symbols
assert run('foo(bar=isins').get_completion_prefix_length() == 5
assert x == 'isinstance'

View File

@@ -6,6 +6,7 @@ import pytest
from ..helpers import get_example_dir, set_cwd, root_dir, test_dir
from jedi import Interpreter
from jedi.api import Project, get_default_project
from jedi.api.project import _is_potential_project, _CONTAINS_POTENTIAL_PROJECT
def test_django_default_project(Script):
@@ -160,3 +161,21 @@ def test_complete_search(Script, string, completions, all_scopes):
project = Project(test_dir)
defs = project.complete_search(string, all_scopes=all_scopes)
assert [d.complete for d in defs] == completions
@pytest.mark.parametrize(
'path,expected', [
(Path(__file__).parents[2], True), # The path of the project
(Path(__file__).parents[1], False), # The path of the tests, not a project
(Path.home(), None)
]
)
def test_is_potential_project(path, expected):
if expected is None:
try:
expected = _CONTAINS_POTENTIAL_PROJECT in os.listdir(path)
except OSError:
expected = False
assert _is_potential_project(path) == expected