[Zodb-checkins] CVS: ZODB3 - test.py:1.24.8.1

Jeremy Hylton jeremy at zope.com
Mon Sep 15 14:03:06 EDT 2003


Update of /cvs-repository/ZODB3
In directory cvs.zope.org:/tmp/cvs-serv13599

Modified Files:
      Tag: Zope-2_7-branch
	test.py 
Log Message:
Take two: Merge changes from ZODB3-3_2-branch to Zope-2_7-branch.

Please make all future changes on the Zope-2_7-branch instead.

The previous attempt used "cvs up -j ZODB3-3_2-branch", but appeared
to get only a small fraction of the changes.  This attempt is based on
copying a checkout of ZODB3-3_2-branch over top of a checkout of
Zope-2_7-branch.


=== ZODB3/test.py 1.24 => 1.24.8.1 ===
--- ZODB3/test.py:1.24	Thu Apr 24 11:53:00 2003
+++ ZODB3/test.py	Mon Sep 15 14:03:05 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,8 +236,31 @@
                 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)
         if len(s) > self._maxWidth:
@@ -478,6 +506,10 @@
         self.type2all = {}
 
     def update(self):
+        from ZEO.ClientStorage import ClientStorage
+        from ZODB.DB import DB
+        from ZODB.Connection import Connection
+
         obs = sys.getobjects(0)
         type2count = {}
         type2all = {}
@@ -500,6 +532,22 @@
         for delta1, delta2, t in ct:
             if delta1 or delta2:
                 print "%-55s %8d %8d" % (t, delta1, delta2)
+                if issubclass(t, (ClientStorage, DB, Connection)):
+                    for o in obs:
+                        if isinstance(o, t):
+                            delta1 -= 1
+                            refs = gc.get_referrers(o)
+                            print sys.getrefcount(o), \
+                                   len(refs), map(type, refs)
+##                            print "Referrers"
+##                            for r in refs[2:]:
+##                                # Things that refer to the object
+##                                print "\t", type(r), \
+##                                      len(gc.get_referrers(r))
+##                                if isinstance(r, dict):
+##                                    print "\t", r.keys()
+                        if not delta1:
+                            break
 
         self.type2count = type2count
         self.type2all = type2all




More information about the Zodb-checkins mailing list