mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-15 18:17:07 +08:00
Refactor the namespace package tests
This commit is contained in:
@@ -1,56 +1,66 @@
|
|||||||
from os.path import dirname, join
|
from os.path import dirname, join
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
def test_namespace_package(Script):
|
|
||||||
sys_path = [join(dirname(__file__), d)
|
|
||||||
for d in ['namespace_package/ns1', 'namespace_package/ns2']]
|
|
||||||
|
|
||||||
def script_with_path(*args, **kwargs):
|
SYS_PATH = [join(dirname(__file__), d)
|
||||||
return Script(sys_path=sys_path, *args, **kwargs)
|
for d in ['namespace_package/ns1', 'namespace_package/ns2']]
|
||||||
|
|
||||||
# goto definition
|
|
||||||
assert script_with_path('from pkg import ns1_file').goto_definitions()
|
|
||||||
assert script_with_path('from pkg import ns2_file').goto_definitions()
|
|
||||||
assert not script_with_path('from pkg import ns3_file').goto_definitions()
|
|
||||||
|
|
||||||
# goto assignment
|
def script_with_path(Script, *args, **kwargs):
|
||||||
tests = {
|
return Script(sys_path=SYS_PATH, *args, **kwargs)
|
||||||
'from pkg.ns2_folder.nested import foo': 'nested!',
|
|
||||||
'from pkg.ns2_folder import foo': 'ns2_folder!',
|
|
||||||
'from pkg.ns2_file import foo': 'ns2_file!',
|
|
||||||
'from pkg.ns1_folder import foo': 'ns1_folder!',
|
|
||||||
'from pkg.ns1_file import foo': 'ns1_file!',
|
|
||||||
'from pkg import foo': 'ns1!',
|
|
||||||
'from pkg.nested.ns1_nested_file import foo': 'ns1_nested_file!',
|
|
||||||
}
|
|
||||||
for source, solution in tests.items():
|
|
||||||
ass = script_with_path(source).goto_assignments()
|
|
||||||
assert len(ass) == 1
|
|
||||||
assert ass[0].description == "foo = '%s'" % solution
|
|
||||||
|
|
||||||
|
|
||||||
|
def test_goto_definition(Script):
|
||||||
|
assert script_with_path(Script, 'from pkg import ns1_file').goto_definitions()
|
||||||
|
assert script_with_path(Script, 'from pkg import ns2_file').goto_definitions()
|
||||||
|
assert not script_with_path(Script, 'from pkg import ns3_file').goto_definitions()
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
('source', 'solution'), [
|
||||||
|
('from pkg.ns2_folder.nested import foo', 'nested!'),
|
||||||
|
('from pkg.ns2_folder import foo', 'ns2_folder!'),
|
||||||
|
('from pkg.ns2_file import foo', 'ns2_file!'),
|
||||||
|
('from pkg.ns1_folder import foo', 'ns1_folder!'),
|
||||||
|
('from pkg.ns1_file import foo', 'ns1_file!'),
|
||||||
|
('from pkg import foo', 'ns1!'),
|
||||||
|
('from pkg.nested.ns1_nested_file import foo', 'ns1_nested_file!'),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
def test_goto_assignment(Script, source, solution):
|
||||||
|
ass = script_with_path(Script, source).goto_assignments()
|
||||||
|
assert len(ass) == 1
|
||||||
|
assert ass[0].description == "foo = '%s'" % solution
|
||||||
|
|
||||||
|
|
||||||
|
def test_simple_completions(Script):
|
||||||
# completion
|
# completion
|
||||||
completions = script_with_path('from pkg import ').completions()
|
completions = script_with_path(Script, 'from pkg import ').completions()
|
||||||
names = [str(c.name) for c in completions] # str because of unicode
|
names = [str(c.name) for c in completions] # str because of unicode
|
||||||
compare = ['foo', 'ns1_file', 'ns1_folder', 'ns2_folder', 'ns2_file',
|
compare = ['foo', 'ns1_file', 'ns1_folder', 'ns2_folder', 'ns2_file',
|
||||||
'pkg_resources', 'pkgutil', '__name__', '__path__',
|
'pkg_resources', 'pkgutil', 'nested', '__name__', '__path__',
|
||||||
'__package__', '__file__', '__doc__']
|
'__package__', '__file__', '__doc__']
|
||||||
# must at least contain these items, other items are not important
|
# must at least contain these items, other items are not important
|
||||||
assert set(compare) == set(names)
|
assert set(compare) == set(names)
|
||||||
|
|
||||||
tests = {
|
|
||||||
'from pkg import ns2_folder as x': 'ns2_folder!',
|
@pytest.mark.parametrize(
|
||||||
'from pkg import ns2_file as x': 'ns2_file!',
|
('source', 'solution'), [
|
||||||
'from pkg.ns2_folder import nested as x': 'nested!',
|
('from pkg import ns2_folder as x', 'ns2_folder!'),
|
||||||
'from pkg import ns1_folder as x': 'ns1_folder!',
|
('from pkg import ns2_file as x', 'ns2_file!'),
|
||||||
'from pkg import ns1_file as x': 'ns1_file!',
|
('from pkg.ns2_folder import nested as x', 'nested!'),
|
||||||
'import pkg as x': 'ns1!',
|
('from pkg import ns1_folder as x', 'ns1_folder!'),
|
||||||
}
|
('from pkg import ns1_file as x', 'ns1_file!'),
|
||||||
for source, solution in tests.items():
|
('import pkg as x', 'ns1!'),
|
||||||
for c in script_with_path(source + '; x.').completions():
|
]
|
||||||
if c.name == 'foo':
|
)
|
||||||
completion = c
|
def test_completions(Script, source, solution):
|
||||||
solution = "foo = '%s'" % solution
|
for c in script_with_path(Script, source + '; x.').completions():
|
||||||
assert completion.description == solution
|
if c.name == 'foo':
|
||||||
|
completion = c
|
||||||
|
solution = "foo = '%s'" % solution
|
||||||
|
assert completion.description == solution
|
||||||
|
|
||||||
|
|
||||||
def test_nested_namespace_package(Script):
|
def test_nested_namespace_package(Script):
|
||||||
|
|||||||
Reference in New Issue
Block a user