[Checkins] SVN: transaction/branches/sphinx/ Coverage for TransactionManager as a context manager.

Tres Seaver cvs-admin at zope.org
Mon Dec 17 22:09:13 UTC 2012


Log message for revision 128723:
  Coverage for TransactionManager as a context manager.

Changed:
  _U  transaction/branches/sphinx/
  U   transaction/branches/sphinx/transaction/tests/test__manager.py

-=-
Modified: transaction/branches/sphinx/transaction/tests/test__manager.py
===================================================================
--- transaction/branches/sphinx/transaction/tests/test__manager.py	2012-12-17 22:09:11 UTC (rev 128722)
+++ transaction/branches/sphinx/transaction/tests/test__manager.py	2012-12-17 22:09:12 UTC (rev 128723)
@@ -157,6 +157,38 @@
         tm.abort()
         self.assertTrue(txn._aborted)
 
+    def test_as_context_manager_wo_error(self):
+        class _Test(object):
+            _committed = False
+            _aborted = False
+            def commit(self):
+                self._committed = True
+            def abort(self):
+                self._aborted = True
+        tm = self._makeOne()
+        with tm:
+            tm._txn = txn = _Test()
+        self.assertTrue(txn._committed)
+        self.assertFalse(txn._aborted)
+
+    def test_as_context_manager_w_error(self):
+        class _Test(object):
+            _committed = False
+            _aborted = False
+            def commit(self):
+                self._committed = True
+            def abort(self):
+                self._aborted = True
+        tm = self._makeOne()
+        try:
+            with tm:
+                tm._txn = txn = _Test()
+                1/0
+        except ZeroDivisionError: 
+            pass
+        self.assertFalse(txn._committed)
+        self.assertTrue(txn._aborted)
+
     # basic tests with two sub trans jars
     # really we only need one, so tests for
     # sub1 should identical to tests for sub2



More information about the checkins mailing list