diff options
author | Brett Cannon <bcannon@gmail.com> | 2009-03-04 01:00:53 (GMT) |
---|---|---|
committer | Brett Cannon <bcannon@gmail.com> | 2009-03-04 01:00:53 (GMT) |
commit | 417937733fdcb2aa23b2cf726a5cc6484fe803f5 (patch) | |
tree | ffb93b79e652695f356bad2da1da4b4de1ab9e30 /Lib/test/test_importlib.py | |
parent | 131af6505ace852a5754f380d451636c09e7d597 (diff) | |
download | cpython-417937733fdcb2aa23b2cf726a5cc6484fe803f5.zip cpython-417937733fdcb2aa23b2cf726a5cc6484fe803f5.tar.gz cpython-417937733fdcb2aa23b2cf726a5cc6484fe803f5.tar.bz2 |
Fix some more bugs caused by the backport from 3.x for importlib.
Do a more exact copy of the final 3.x code to resolve bugs and add
appropriate tests.
Diffstat (limited to 'Lib/test/test_importlib.py')
-rw-r--r-- | Lib/test/test_importlib.py | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/Lib/test/test_importlib.py b/Lib/test/test_importlib.py index 73bb654..51d8da6 100644 --- a/Lib/test/test_importlib.py +++ b/Lib/test/test_importlib.py @@ -135,20 +135,20 @@ class ImportModuleTests(unittest.TestCase): module = importlib.import_module(name) self.assertEqual(module.__name__, name) - def test_relative_package_import(self): + def test_shallow_relative_package_import(self): + modules = ['a.__init__', 'a.b.__init__', 'a.b.c.__init__', 'a.b.c.d'] + with mock_modules(*modules) as mock: + with import_state(meta_path=[mock]): + module = importlib.import_module('.d', 'a.b.c') + self.assertEqual(module.__name__, 'a.b.c.d') + + def test_deep_relative_package_import(self): # Test importing a module from a package through a relatve import. - pkg_name = 'pkg' - pkg_long_name = '{0}.__init__'.format(pkg_name) - module_name = 'mod' - subpkg_name = '{0}.subpkg'.format(pkg_name) - subpkg_long_name = '{0}.__init__'.format(subpkg_name) - absolute_name = '{0}.{1}'.format(pkg_name, module_name) - relative_name = '..{0}'.format(module_name) - with mock_modules(pkg_long_name, subpkg_long_name, - absolute_name) as mock: + modules = ['a.__init__', 'a.b.__init__', 'a.c'] + with mock_modules(*modules) as mock: with import_state(meta_path=[mock]): - module = importlib.import_module(relative_name, subpkg_name) - self.assertEqual(module.__name__, absolute_name) + module = importlib.import_module('..c', 'a.b') + self.assertEqual(module.__name__, 'a.c') def test_absolute_import_with_package(self): # Test importing a module from a package with an absolute name with |