]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Merged revisions 76240 via svnmerge from
authorAntoine Pitrou <solipsis@pitrou.net>
Fri, 13 Nov 2009 16:31:51 +0000 (16:31 +0000)
committerAntoine Pitrou <solipsis@pitrou.net>
Fri, 13 Nov 2009 16:31:51 +0000 (16:31 +0000)
svn+ssh://pythondev@svn.python.org/python/branches/py3k

........
  r76240 | antoine.pitrou | 2009-11-13 17:29:04 +0100 (ven., 13 nov. 2009) | 6 lines

  Issue #6551: test_zipimport could import and then destroy some modules of
  the encodings package, which would make other tests fail further down
  the road because the internally cached encoders and decoders would point
  to empty global variables.
........

Lib/test/support.py
Lib/test/test_importhooks.py
Lib/test/test_pkg.py
Misc/NEWS

index 5672a20c9a70ffe8c4a425d465dca382f0cd407f..18fb3919e2de23bf3e46e004ce3051baed0302eb 100644 (file)
@@ -919,6 +919,23 @@ def run_doctest(module, verbosity=None):
               (module.__name__, t))
     return f, t
 
+
+#=======================================================================
+# Support for saving and restoring the imported modules.
+
+def modules_setup():
+    return sys.modules.copy(),
+
+def modules_cleanup(oldmodules):
+    # Encoders/decoders are registered permanently within the internal
+    # codec cache. If we destroy the corresponding modules their
+    # globals will be set to None which will trip up the cached functions.
+    encodings = [(k, v) for k, v in sys.modules.items()
+                 if k.startswith('encodings.')]
+    sys.modules.clear()
+    sys.modules.update(encodings)
+    sys.modules.update(oldmodules)
+
 #=======================================================================
 # Threading support to prevent reporting refleaks when running regrtest.py -R
 
index bf2870dbec5d283417dbee5743919337a531382e..1da30b7c7743c8f5b08eb60c5275db8752b7dfa8 100644 (file)
@@ -143,15 +143,14 @@ class ImportHooksBaseTestCase(unittest.TestCase):
         self.meta_path = sys.meta_path[:]
         self.path_hooks = sys.path_hooks[:]
         sys.path_importer_cache.clear()
-        self.modules_before = sys.modules.copy()
+        self.modules_before = support.modules_setup()
 
     def tearDown(self):
         sys.path[:] = self.path
         sys.meta_path[:] = self.meta_path
         sys.path_hooks[:] = self.path_hooks
         sys.path_importer_cache.clear()
-        sys.modules.clear()
-        sys.modules.update(self.modules_before)
+        support.modules_cleanup(*self.modules_before)
 
 
 class ImportHooksTestCase(ImportHooksBaseTestCase):
index 0c568bb3b55e1e68bdf8834f49c3ab0fc0588777..2e293f4fbe537022091bf09a36797da27aea7f58 100644 (file)
@@ -48,13 +48,11 @@ class TestPkg(unittest.TestCase):
         self.root = None
         self.pkgname = None
         self.syspath = list(sys.path)
-        self.sysmodules = sys.modules.copy()
+        self.modules_before = support.modules_setup()
 
     def tearDown(self):
         sys.path[:] = self.syspath
-        sys.modules.clear()
-        sys.modules.update(self.sysmodules)
-        del self.sysmodules
+        support.modules_cleanup(*self.modules_before)
         cleanout(self.root)
 
         # delete all modules concerning the tested hiearchy
index e4791cff803b4cc24ae38b7209625c88c92fa6cf..fd56e89e07b4824639d2b8e15038a0bc2c64a455 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -144,6 +144,11 @@ Extension Modules
 Tests
 -----
 
+- Issue #6551: test_zipimport could import and then destroy some modules of
+  the encodings package, which would make other tests fail further down
+  the road because the internally cached encoders and decoders would point
+  to empty global variables.
+
 - Issue #7295: Do not use a hardcoded file name in test_tarfile.
 
 - Issue #7270: Add some dedicated unit tests for multi-thread synchronization