diff options
author | Nick Coghlan <ncoghlan@gmail.com> | 2012-07-20 13:40:09 (GMT) |
---|---|---|
committer | Nick Coghlan <ncoghlan@gmail.com> | 2012-07-20 13:40:09 (GMT) |
commit | be7e49fd820318509cd8b4dbde479c552f74ef62 (patch) | |
tree | 856c3693092233495f1ecadbd90c0b7e085cc70d /Lib/test/test_import.py | |
parent | 818b1186f9459646a4ad7015ed45ce9dfea0fa55 (diff) | |
download | cpython-be7e49fd820318509cd8b4dbde479c552f74ef62.zip cpython-be7e49fd820318509cd8b4dbde479c552f74ef62.tar.gz cpython-be7e49fd820318509cd8b4dbde479c552f74ef62.tar.bz2 |
Close #15386: There was a loophole that meant importlib.machinery and imp would sometimes reference an uninitialised copy of importlib._bootstrap
Diffstat (limited to 'Lib/test/test_import.py')
-rw-r--r-- | Lib/test/test_import.py | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/Lib/test/test_import.py b/Lib/test/test_import.py index 89ec8dc..51b52c7 100644 --- a/Lib/test/test_import.py +++ b/Lib/test/test_import.py @@ -1,8 +1,9 @@ +# We import importlib *ASAP* in order to test #15386 +import importlib import builtins import imp from importlib.test.import_ import test_suite as importlib_import_test_suite from importlib.test.import_ import util as importlib_util -import importlib import marshal import os import platform @@ -777,6 +778,15 @@ class ImportlibBootstrapTests(unittest.TestCase): self.assertEqual(mod.__package__, 'importlib') self.assertTrue(mod.__file__.endswith('_bootstrap.py'), mod.__file__) + def test_there_can_be_only_one(self): + # Issue #15386 revealed a tricky loophole in the bootstrapping + # This test is technically redundant, since the bug caused importing + # this test module to crash completely, but it helps prove the point + from importlib import machinery + mod = sys.modules['_frozen_importlib'] + self.assertIs(machinery.FileFinder, mod.FileFinder) + self.assertIs(imp.new_module, mod.new_module) + class ImportTracebackTests(unittest.TestCase): |