forked from VimPlug/jedi
move more test files to specific directories
This commit is contained in:
9
test/evaluate/namespace_package/ns1/pkg/__init__.py
Normal file
9
test/evaluate/namespace_package/ns1/pkg/__init__.py
Normal file
@@ -0,0 +1,9 @@
|
||||
foo = 'ns1!'
|
||||
|
||||
# this is a namespace package
|
||||
try:
|
||||
import pkg_resources
|
||||
pkg_resources.declare_namespace(__name__)
|
||||
except ImportError:
|
||||
import pkgutil
|
||||
__path__ = pkgutil.extend_path(__path__, __name__)
|
||||
1
test/evaluate/namespace_package/ns1/pkg/ns1_file.py
Normal file
1
test/evaluate/namespace_package/ns1/pkg/ns1_file.py
Normal file
@@ -0,0 +1 @@
|
||||
foo = 'ns1_file!'
|
||||
@@ -0,0 +1 @@
|
||||
foo = 'ns1_folder!'
|
||||
1
test/evaluate/namespace_package/ns2/pkg/ns2_file.py
Normal file
1
test/evaluate/namespace_package/ns2/pkg/ns2_file.py
Normal file
@@ -0,0 +1 @@
|
||||
foo = 'ns2_file!'
|
||||
@@ -0,0 +1 @@
|
||||
foo = 'ns2_folder!'
|
||||
@@ -0,0 +1 @@
|
||||
foo = 'nested!'
|
||||
1
test/evaluate/not_in_sys_path/not_in_sys_path.py
Normal file
1
test/evaluate/not_in_sys_path/not_in_sys_path.py
Normal file
@@ -0,0 +1 @@
|
||||
value = 3
|
||||
@@ -0,0 +1 @@
|
||||
value = 'package'
|
||||
@@ -0,0 +1 @@
|
||||
value = 'package.module'
|
||||
7
test/evaluate/not_in_sys_path/pkg/module.py
Normal file
7
test/evaluate/not_in_sys_path/pkg/module.py
Normal file
@@ -0,0 +1,7 @@
|
||||
import not_in_sys_path
|
||||
import not_in_sys_path_package
|
||||
from not_in_sys_path_package import module
|
||||
|
||||
not_in_sys_path.value
|
||||
not_in_sys_path_package.value
|
||||
module.value
|
||||
@@ -12,7 +12,7 @@ def test_find_module_py33():
|
||||
assert find_module_py33('_io') == (None, '_io', False)
|
||||
|
||||
|
||||
@cwd_at('test/not_in_sys_path/pkg')
|
||||
@cwd_at('test/evaluate/not_in_sys_path/pkg')
|
||||
def test_import_not_in_sys_path():
|
||||
"""
|
||||
non-direct imports (not in sys.path)
|
||||
|
||||
53
test/evaluate/test_namespace_package.py
Normal file
53
test/evaluate/test_namespace_package.py
Normal file
@@ -0,0 +1,53 @@
|
||||
import jedi
|
||||
import sys
|
||||
from os.path import dirname, join
|
||||
|
||||
|
||||
def test_namespace_package():
|
||||
sys.path.insert(0, join(dirname(__file__), 'namespace_package/ns1'))
|
||||
sys.path.insert(1, join(dirname(__file__), 'namespace_package/ns2'))
|
||||
try:
|
||||
# goto definition
|
||||
assert jedi.Script('from pkg import ns1_file').goto_definitions()
|
||||
assert jedi.Script('from pkg import ns2_file').goto_definitions()
|
||||
assert not jedi.Script('from pkg import ns3_file').goto_definitions()
|
||||
|
||||
# goto assignment
|
||||
tests = {
|
||||
'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!',
|
||||
}
|
||||
for source, solution in tests.items():
|
||||
ass = jedi.Script(source).goto_assignments()
|
||||
assert len(ass) == 1
|
||||
assert ass[0].description == "foo = '%s'" % solution
|
||||
|
||||
# completion
|
||||
completions = jedi.Script('from pkg import ').completions()
|
||||
names = [str(c.name) for c in completions] # str because of unicode
|
||||
compare = ['foo', 'ns1_file', 'ns1_folder', 'ns2_folder', 'ns2_file']
|
||||
# must at least contain these items, other items are not important
|
||||
assert not (set(compare) - set(names))
|
||||
|
||||
tests = {
|
||||
'from pkg import ns2_folder as x': 'ns2_folder!',
|
||||
'from pkg import ns2_file as x': 'ns2_file!',
|
||||
'from pkg.ns2_folder import nested as x': 'nested!',
|
||||
'from pkg import ns1_folder as x': 'ns1_folder!',
|
||||
'from pkg import ns1_file as x': 'ns1_file!',
|
||||
'import pkg as x': 'ns1!',
|
||||
}
|
||||
for source, solution in tests.items():
|
||||
for c in jedi.Script(source + '; x.').completions():
|
||||
if c.name == 'foo':
|
||||
completion = c
|
||||
solution = "statement: foo = '%s'" % solution
|
||||
assert completion.description == solution
|
||||
|
||||
finally:
|
||||
sys.path.pop(0)
|
||||
sys.path.pop(0)
|
||||
Reference in New Issue
Block a user