mirror of https://github.com/python/cpython
Issue #15210: Greatly simplify the test for supporting importlib
working without _frozen_importlib by moving to an import over a direct access in sys.modules.
This commit is contained in:
parent
3bee1f1154
commit
53089c6e91
|
@ -6,8 +6,8 @@ import imp
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
try:
|
try:
|
||||||
_bootstrap = sys.modules['_frozen_importlib']
|
import _frozen_importlib as _bootstrap
|
||||||
except KeyError:
|
except ImportError:
|
||||||
from . import _bootstrap
|
from . import _bootstrap
|
||||||
_bootstrap._setup(sys, imp)
|
_bootstrap._setup(sys, imp)
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
from . import util
|
from . import util
|
||||||
import imp
|
import imp
|
||||||
import importlib
|
import importlib
|
||||||
|
from importlib import machinery
|
||||||
import sys
|
import sys
|
||||||
|
from test import support
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
|
|
||||||
|
@ -164,18 +166,9 @@ class FrozenImportlibTests(unittest.TestCase):
|
||||||
|
|
||||||
def test_no_frozen_importlib(self):
|
def test_no_frozen_importlib(self):
|
||||||
# Should be able to import w/o _frozen_importlib being defined.
|
# Should be able to import w/o _frozen_importlib being defined.
|
||||||
modules = {}
|
module = support.import_fresh_module('importlib', blocked=['_frozen_importlib'])
|
||||||
for name in ('importlib', 'importlib.__init__', 'importlib._bootstrap',
|
self.assertFalse(isinstance(module.__loader__,
|
||||||
'_frozen_importlib'):
|
machinery.FrozenImporter))
|
||||||
try:
|
|
||||||
modules[name] = sys.modules[name]
|
|
||||||
del sys.modules[name]
|
|
||||||
except KeyError:
|
|
||||||
continue
|
|
||||||
modules['_frozen_importlib'] = None
|
|
||||||
import importlib
|
|
||||||
for name, module in modules.items():
|
|
||||||
sys.modules[name] = module
|
|
||||||
|
|
||||||
|
|
||||||
def test_main():
|
def test_main():
|
||||||
|
|
Loading…
Reference in New Issue