[Zodb-checkins] CVS: Packages/bsddb3Storage - ZODBTestBase.py:1.2

barry@digicool.com barry@digicool.com
Mon, 16 Apr 2001 16:11:34 -0400 (EDT)


Update of /cvs-repository/Packages/bsddb3Storage/test
In directory korak:/tmp/cvs-serv13757

Modified Files:
	ZODBTestBase.py 
Log Message:
Fleshed out as the base class for testing storages at the ZODB level.



--- Updated File ZODBTestBase.py in package Packages/bsddb3Storage --
--- ZODBTestBase.py	2001/04/11 22:19:41	1.1
+++ ZODBTestBase.py	2001/04/16 20:11:34	1.2
@@ -1,2 +1,38 @@
-# Unit tests at the ZODB layer
+# Base class for unit tests at the ZODB layer
 
+import os
+import errno
+import unittest
+
+from ZODB import DB
+
+DBHOME = 'test-db'
+
+
+
+class ZODBTestBase(unittest.TestCase):
+    def setUp(self):
+        os.mkdir(DBHOME)
+
+        try:
+            self._storage = self.ConcreteStorage(DBHOME)
+            self._db = DB(self._storage)
+            self._conn = self._db.open()
+            self._root = self._conn.root()
+        except:
+            self.tearDown()
+            raise
+
+    def _close(self):
+        self._db.close()
+
+    def tearDown(self):
+        # 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.
+        get_transaction().abort()
+        self._close()
+        for file in os.listdir(DBHOME):
+            os.unlink(os.path.join(DBHOME, file))
+        os.removedirs(DBHOME)