osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Python-Dev] Tests failing on Windows with TESTFN


On Sun, Jul 29, 2018 at 3:13 AM Tim Golden <mail at timgolden.me.uk> wrote:
> For an example:
>
> http://tjg.org.uk/test.log

Thank you!  After inspecting all the errors, it does seem that they
are ALL caused by "bare" os.unlink/rmdir calls.  So it seems that a
massive undertaking of ferreting out these locations and replacing
them with their support equivalents would be needed to have a passing
test suite for you.

Unfortunately, test_mailbox is failing due to the same fate, but
within the stdlib itself.  The fix for that will probably need to be a
rename/delete dance.

diff --git a/Lib/mailbox.py b/Lib/mailbox.py
index 056251d..23662f2 100644
--- a/Lib/mailbox.py
+++ b/Lib/mailbox.py
@@ -701,8 +701,10 @@ class _singlefileMailbox(Mailbox):
         try:
             os.rename(new_file.name, self._path)
         except FileExistsError:
-            os.remove(self._path)
+            temp_name = _create_temporary_name(self._path)
+            os.rename(self._path, temp_name)
             os.rename(new_file.name, self._path)
+            os.remove(temp_name)
         self._file = open(self._path, 'rb+')
         self._toc = new_toc
         self._pending = False
@@ -2112,11 +2114,14 @@ def _create_carefully(path):
     finally:
         os.close(fd)

+def _create_temporary_name(path):
+    """Create a temp filename based on path."""
+    return '%s.%s.%s.%s' % (path, int(time.time()), socket.gethostname(),
+                            os.getpid())
+
 def _create_temporary(path):
     """Create a temp file based on path and open for reading and writing."""
-    return _create_carefully('%s.%s.%s.%s' % (path, int(time.time()),
-                                              socket.gethostname(),
-                                              os.getpid()))
+    return _create_carefully(_create_temporary_name(path))

 def _sync_flush(f):
     """Ensure changes to file f are physically on disk."""


-- 
Jeremy Kloth