From e01d901399223a9f9fbce7993b00f68e0daa1eb1 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Tue, 26 Mar 2019 09:33:54 +0100 Subject: [PATCH] Test zip imports that have nested modules --- test/test_evaluate/test_imports.py | 27 ++++++++++++++++------ test/test_evaluate/zipped_imports/pkg.zip | Bin 463 -> 811 bytes 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/test/test_evaluate/test_imports.py b/test/test_evaluate/test_imports.py index c6af770c..8f42d4e7 100644 --- a/test/test_evaluate/test_imports.py +++ b/test/test_evaluate/test_imports.py @@ -56,14 +56,27 @@ def test_find_module_package_zipped(Script, evaluator, environment): assert is_package is True -def test_correct_zip_package_behavior(Script, evaluator, environment): +@pytest.mark.parametrize( + 'code, file, package, path', [ + ('import pkg', '__init__.py', 'pkg', 'pkg'), + ('from pkg import module', 'module.py', 'pkg', None), + ('from pkg import nested', os.path.join('nested', '__init__.py'), + 'pkg.nested', os.path.join('pkg', 'nested')), + ('from pkg.nested import nested_module', + os.path.join('nested', 'nested_module.py'), 'pkg.nested', None), + ] + +) +def test_correct_zip_package_behavior(Script, evaluator, environment, code, + file, package, path): sys_path = environment.get_sys_path() + [pkg_zip_path] - pkg, = Script('import pkg', sys_path=sys_path).goto_definitions() + pkg, = Script(code, sys_path=sys_path).goto_definitions() context, = pkg._name.infer() - assert context.py__file__() == os.path.join(pkg_zip_path, 'pkg', '__init__.py') - assert context.is_package is True - assert context.py__package__() == ('pkg',) - assert context.py__path__() == [os.path.join(pkg_zip_path, 'pkg')] + assert context.py__file__() == os.path.join(pkg_zip_path, 'pkg', file) + assert '.'.join(context.py__package__()) == package + assert context.is_package is (path is not None) + if path is not None: + assert context.py__path__() == [os.path.join(pkg_zip_path, path)] def test_find_module_not_package_zipped(Script, evaluator, environment): @@ -312,7 +325,7 @@ def test_relative_imports_with_multiple_similar_directories(Script, path, empty_ assert name.name == 'api_test1' -def test_relative_imports_x(Script): +def test_relative_imports_with_outside_paths(Script): dir = get_example_dir('issue1209') project = Project(dir, sys_path=[], smart_sys_path=False) script = Script( diff --git a/test/test_evaluate/zipped_imports/pkg.zip b/test/test_evaluate/zipped_imports/pkg.zip index 3b1bee0a3f06bc7a14408b3069f23dafde2cf376..41366b12d1533a77eddc7610a6d31a0981491e54 100644 GIT binary patch delta 379 zcmX@lyqayo&w6GS5oQJ;nB`sN2clts8^|cgPS?*%EiOq-(GT!uX5j)WY)4ZlhN>_= zJ~J<~BtBlRpc0{HDw-Z?xE@ik=@3iebMsS5b5emiCw@Ot&&XuYjN54tX9_g@b^H!D z3+hmiM%+$?XjEv}(x||Q;zJaNGcrZP48i7hgdriQhM;>Sz?+o~q?io|JAg`iftY~- E0Am76+W-In delta 31 gcmZ3@cAj~{&&mCaheTM}7=VBo2oC}2?;s8X0FreE&;S4c