diff options
author | Benjamin Peterson <benjamin@python.org> | 2012-04-18 10:55:43 -0400 |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2012-04-18 10:55:43 -0400 |
commit | d76bc7abac37ac345878ed2db7e264f59fc79985 (patch) | |
tree | 0c933be1c1ebc649ba9279935cc75c13b05346fd /Lib/importlib/test | |
parent | da20cd2b6bf40d712f6296b9e21ff099b22aab71 (diff) | |
download | cpython-d76bc7abac37ac345878ed2db7e264f59fc79985.tar.gz cpython-d76bc7abac37ac345878ed2db7e264f59fc79985.zip |
rollback 005fd1fe31ab (see #14609 and #14582)
Being able to overload a sys.module entry during import of a module was broken
by this changeset.
Diffstat (limited to 'Lib/importlib/test')
-rw-r--r-- | Lib/importlib/test/import_/test_caching.py | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/Lib/importlib/test/import_/test_caching.py b/Lib/importlib/test/import_/test_caching.py index 467eee15a68..3baff5501ed 100644 --- a/Lib/importlib/test/import_/test_caching.py +++ b/Lib/importlib/test/import_/test_caching.py @@ -47,12 +47,36 @@ class UseCache(unittest.TestCase): mock.load_module = MethodType(load_module, mock) return mock - def test_using_loader_return(self): - loader_return = 'hi there!' - with self.create_mock('module', return_=loader_return) as mock: + # __import__ inconsistent between loaders and built-in import when it comes + # to when to use the module in sys.modules and when not to. + @import_util.importlib_only + def test_using_cache_after_loader(self): + # [from cache on return] + with self.create_mock('module') as mock: with util.import_state(meta_path=[mock]): module = import_util.import_('module') - self.assertEqual(module, loader_return) + self.assertEqual(id(module), id(sys.modules['module'])) + + # See test_using_cache_after_loader() for reasoning. + @import_util.importlib_only + def test_using_cache_for_assigning_to_attribute(self): + # [from cache to attribute] + with self.create_mock('pkg.__init__', 'pkg.module') as importer: + with util.import_state(meta_path=[importer]): + module = import_util.import_('pkg.module') + self.assertTrue(hasattr(module, 'module')) + self.assertTrue(id(module.module), id(sys.modules['pkg.module'])) + + # See test_using_cache_after_loader() for reasoning. + @import_util.importlib_only + def test_using_cache_for_fromlist(self): + # [from cache for fromlist] + with self.create_mock('pkg.__init__', 'pkg.module') as importer: + with util.import_state(meta_path=[importer]): + module = import_util.import_('pkg', fromlist=['module']) + self.assertTrue(hasattr(module, 'module')) + self.assertEqual(id(module.module), + id(sys.modules['pkg.module'])) def test_main(): |