[Checkins] SVN: zope.testing/trunk/src/zope/testing/setupstack. More carefully remove temporary directories to deal with read-only files on windows

Jim Fulton jim at zope.com
Fri Oct 17 14:23:58 EDT 2008


Log message for revision 92340:
  More carefully remove temporary directories to deal with read-only files on windows

Changed:
  U   zope.testing/trunk/src/zope/testing/setupstack.py
  U   zope.testing/trunk/src/zope/testing/setupstack.txt

-=-
Modified: zope.testing/trunk/src/zope/testing/setupstack.py
===================================================================
--- zope.testing/trunk/src/zope/testing/setupstack.py	2008-10-17 17:43:09 UTC (rev 92339)
+++ zope.testing/trunk/src/zope/testing/setupstack.py	2008-10-17 18:23:57 UTC (rev 92340)
@@ -16,7 +16,7 @@
 See setupstack.txt
 """
 
-import os, shutil, tempfile
+import os, stat, tempfile
 
 key = '__' + __name__
 
@@ -34,9 +34,19 @@
 
 def setUpDirectory(test):
     tmp = tempfile.mkdtemp()
-    register(test, shutil.rmtree, tmp)
+    register(test, rmtree, tmp)
     here = os.getcwd()
     register(test, os.chdir, here)
     os.chdir(tmp)
 
+def rmtree(path):
+    for path, dirs, files in os.walk(path, False):
+        for fname in files:
+            fname = os.path.join(path, fname)
+            os.chmod(fname, stat.S_IWUSR)
+            os.remove(fname)
+        for dname in dirs:
+            dname = os.path.join(path, dname)
+            os.rmdir(dname)
+    os.rmdir(path)
     

Modified: zope.testing/trunk/src/zope/testing/setupstack.txt
===================================================================
--- zope.testing/trunk/src/zope/testing/setupstack.txt	2008-10-17 17:43:09 UTC (rev 92339)
+++ zope.testing/trunk/src/zope/testing/setupstack.txt	2008-10-17 18:23:57 UTC (rev 92340)
@@ -80,6 +80,13 @@
     >>> os.path.exists('Data.fs')
     True
 
+We'll make the file read-only. This can cause problems on Windows, but
+setupstack takes care of that by making files writable before trying
+to remove them.
+
+    >>> import stat
+    >>> os.chmod('Data.fs', stat.S_IREAD)
+
 When tearDown is called:
 
     >>> zope.testing.setupstack.tearDown(test)



More information about the Checkins mailing list