forked from VimPlug/jedi
Merge branch 'master' into deprecations
This commit is contained in:
@@ -15,7 +15,7 @@ from test.helpers import test_dir, get_example_dir
|
||||
|
||||
|
||||
def test_preload_modules():
|
||||
def check_loaded(*modules):
|
||||
def check_loaded(*module_names):
|
||||
for grammar_cache in cache.parser_cache.values():
|
||||
if None in grammar_cache:
|
||||
break
|
||||
@@ -25,9 +25,9 @@ def test_preload_modules():
|
||||
if path is not None and str(path).startswith(str(typeshed.TYPESHED_PATH))
|
||||
)
|
||||
# +1 for None module (currently used)
|
||||
assert len(grammar_cache) - typeshed_cache_count == len(modules) + 1
|
||||
for i in modules:
|
||||
assert [i in k for k in grammar_cache.keys() if k is not None]
|
||||
assert len(grammar_cache) - typeshed_cache_count == len(module_names) + 1
|
||||
for i in module_names:
|
||||
assert [i in str(k) for k in grammar_cache.keys() if k is not None]
|
||||
|
||||
old_cache = cache.parser_cache.copy()
|
||||
cache.parser_cache.clear()
|
||||
@@ -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]
|
||||
|
||||
@@ -121,11 +121,8 @@ def test_multiple_signatures(Script):
|
||||
|
||||
|
||||
def test_get_signatures_whitespace(Script):
|
||||
s = dedent("""\
|
||||
abs(
|
||||
def x():
|
||||
pass
|
||||
""") # noqa
|
||||
# note: trailing space after 'abs'
|
||||
s = 'abs( \ndef x():\n pass\n'
|
||||
assert_signature(Script, s, 'abs', 0, line=1, column=5)
|
||||
|
||||
|
||||
|
||||
@@ -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'
|
||||
|
||||
|
||||
|
||||
@@ -621,7 +621,8 @@ def bar():
|
||||
|
||||
# typing is available via globals.
|
||||
({'return': 'typing.Union[str, int]'}, ['int', 'str'], ''),
|
||||
({'return': 'typing.Union["str", int]'}, ['int'], ''),
|
||||
({'return': 'typing.Union["str", int]'},
|
||||
['int', 'str'] if sys.version_info >= (3, 9) else ['int'], ''),
|
||||
({'return': 'typing.Union["str", 1]'}, [], ''),
|
||||
({'return': 'typing.Optional[str]'}, ['NoneType', 'str'], ''),
|
||||
({'return': 'typing.Optional[str, int]'}, [], ''), # Takes only one arg
|
||||
|
||||
@@ -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):
|
||||
@@ -17,7 +18,12 @@ def test_django_default_project(Script):
|
||||
)
|
||||
c, = script.complete()
|
||||
assert c.name == "SomeModel"
|
||||
assert script._inference_state.project._django is True
|
||||
|
||||
project = script._inference_state.project
|
||||
assert project._django is True
|
||||
assert project.sys_path is None
|
||||
assert project.smart_sys_path is True
|
||||
assert project.load_unsafe_extensions is False
|
||||
|
||||
|
||||
def test_django_default_project_of_file(Script):
|
||||
@@ -155,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
|
||||
|
||||
Reference in New Issue
Block a user