[Python-checkins] python/dist/src/Lib/test test_importhooks.py, 1.2, 1.3

pje at users.sourceforge.net pje at users.sourceforge.net
Thu Sep 23 06:37:38 CEST 2004


Update of /cvsroot/python/python/dist/src/Lib/test
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24775/Lib/test

Modified Files:
	test_importhooks.py 
Log Message:
Fix for SF bug #1029475 : reload() doesn't work with PEP 302 loaders.


Index: test_importhooks.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_importhooks.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- test_importhooks.py	17 Feb 2003 14:51:41 -0000	1.2
+++ test_importhooks.py	23 Sep 2004 04:37:35 -0000	1.3
@@ -12,7 +12,13 @@
     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 @@
         "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 @@
 
     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 @@
             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)



More information about the Python-checkins mailing list