diff options
author | Phillip J. Eby <pje@telecommunity.com> | 2004-09-23 04:37:36 (GMT) |
---|---|---|
committer | Phillip J. Eby <pje@telecommunity.com> | 2004-09-23 04:37:36 (GMT) |
commit | 7ec642a4d2ee98dfc0b67431255046374abc4ed7 (patch) | |
tree | b018d53945c80947cd15fa8efe369fac64d7657a /Lib/test | |
parent | f4aca755bc9f26b51b6820a162a3f76c2a1a1abc (diff) | |
download | cpython-7ec642a4d2ee98dfc0b67431255046374abc4ed7.zip cpython-7ec642a4d2ee98dfc0b67431255046374abc4ed7.tar.gz cpython-7ec642a4d2ee98dfc0b67431255046374abc4ed7.tar.bz2 |
Fix for SF bug #1029475 : reload() doesn't work with PEP 302 loaders.
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_importhooks.py | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/Lib/test/test_importhooks.py b/Lib/test/test_importhooks.py index 4191a17..5ece533 100644 --- a/Lib/test/test_importhooks.py +++ b/Lib/test/test_importhooks.py @@ -12,7 +12,13 @@ def get_file(): return __file__ """ +reload_src = test_src+"""\ +reloaded = True +""" + test_co = compile(test_src, "<???>", "exec") +reload_co = compile(reload_src, "<???>", "exec") + test_path = "!!!_test_!!!" @@ -32,6 +38,7 @@ class TestImporter: "hooktestpackage": (True, test_co), "hooktestpackage.sub": (True, test_co), "hooktestpackage.sub.subber": (False, test_co), + "reloadmodule": (False, test_co), } def __init__(self, path=test_path): @@ -52,8 +59,7 @@ class TestImporter: def load_module(self, fullname): ispkg, code = self.modules[fullname] - mod = imp.new_module(fullname) - sys.modules[fullname] = mod + mod = sys.modules.setdefault(fullname,imp.new_module(fullname)) mod.__file__ = "<%s>" % self.__class__.__name__ mod.__loader__ = self if ispkg: @@ -163,6 +169,14 @@ class ImportHooksTestCase(ImportHooksBaseTestCase): self.assertEqual(hooktestpackage.sub.__loader__, importer) self.assertEqual(hooktestpackage.sub.subber.__loader__, importer) + TestImporter.modules['reloadmodule'] = (False, test_co) + import reloadmodule + self.failIf(hasattr(reloadmodule,'reloaded')) + + TestImporter.modules['reloadmodule'] = (False, reload_co) + reload(reloadmodule) + self.failUnless(hasattr(reloadmodule,'reloaded')) + def testMetaPath(self): i = MetaImporter() sys.meta_path.append(i) |