[Python-checkins] r76115 - in python/branches/release31-maint: Lib/importlib/test/source/util.py Misc/NEWS

brett.cannon python-checkins at python.org
Thu Nov 5 02:34:30 CET 2009


Author: brett.cannon
Date: Thu Nov  5 02:34:30 2009
New Revision: 76115

Log:
Merged revisions 76113-76114 via svnmerge from 
svn+ssh://pythondev@svn.python.org/python/branches/py3k

........
  r76113 | brett.cannon | 2009-11-04 17:17:22 -0800 (Wed, 04 Nov 2009) | 3 lines
  
  importlib.test.source.util referenced variables in the 'finally' part of a
  try/finally which may not have been set.
........
  r76114 | brett.cannon | 2009-11-04 17:26:57 -0800 (Wed, 04 Nov 2009) | 6 lines
  
  Use tempfile.mkdtemp() instead of tempfile.tempdir for where importlib places
  source files for tests. Allows for concurrent execution of the tests by
  preventing various executions from trampling each other.
  
  Closes issue #7248.
........


Modified:
   python/branches/release31-maint/   (props changed)
   python/branches/release31-maint/Lib/importlib/test/source/util.py
   python/branches/release31-maint/Misc/NEWS

Modified: python/branches/release31-maint/Lib/importlib/test/source/util.py
==============================================================================
--- python/branches/release31-maint/Lib/importlib/test/source/util.py	(original)
+++ python/branches/release31-maint/Lib/importlib/test/source/util.py	Thu Nov  5 02:34:30 2009
@@ -42,8 +42,8 @@
     that contains the name passed into the context manager that caused the
     creation of the module.
 
-    All files are created in a temporary directory specified by
-    tempfile.gettempdir(). This directory is inserted at the beginning of
+    All files are created in a temporary directory returned by
+    tempfile.mkdtemp(). This directory is inserted at the beginning of
     sys.path. When the context manager exits all created files (source and
     bytecode) are explicitly deleted.
 
@@ -55,8 +55,10 @@
     source = 'attr = {0!r}'
     created_paths = []
     mapping = {}
+    state_manager = None
+    uncache_manager = None
     try:
-        temp_dir = tempfile.gettempdir()
+        temp_dir = tempfile.mkdtemp()
         mapping['.root'] = temp_dir
         import_names = set()
         for name in names:
@@ -85,13 +87,8 @@
         state_manager.__enter__()
         yield mapping
     finally:
-        state_manager.__exit__(None, None, None)
-        uncache_manager.__exit__(None, None, None)
-        # Reverse the order for path removal to unroll directory creation.
-        for path in reversed(created_paths):
-            if file_path.endswith('.py'):
-                support.unlink(path)
-                support.unlink(path + 'c')
-                support.unlink(path + 'o')
-            else:
-                os.rmdir(path)
+        if state_manager is not None:
+            state_manager.__exit__(None, None, None)
+        if uncache_manager is not None:
+            uncache_manager.__exit__(None, None, None)
+        support.rmtree(temp_dir)

Modified: python/branches/release31-maint/Misc/NEWS
==============================================================================
--- python/branches/release31-maint/Misc/NEWS	(original)
+++ python/branches/release31-maint/Misc/NEWS	Thu Nov  5 02:34:30 2009
@@ -134,6 +134,14 @@
 Tests
 -----
 
+- Issue #7248 (part 2): Use a unique temporary directory for importlib source
+  tests instead of tempfile.tempdir. This prevents the tests from sharing state
+  between concurrent executions on the same system.
+
+- Issue #7248: In importlib.test.source.util a try/finally block did not make
+  sure that some referenced objects actually were created in the block before
+  calling methods on the object.
+
 - Issue #7055: test___all__ now greedily detects all modules which have an
   __all__ attribute, rather than using a hardcoded and incomplete list.
 


More information about the Python-checkins mailing list