[Zodb-checkins] CVS: StandaloneZODB/ZODB/tests - Corruption.py:1.5 StorageTestBase.py:1.16 testFileStorage.py:1.18 testZODB.py:1.3

Jeremy Hylton jeremy@zope.com
Thu, 8 Aug 2002 14:25:11 -0400


Update of /cvs-repository/StandaloneZODB/ZODB/tests
In directory cvs.zope.org:/tmp/cvs-serv17911/ZODB/tests

Modified Files:
	Corruption.py StorageTestBase.py testFileStorage.py 
	testZODB.py 
Log Message:
Refactor test cleanup to use removefs() helper function.

StorageTestBase.removefs() will attempt to remove files with all the
possible extensions that FileStorage will create.  It will raise
os.error for any error except ENOENT.

Remove many variants of removefs() implemented in the various test
suites.


=== StandaloneZODB/ZODB/tests/Corruption.py 1.4 => 1.5 ===
--- StandaloneZODB/ZODB/tests/Corruption.py:1.4	Fri Jan 25 12:03:25 2002
+++ StandaloneZODB/ZODB/tests/Corruption.py	Thu Aug  8 14:25:10 2002
@@ -7,7 +7,7 @@
 import unittest
 
 import ZODB, ZODB.FileStorage
-from StorageTestBase import StorageTestBase
+from StorageTestBase import StorageTestBase, removefs
 
 class FileStorageCorruptTests(StorageTestBase):
 
@@ -17,10 +17,7 @@
 
     def tearDown(self):
         self._storage.close()
-        for ext in '', '.old', '.tmp', '.lock', '.index':
-            path = self.path + ext
-            if os.path.exists(path):
-                os.remove(path)
+        removefs(self.path)
 
     def _do_stores(self):
         oids = []


=== StandaloneZODB/ZODB/tests/StorageTestBase.py 1.15 => 1.16 ===
--- StandaloneZODB/ZODB/tests/StorageTestBase.py:1.15	Fri Jan 25 12:30:42 2002
+++ StandaloneZODB/ZODB/tests/StorageTestBase.py	Thu Aug  8 14:25:10 2002
@@ -6,6 +6,8 @@
 single object revision.
 """
 
+import errno
+import os
 import pickle
 import string
 import sys
@@ -105,6 +107,16 @@
     mod = __import__(name)
     return sys.modules[name]
 
+def removefs(base):
+    """Remove all files created by FileStorage with path base."""
+    for ext in '', '.old', '.tmp', '.lock', '.index', '.pack':
+        path = base + ext
+        try:
+            os.remove(path)
+        except os.error, err:
+            if err[0] != errno.ENOENT:
+                raise
+        
 
 class StorageTestBase(unittest.TestCase):
 


=== StandaloneZODB/ZODB/tests/testFileStorage.py 1.17 => 1.18 ===
--- StandaloneZODB/ZODB/tests/testFileStorage.py:1.17	Mon Apr 22 18:23:48 2002
+++ StandaloneZODB/ZODB/tests/testFileStorage.py	Thu Aug  8 14:25:10 2002
@@ -44,10 +44,7 @@
 
     def tearDown(self):
         self._storage.close()
-        for ext in '', '.old', '.tmp', '.lock', '.index':
-            path = 'FileStorageTests.fs' + ext
-            if os.path.exists(path):
-                os.remove(path)
+        StorageTestBase.removefs("FileStorageTests.fs")
 
     def checkLongMetadata(self):
         s = "X" * 75000
@@ -76,13 +73,8 @@
     def tearDown(self):
         self._storage.close()
         self._dst.close()
-        for ext in '', '.old', '.tmp', '.lock', '.index':
-            for fs in 'Source', 'Dest':
-                path = fs + '.fs' + ext
-                try:
-                    os.remove(path)
-                except OSError, e:
-                    if e.errno <> errno.ENOENT: raise
+        StorageTestBase.removefs("Source.fs")
+        StorageTestBase.removefs("Dest.fs")
 
     def checkSimpleRecovery(self):
         oid = self._storage.new_oid()


=== StandaloneZODB/ZODB/tests/testZODB.py 1.2 => 1.3 ===
--- StandaloneZODB/ZODB/tests/testZODB.py:1.2	Wed Jun 12 16:39:20 2002
+++ StandaloneZODB/ZODB/tests/testZODB.py	Thu Aug  8 14:25:10 2002
@@ -3,6 +3,7 @@
 import ZODB
 import ZODB.FileStorage
 from ZODB.PersistentMapping import PersistentMapping
+from ZODB.tests.StorageTestBase import removefs
 import unittest
 
 class ExportImportTests:
@@ -76,8 +77,6 @@
 class ZODBTests(unittest.TestCase, ExportImportTests):
 
     def setUp(self):
-        try: os.remove('ZODBTests.fs')
-        except: pass
         self._storage = ZODB.FileStorage.FileStorage(
             'ZODBTests.fs', create=1)
         self._db = ZODB.DB(self._storage)
@@ -93,7 +92,7 @@
 
     def tearDown(self):
         self._storage.close()
-        os.remove('ZODBTests.fs')
+        removefs("ZODBTests.fs")
 
 def test_suite():
     return unittest.makeSuite(ZODBTests, 'check')