forked from VimPlug/jedi
Make sure there are proper tests for goto_assignments with prefer_stubs and only_stubs
This commit is contained in:
@@ -6,6 +6,7 @@ from jedi.api.project import Project
|
|||||||
from test.helpers import root_dir
|
from test.helpers import root_dir
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('type_', ['goto', 'infer'])
|
||||||
@pytest.mark.parametrize('way', ['direct', 'indirect'])
|
@pytest.mark.parametrize('way', ['direct', 'indirect'])
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
'kwargs', [
|
'kwargs', [
|
||||||
@@ -15,37 +16,48 @@ from test.helpers import root_dir
|
|||||||
]
|
]
|
||||||
)
|
)
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
('code', 'full_name', 'has_stub', 'has_python'), [
|
('code', 'full_name', 'has_stub', 'has_python', 'goto_changes'), [
|
||||||
['import os; os.walk', 'os.walk', True, True],
|
['import os; os.walk', 'os.walk', True, True, {}],
|
||||||
['from collections import Counter', 'collections.Counter', True, True],
|
['from collections import Counter', 'collections.Counter', True, True, {}],
|
||||||
['from collections', 'collections', True, True],
|
['from collections', 'collections', True, True, {}],
|
||||||
['from collections import Counter; Counter', 'collections.Counter', True, True],
|
['from collections import Counter; Counter', 'collections.Counter', True, True, {}],
|
||||||
['from collections import Counter; Counter()', 'collections.Counter', True, True],
|
['from collections import Counter; Counter()', 'collections.Counter', True, True, {}],
|
||||||
['from collections import Counter; Counter.most_common',
|
['from collections import Counter; Counter.most_common',
|
||||||
'collections.Counter.most_common', True, True],
|
'collections.Counter.most_common', True, True, {}],
|
||||||
|
|
||||||
['from keyword import kwlist; kwlist', 'typing.Sequence', True, True],
|
['from keyword import kwlist; kwlist', 'typing.Sequence', True, True,
|
||||||
['from keyword import kwlist', 'typing.Sequence', True, True],
|
{'full_name': 'keyword.kwlist'}],
|
||||||
|
['from keyword import kwlist', 'typing.Sequence', True, True,
|
||||||
|
{'full_name': 'keyword.kwlist'}],
|
||||||
|
|
||||||
['import with_stub', 'with_stub', True, True],
|
['import with_stub', 'with_stub', True, True, {}],
|
||||||
['import with_stub', 'with_stub', True, True],
|
['import with_stub', 'with_stub', True, True, {}],
|
||||||
['import with_stub_folder.python_only', 'with_stub_folder.python_only', False, True],
|
['import with_stub_folder.python_only', 'with_stub_folder.python_only', False, True, {}],
|
||||||
['import stub_only', 'stub_only', True, False],
|
['import stub_only', 'stub_only', True, False, {}],
|
||||||
])
|
])
|
||||||
def test_infer_and_goto(Script, code, full_name, has_stub, has_python, way, kwargs):
|
def test_infer_and_goto(Script, code, full_name, has_stub, has_python, way,
|
||||||
|
kwargs, type_, goto_changes):
|
||||||
project = Project(os.path.join(root_dir, 'test', 'completion', 'stub_folder'))
|
project = Project(os.path.join(root_dir, 'test', 'completion', 'stub_folder'))
|
||||||
s = Script(code, _project=project)
|
s = Script(code, _project=project)
|
||||||
prefer_stubs = kwargs['prefer_stubs']
|
prefer_stubs = kwargs['prefer_stubs']
|
||||||
only_stubs = kwargs['only_stubs']
|
only_stubs = kwargs['only_stubs']
|
||||||
|
if type_ == 'goto':
|
||||||
|
full_name = goto_changes.get('full_name', full_name)
|
||||||
if way == 'direct':
|
if way == 'direct':
|
||||||
defs = s.goto_definitions(**kwargs)
|
if type_ == 'goto':
|
||||||
|
defs = s.goto_assignments(follow_imports=True, **kwargs)
|
||||||
|
else:
|
||||||
|
defs = s.goto_definitions(**kwargs)
|
||||||
else:
|
else:
|
||||||
goto_defs = s.goto_assignments(
|
goto_defs = s.goto_assignments(
|
||||||
# Prefering stubs when we want to go to python and vice versa
|
# Prefering stubs when we want to go to python and vice versa
|
||||||
prefer_stubs=not (prefer_stubs or only_stubs),
|
prefer_stubs=not (prefer_stubs or only_stubs),
|
||||||
follow_imports=True,
|
follow_imports=True,
|
||||||
)
|
)
|
||||||
defs = [d for goto_def in goto_defs for d in goto_def.infer(**kwargs)]
|
if type_ == 'goto':
|
||||||
|
defs = [d for goto_def in goto_defs for d in goto_def.goto_assignments(**kwargs)]
|
||||||
|
else:
|
||||||
|
defs = [d for goto_def in goto_defs for d in goto_def.infer(**kwargs)]
|
||||||
|
|
||||||
if not has_stub and only_stubs:
|
if not has_stub and only_stubs:
|
||||||
assert not defs
|
assert not defs
|
||||||
|
|||||||
Reference in New Issue
Block a user