diff options
author | Larry Hastings <larry@hastings.org> | 2015-09-06 03:53:04 (GMT) |
---|---|---|
committer | Larry Hastings <larry@hastings.org> | 2015-09-06 03:53:04 (GMT) |
commit | 055a9e0bc8eb28fd64158ade11019b712116aeae (patch) | |
tree | 00f75387fa11dfc0678884f5d2f15e24ad6b525c /Lib/test | |
parent | 699534210c935de3d5041c801bd97270fd31a522 (diff) | |
parent | 9d3c61c86a20678d604c96a68bbf4a966877f0b9 (diff) | |
download | cpython-055a9e0bc8eb28fd64158ade11019b712116aeae.zip cpython-055a9e0bc8eb28fd64158ade11019b712116aeae.tar.gz cpython-055a9e0bc8eb28fd64158ade11019b712116aeae.tar.bz2 |
Merged in ncoghlan/cpython350 (pull request #17)
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/imp_dummy.py | 3 | ||||
-rw-r--r-- | Lib/test/test_imp.py | 24 |
2 files changed, 27 insertions, 0 deletions
diff --git a/Lib/test/imp_dummy.py b/Lib/test/imp_dummy.py new file mode 100644 index 0000000..2a4deb4 --- /dev/null +++ b/Lib/test/imp_dummy.py @@ -0,0 +1,3 @@ +# Fodder for test of issue24748 in test_imp + +dummy_name = True diff --git a/Lib/test/test_imp.py b/Lib/test/test_imp.py index 47bf1de..ee9ee1a 100644 --- a/Lib/test/test_imp.py +++ b/Lib/test/test_imp.py @@ -3,6 +3,7 @@ try: except ImportError: _thread = None import importlib +import importlib.util import os import os.path import shutil @@ -275,6 +276,29 @@ class ImportTests(unittest.TestCase): self.skipTest("found module doesn't appear to be a C extension") imp.load_module(name, None, *found[1:]) + @requires_load_dynamic + def test_issue24748_load_module_skips_sys_modules_check(self): + name = 'test.imp_dummy' + try: + del sys.modules[name] + except KeyError: + pass + try: + module = importlib.import_module(name) + spec = importlib.util.find_spec('_testmultiphase') + module = imp.load_dynamic(name, spec.origin) + self.assertEqual(module.__name__, name) + self.assertEqual(module.__spec__.name, name) + self.assertEqual(module.__spec__.origin, spec.origin) + self.assertRaises(AttributeError, getattr, module, 'dummy_name') + self.assertEqual(module.int_const, 1969) + self.assertIs(sys.modules[name], module) + finally: + try: + del sys.modules[name] + except KeyError: + pass + @unittest.skipIf(sys.dont_write_bytecode, "test meaningful only when writing bytecode") def test_bug7732(self): |