diff options
author | Nick Coghlan <ncoghlan@gmail.com> | 2012-08-31 14:13:45 (GMT) |
---|---|---|
committer | Nick Coghlan <ncoghlan@gmail.com> | 2012-08-31 14:13:45 (GMT) |
commit | 91b9f139bc629e1ba931c60a3301e8062f6f4e6d (patch) | |
tree | e959ba896e7fcb4c24bcafad98673c737b281369 /Lib/test/test_imp.py | |
parent | 380c55cc58911a4777f080744f596d1e96fd2357 (diff) | |
download | cpython-91b9f139bc629e1ba931c60a3301e8062f6f4e6d.zip cpython-91b9f139bc629e1ba931c60a3301e8062f6f4e6d.tar.gz cpython-91b9f139bc629e1ba931c60a3301e8062f6f4e6d.tar.bz2 |
Issue #15828: Restore support for C extension modules in imp.load_module()
Diffstat (limited to 'Lib/test/test_imp.py')
-rw-r--r-- | Lib/test/test_imp.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/Lib/test/test_imp.py b/Lib/test/test_imp.py index a660278..20e5608 100644 --- a/Lib/test/test_imp.py +++ b/Lib/test/test_imp.py @@ -186,6 +186,35 @@ class ImportTests(unittest.TestCase): self.assertRaises(SyntaxError, imp.find_module, "badsyntax_pep3120", [path]) + def test_load_from_source(self): + # Verify that the imp module can correctly load and find .py files + # XXX (ncoghlan): It would be nice to use support.CleanImport + # here, but that breaks because the os module registers some + # handlers in copy_reg on import. Since CleanImport doesn't + # revert that registration, the module is left in a broken + # state after reversion. Reinitialising the module contents + # and just reverting os.environ to its previous state is an OK + # workaround + orig_path = os.path + orig_getenv = os.getenv + with support.EnvironmentVarGuard(): + x = imp.find_module("os") + self.addCleanup(x[0].close) + new_os = imp.load_module("os", *x) + self.assertIs(os, new_os) + self.assertIs(orig_path, new_os.path) + self.assertIsNot(orig_getenv, new_os.getenv) + + @support.cpython_only + def test_issue15828_load_extensions(self): + # Issue 15828 picked up that the adapter between the old imp API + # and importlib couldn't handle C extensions + example = "_heapq" + x = imp.find_module(example) + self.addCleanup(x[0].close) + mod = imp.load_module(example, *x) + self.assertEqual(mod.__name__, example) + def test_load_dynamic_ImportError_path(self): # Issue #1559549 added `name` and `path` attributes to ImportError # in order to provide better detail. Issue #10854 implemented those |