From 53089c6e91f6152bc43776587e82a0bbeb574fe0 Mon Sep 17 00:00:00 2001 From: Brett Cannon Date: Wed, 4 Jul 2012 14:03:40 -0400 Subject: [PATCH] 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. --- Lib/importlib/__init__.py | 4 ++-- Lib/importlib/test/test_api.py | 17 +++++------------ 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/Lib/importlib/__init__.py b/Lib/importlib/__init__.py index dad0833fce0..0935ada2883 100644 --- a/Lib/importlib/__init__.py +++ b/Lib/importlib/__init__.py @@ -6,8 +6,8 @@ import imp import sys try: - _bootstrap = sys.modules['_frozen_importlib'] -except KeyError: + import _frozen_importlib as _bootstrap +except ImportError: from . import _bootstrap _bootstrap._setup(sys, imp) else: diff --git a/Lib/importlib/test/test_api.py b/Lib/importlib/test/test_api.py index 8431eab6f7d..ba2a7212278 100644 --- a/Lib/importlib/test/test_api.py +++ b/Lib/importlib/test/test_api.py @@ -1,7 +1,9 @@ from . import util import imp import importlib +from importlib import machinery import sys +from test import support import unittest @@ -164,18 +166,9 @@ class FrozenImportlibTests(unittest.TestCase): def test_no_frozen_importlib(self): # Should be able to import w/o _frozen_importlib being defined. - modules = {} - for name in ('importlib', 'importlib.__init__', 'importlib._bootstrap', - '_frozen_importlib'): - 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 + module = support.import_fresh_module('importlib', blocked=['_frozen_importlib']) + self.assertFalse(isinstance(module.__loader__, + machinery.FrozenImporter)) def test_main():