[Zope3-checkins] CVS: ZODB4/src/zodb/storage/tests - base.py:1.4
Barry Warsaw
barry@wooz.org
Fri, 24 Jan 2003 13:55:33 -0500
Update of /cvs-repository/ZODB4/src/zodb/storage/tests
In directory cvs.zope.org:/tmp/cvs-serv8043
Modified Files:
base.py
Log Message:
BerkeleyTestBase: Refactor the way storages are set up and torn down.
=== ZODB4/src/zodb/storage/tests/base.py 1.3 => 1.4 ===
--- ZODB4/src/zodb/storage/tests/base.py:1.3 Wed Jan 22 14:44:58 2003
+++ ZODB4/src/zodb/storage/tests/base.py Fri Jan 24 13:55:31 2003
@@ -24,6 +24,7 @@
import sys
import errno
import types
+import shutil
import unittest
from transaction import get_transaction
@@ -195,40 +196,48 @@
class BerkeleyTestBase(StorageTestBase):
- def _zap_dbhome(self, dir):
- # If the tests exited with any uncommitted objects, they'll blow up
- # subsequent tests because the next transaction commit will try to
- # commit those object. But they're tied to closed databases, so
- # that's broken. Aborting the transaction now saves us the headache.
- try:
- for file in os.listdir(dir):
- os.unlink(os.path.join(dir, file))
- os.removedirs(dir)
- except OSError, e:
- if e.errno <> errno.ENOENT:
- raise
-
- def _mk_dbhome(self, dir):
+ def _config(self):
# Checkpointing just slows the tests down because we have to wait for
# the thread to properly shutdown. This can take up to 10 seconds, so
# for the purposes of the test suite we shut off this thread.
config = BerkeleyConfig()
config.interval = 0
+ return config
+
+ def _envdir(self):
+ return DBHOME
+
+ def _open(self):
+ self._storage = self.ConcreteStorage(self._envdir(), self._config())
+
+ def _zap_dbhome(self, dir=None):
+ if dir is None:
+ dir = self._envdir()
+ # XXX Pre-Python 2.3 doesn't ignore errors if the first arg doesn't
+ # exist, even if the second is True.
+ try:
+ shutil.rmtree(dir, True)
+ except OSError, e:
+ if e.errno <> errno.ENOENT: raise
+
+ def _mk_dbhome(self, dir=None):
+ if dir is None:
+ dir = self._get_envdir()
os.mkdir(dir)
try:
- return self.ConcreteStorage(dir, config=config)
+ return self.ConcreteStorage(dir, config=self._config())
except:
- self._zap_dbhome(dir)
+ self._zap_dbhome()
raise
def setUp(self):
StorageTestBase.setUp(self)
- self._zap_dbhome(DBHOME)
- self._storage = self._mk_dbhome(DBHOME)
+ self._zap_dbhome()
+ self._open()
def tearDown(self):
StorageTestBase.tearDown(self)
- self._zap_dbhome(DBHOME)
+ self._zap_dbhome()