diff options
author | Brett Cannon <bcannon@gmail.com> | 2009-03-04 01:02:54 (GMT) |
---|---|---|
committer | Brett Cannon <bcannon@gmail.com> | 2009-03-04 01:02:54 (GMT) |
commit | b5f03c67794338b465a6cccecd4e5cbc704af07a (patch) | |
tree | 6a316b58aa1b0b12c6dc782e5c577a1c19876e16 | |
parent | 4fa88fa0ba35e25ad9be66ebbdaba9aca553dc8b (diff) | |
download | cpython-b5f03c67794338b465a6cccecd4e5cbc704af07a.zip cpython-b5f03c67794338b465a6cccecd4e5cbc704af07a.tar.gz cpython-b5f03c67794338b465a6cccecd4e5cbc704af07a.tar.bz2 |
Add a test for importlib.import_module.
-rw-r--r-- | Lib/importlib/test/test_api.py | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/Lib/importlib/test/test_api.py b/Lib/importlib/test/test_api.py index 8847dc9..65f8d04 100644 --- a/Lib/importlib/test/test_api.py +++ b/Lib/importlib/test/test_api.py @@ -26,7 +26,7 @@ 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): # Test importing a module from a package through a relatve import. pkg_name = 'pkg' pkg_long_name = '{0}.__init__'.format(pkg_name) @@ -39,6 +39,15 @@ class ImportModuleTests(unittest.TestCase): module = importlib.import_module(relative_name, pkg_name) self.assertEqual(module.__name__, absolute_name) + def test_deep_relative_package_import(self): + modules = ['a.__init__', 'a.b.__init__', 'a.c'] + with util.mock_modules(*modules) as mock: + with util.import_state(meta_path=[mock]): + importlib.import_module('a') + importlib.import_module('a.b') + 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 # the 'package' argument given. |