[Zodb-checkins] CVS: ZODB3 - test.py:1.25
Jeremy Hylton
jeremy at zope.com
Mon Sep 15 12:29:24 EDT 2003
Update of /cvs-repository/ZODB3
In directory cvs.zope.org:/tmp/cvs-serv29167
Modified Files:
test.py
Log Message:
Merge changes from ZODB3-3_2-branch to Zope-2_7-branch.
Please make all future changes on the Zope-2_7-branch instead.
=== ZODB3/test.py 1.24 => 1.25 ===
--- ZODB3/test.py:1.24 Thu Apr 24 11:53:00 2003
+++ ZODB3/test.py Mon Sep 15 12:29:23 2003
@@ -144,13 +144,17 @@
import pdb
import sys
import time
-import traceback
+import errno
+import tempfile
import unittest
+import traceback
from distutils.util import get_platform
PLAT_SPEC = "%s-%s" % (get_platform(), sys.version[0:3])
+default_temp_dir = tempfile.gettempdir()
+
class ImmediateTestResult(unittest._TextTestResult):
__super_init = unittest._TextTestResult.__init__
@@ -182,6 +186,7 @@
def stopTest(self, test):
self._testtimes[test] = time.time() - self._testtimes[test]
+ self.deleteTempDir()
if gc.garbage:
print "The following test left garbage:"
print test
@@ -231,7 +236,30 @@
self._lastWidth = width
self.stream.flush()
self.__super_startTest(test)
+ self.createTempDir(test)
self._testtimes[test] = time.time()
+
+ def createTempDir(self, test):
+ # Set test-specific temp directory
+ name = test._TestCase__testMethodName # blast it
+ tempfile.tempdir = self.tempdir = os.path.join(default_temp_dir, name)
+ try:
+ os.mkdir(self.tempdir)
+ except OSError, err:
+ # If the directory already exists, that's fine. Otherwise
+ # the test is going to fail if it uses a tempfile, so raise.
+ if err[0] != errno.EEXIST:
+ raise
+
+ def deleteTempDir(self):
+ try:
+ os.rmdir(self.tempdir)
+ except OSError, err:
+ # If there's an error other than a non-empty directory, print
+ # a warning; continue in any case.
+ # Caution: errno.ENOTEMPTY doesn't work x-platform.
+ if len(os.listdir(self.tempdir)) == 0:
+ print "in test.py's deleteTempDir():", err
def getShortDescription(self, test):
s = self.getDescription(test)
More information about the Zodb-checkins
mailing list