[Zope3-checkins] CVS: Zope3/lib/python/ZODB/tests - testTransaction.py:1.11 testZODB.py:1.8

Jeremy Hylton jeremy@zope.com
Thu, 25 Jul 2002 16:56:57 -0400


Update of /cvs-repository/Zope3/lib/python/ZODB/tests
In directory cvs.zope.org:/tmp/cvs-serv12872/ZODB/tests

Modified Files:
	testTransaction.py testZODB.py 
Log Message:
Implement Rollback() for Connection.

XXX Not sure if it should be possible to rollback more than once.

Add RollbackError to POSException and do a lot of reformatting there.

In testTransaction(), make sure any current transaction is aborted
when the test ends.





=== Zope3/lib/python/ZODB/tests/testTransaction.py 1.10 => 1.11 ===
 from ZODB.DB import DB
 from ZODB.FileStorage import FileStorage
 from ZODB.tests.MinPO import MinPO
+from ZODB.POSException import RollbackError
 
 class TransactionTestBase(unittest.TestCase):
 
@@ -34,6 +35,7 @@
         self.root = conn.root()
 
     def tearDown(self):
+        get_transaction().abort()
         self.fs.close()
         for ext in '', '.index', '.lock', '.tmp':
             path = self.fs_path + ext
@@ -42,7 +44,7 @@
 
 class BasicTests:
 
-    def checkSingleCommit(self, subtrans=None):
+    def testSingleCommit(self, subtrans=None):
         self.root["a"] = MinPO("a")
         if subtrans:
             get_transaction().savepoint()
@@ -50,7 +52,7 @@
             get_transaction().commit()
         self.assertEqual(self.root["a"].value, "a")
 
-    def checkMultipleCommits(self, subtrans=None):
+    def testMultipleCommits(self, subtrans=None):
         a = self.root["a"] = MinPO("a")
         get_transaction().commit()
         a.extra_attr = MinPO("b")
@@ -62,7 +64,7 @@
         self.assertEqual(self.root["a"].value, "a")
         self.assertEqual(self.root["a"].extra_attr, MinPO("b"))
 
-    def checkCommitAndAbort(self, subtrans=None):
+    def testCommitAndAbort(self, subtrans=None):
         a = self.root["a"] = MinPO("a")
         if subtrans:
             get_transaction().savepoint()
@@ -84,20 +86,20 @@
         unbound_method(self, 1)
         get_transaction().commit() 
                             
-    checkSubSingleCommit = lambda self:\
-                           self.wrap_test(BasicTests, "checkSingleCommit")
+    testSubSingleCommit = lambda self:\
+                           self.wrap_test(BasicTests, "testSingleCommit")
 
-    checkSubMultipleCommits = lambda self:\
+    testSubMultipleCommits = lambda self:\
                               self.wrap_test(BasicTests,
-                                             "checkMultipleCommits")
+                                             "testMultipleCommits")
 
-    checkSubCommitAndAbort = lambda self:\
+    testSubCommitAndAbort = lambda self:\
                              self.wrap_test(BasicTests,
-                                            "checkCommitAndAbort")
+                                            "testCommitAndAbort")
 
 class AllTests(TransactionTestBase, BasicTests, SubtransTests):
 
-    def XXXcheckSavepointAndRollback(self):
+    def testSavepointAndRollback(self):
         self.root["a"] = MinPO()
         rb1 = get_transaction().savepoint()
         self.root["b"] = MinPO()
@@ -110,10 +112,29 @@
         self.assertEqual(len(self.root), 1)
         self.assert_("a" in self.root)
         self.assert_("b" not in self.root)
-        
+
+        self.root["c"] = MinPO()
+        rb3 = get_transaction().savepoint()
+        self.root["d"] = MinPO()
+        rb4 = get_transaction().savepoint()
+        rb3.rollback()
+        self.assertRaises(RollbackError, rb4.rollback)
+
+        self.root["e"] = MinPO()
+        rb5 = get_transaction().savepoint()
+        self.root["f"] = MinPO()
+        rb6 = get_transaction().savepoint()
+        self.root["g"] = MinPO()
+        rb6.rollback()
+        self.root["h"] = MinPO()
+        self.assertEqual(len(self.root), 3)
+        for name in "a", "e", "h":
+            self.assert_(name in self.root)
+        for name in "b", "c", "d", "f", "g":
+            self.assert_(name not in self.root)
 
 def test_suite():
-    return unittest.makeSuite(AllTests, 'check')
+    return unittest.makeSuite(AllTests)
 
 def main():
     tests = test_suite()


=== Zope3/lib/python/ZODB/tests/testZODB.py 1.7 => 1.8 ===
 class ZODBTests(unittest.TestCase, ExportImportTests):
 
     def setUp(self):
-        try:
-            os.remove('ZODBTests.fs')
-        except:
-            pass
         self._db = ZODB.FileStorage.DB("ZODBTest.fs", create=1)
         get_transaction().begin()
         conn = self._db.open()