cpython: 3e8f0111feed (original) (raw)
Mercurial > cpython
changeset 69957:3e8f0111feed
#11910: merge with 3.2. [#11910]
Ezio Melotti ezio.melotti@gmail.com | |
---|---|
date | Mon, 09 May 2011 06:44:36 +0300 |
parents | e7d8713f95f3(current diff)754bafe8db5f(diff) |
children | 3449406fd04a |
files | Lib/test/support.py |
diffstat | 1 files changed, 8 insertions(+), 4 deletions(-)[+] [-] Lib/test/support.py 12 |
line wrap: on
line diff
--- a/Lib/test/support.py +++ b/Lib/test/support.py @@ -91,12 +91,14 @@ def import_module(name, deprecated=False def _save_and_remove_module(name, orig_modules): """Helper function to save and remove a module from sys.modules
Return value is True if the module was in sys.modules and[](#l1.7)
False otherwise."""[](#l1.8)
Return True if the module was in sys.modules, False otherwise.[](#l1.9)
saved = True try: orig_modules[name] = sys.modules[name] except KeyError:Raise ImportError if the module can't be imported."""[](#l1.10)
# try to import the module and raise an error if it can't be imported[](#l1.15)
else: del sys.modules[name]__import__(name)[](#l1.16) saved = False[](#l1.17)
@@ -106,8 +108,7 @@ def _save_and_remove_module(name, orig_m def _save_and_block_module(name, orig_modules): """Helper function to save and block a module in sys.modules
Return value is True if the module was in sys.modules and[](#l1.24)
False otherwise."""[](#l1.25)
saved = True try: orig_modules[name] = sys.modules[name]Return True if the module was in sys.modules, False otherwise."""[](#l1.26)
@@ -123,6 +124,7 @@ def import_fresh_module(name, fresh=(), the sys.modules cache is restored to its original state. Modules named in fresh are also imported anew if needed by the import.
Importing of modules named in blocked is prevented while the fresh import takes place. @@ -144,6 +146,8 @@ def import_fresh_module(name, fresh=(), if not _save_and_block_module(blocked_name, orig_modules): names_to_remove.append(blocked_name) fresh_module = importlib.import_module(name)
except ImportError:[](#l1.42)
fresh_module = None[](#l1.43) finally:[](#l1.44) for orig_name, module in orig_modules.items():[](#l1.45) sys.modules[orig_name] = module[](#l1.46)