[Numpy-svn] r6205 - trunk/numpy/lib/tests

numpy-svn@scip... numpy-svn@scip...
Sat Dec 27 05:46:11 CST 2008


Author: cdavid
Date: 2008-12-27 05:46:08 -0600 (Sat, 27 Dec 2008)
New Revision: 6205

Modified:
   trunk/numpy/lib/tests/test_io.py
Log:
BUG (#827): close temp file before reopning them on windows, and make sure they are not automatically deleted on close either (2.6and higher specific).

Modified: trunk/numpy/lib/tests/test_io.py
===================================================================
--- trunk/numpy/lib/tests/test_io.py	2008-12-27 10:57:05 UTC (rev 6204)
+++ trunk/numpy/lib/tests/test_io.py	2008-12-27 11:46:08 UTC (rev 6205)
@@ -3,7 +3,11 @@
 import StringIO
 
 from tempfile import NamedTemporaryFile
+import sys
 
+
+MAJVER, MINVER = sys.version_info[:2]
+
 class RoundtripTest:
     def roundtrip(self, save_func, *args, **kwargs):
         """
@@ -25,7 +29,14 @@
         file_on_disk = kwargs.get('file_on_disk', False)
 
         if file_on_disk:
-            target_file = NamedTemporaryFile()
+            # Do not delete the file on windows, because we can't
+            # reopen an already opened file on that platform, so we
+            # need to close the file and reopen it, implying no
+            # automatic deletion.
+            if sys.platform == 'win32' and MAJVER >= 2 and MINVER >= 6:
+                target_file = NamedTemporaryFile(delete=False)
+            else:
+                target_file = NamedTemporaryFile()
             load_file = target_file.name
         else:
             target_file = StringIO.StringIO()
@@ -37,6 +48,9 @@
         target_file.flush()
         target_file.seek(0)
 
+        if sys.platform == 'win32' and not isinstance(target_file, StringIO.StringIO):
+            target_file.close()
+
         arr_reloaded = np.load(load_file, **load_kwds)
 
         self.arr = arr



More information about the Numpy-svn mailing list