def test_namespace_package_in_multiple_directories_goto_definition(Script): code = 'from pkg import ns1_file' sys_path = [get_example_dir('implicit_namespace_package', 'ns1'), get_example_dir('implicit_namespace_package', 'ns2')] project = Project('.', sys_path=sys_path) script = Script(code, project=project) result = script.infer() assert len(result) == 1
def test_namespace_package_in_multiple_directories_goto_definition(Script): CODE = 'from pkg import ns1_file' sys_path = [ get_example_dir('implicit_namespace_package', 'ns1'), get_example_dir('implicit_namespace_package', 'ns2') ] script = Script(sys_path=sys_path, source=CODE) result = script.infer() assert len(result) == 1
def test_namespace_name_autocompletion_full_name(Script): code = 'from pk' sys_path = [get_example_dir('implicit_namespace_package', 'ns1'), get_example_dir('implicit_namespace_package', 'ns2')] project = Project('.', sys_path=sys_path) script = Script(code, project=project) compl = script.complete() assert set(c.full_name for c in compl) == set(['pkg'])
def test_namespace_package_in_multiple_directories_autocompletion(Script): code = 'from pkg.' sys_path = [get_example_dir('implicit_namespace_package', 'ns1'), get_example_dir('implicit_namespace_package', 'ns2')] project = Project('.', sys_path=sys_path) script = Script(code, project=project) compl = script.complete() assert set(c.name for c in compl) == set(['ns1_file', 'ns2_file'])
def test_namespace_package_in_multiple_directories_autocompletion(Script): CODE = 'from pkg.' sys_path = [ get_example_dir('implicit_namespace_package', 'ns1'), get_example_dir('implicit_namespace_package', 'ns2') ] script = Script(sys_path=sys_path, source=CODE) compl = script.complete() assert set(c.name for c in compl) == set(['ns1_file', 'ns2_file'])
def test_namespace_name_autocompletion_full_name(Script): CODE = 'from pk' sys_path = [ get_example_dir('implicit_namespace_package', 'ns1'), get_example_dir('implicit_namespace_package', 'ns2') ] script = Script(sys_path=sys_path, source=CODE) compl = script.complete() assert set(c.full_name for c in compl) == set(['pkg'])
def test_implicit_namespace_package(Script): sys_path = [ get_example_dir('implicit_namespace_package', 'ns1'), get_example_dir('implicit_namespace_package', 'ns2') ] project = Project('.', sys_path=sys_path) def script_with_path(*args, **kwargs): return Script(project=project, *args, **kwargs) # goto definition assert script_with_path('from pkg import ns1_file').infer() assert script_with_path('from pkg import ns2_file').infer() assert not script_with_path('from pkg import ns3_file').infer() # goto assignment tests = { 'from pkg.ns2_file import foo': 'ns2_file!', 'from pkg.ns1_file import foo': 'ns1_file!', } for source, solution in tests.items(): ass = script_with_path(source).goto() assert len(ass) == 1 assert ass[0].description == "foo = '%s'" % solution # completion completions = script_with_path('from pkg import ').complete() names = [c.name for c in completions] compare = ['ns1_file', 'ns2_file'] # must at least contain these items, other items are not important assert set(compare) == set(names) tests = { 'from pkg import ns2_file as x': 'ns2_file!', 'from pkg import ns1_file as x': 'ns1_file!' } for source, solution in tests.items(): for c in script_with_path(source + '; x.').complete(): if c.name == 'foo': completion = c solution = "foo = '%s'" % solution assert completion.description == solution
def test_goto_module(Script): def check(line, expected, follow_imports=False): script = Script(path=path) module, = script.goto(line=line, follow_imports=follow_imports) assert module.module_path == expected base_path = get_example_dir('simple_import') path = base_path.joinpath('__init__.py') check(1, base_path.joinpath('module.py')) check(1, base_path.joinpath('module.py'), follow_imports=True) check(5, base_path.joinpath('module2.py'))
def test_folder_io_walk(): root_dir = get_example_dir('namespace_package') iterator = FolderIO(root_dir).walk() root, folder_ios, file_ios = next(iterator) assert {f.path for f in folder_ios } == {join(root_dir, 'ns1'), join(root_dir, 'ns2')} for f in list(folder_ios): if f.path.endswith('ns1'): folder_ios.remove(f) root, folder_ios, file_ios = next(iterator) assert folder_ios assert root.path == join(root_dir, 'ns2') folder_ios.clear() assert next(iterator, None) is None
def ScriptInStubFolder(Script): path = get_example_dir('stub_packages') project = Project(path, sys_path=[path], smart_sys_path=False) return partial(Script, _project=project)
def test_folder_io_walk2(): root_dir = get_example_dir('namespace_package') iterator = FolderIO(root_dir).walk() root, folder_ios, file_ios = next(iterator) folder_ios.clear() assert next(iterator, None) is None