summaryrefslogtreecommitdiff
path: root/Lib/test
diff options
context:
space:
mode:
authorNick Coghlan <ncoghlan@gmail.com>2012-07-20 23:40:09 +1000
committerNick Coghlan <ncoghlan@gmail.com>2012-07-20 23:40:09 +1000
commitbe7e49fd820318509cd8b4dbde479c552f74ef62 (patch)
tree856c3693092233495f1ecadbd90c0b7e085cc70d /Lib/test
parent818b1186f9459646a4ad7015ed45ce9dfea0fa55 (diff)
downloadcpython-git-be7e49fd820318509cd8b4dbde479c552f74ef62.tar.gz
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')
-rwxr-xr-xLib/test/regrtest.py3
-rw-r--r--Lib/test/test_import.py12
2 files changed, 14 insertions, 1 deletions
diff --git a/Lib/test/regrtest.py b/Lib/test/regrtest.py
index 28655f0e65..3c8359aca1 100755
--- a/Lib/test/regrtest.py
+++ b/Lib/test/regrtest.py
@@ -165,6 +165,9 @@ example, to run all the tests except for the gui tests, give the
option '-uall,-gui'.
"""
+# We import importlib *ASAP* in order to test #15386
+import importlib
+
import builtins
import faulthandler
import getopt
diff --git a/Lib/test/test_import.py b/Lib/test/test_import.py
index 89ec8dcedc..51b52c7e0b 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):