[Checkins] SVN: transaction/branches/sphinx/ Factory out dummy logger.

Tres Seaver cvs-admin at zope.org
Mon Dec 17 23:58:01 UTC 2012


Log message for revision 128738:
  Factory out dummy logger.

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

-=-
Modified: transaction/branches/sphinx/transaction/tests/common.py
===================================================================
--- transaction/branches/sphinx/transaction/tests/common.py	2012-12-17 23:58:00 UTC (rev 128737)
+++ transaction/branches/sphinx/transaction/tests/common.py	2012-12-17 23:58:00 UTC (rev 128738)
@@ -22,6 +22,24 @@
         self._lines.extend(lines)
 
 
+class DummyLogger(object):
+    def __init__(self):
+        self._clear()
+    def _clear(self):
+        self._log = []
+    def log(self, level, msg, *args, **kw):
+        if args:
+            self._log.append((level, msg % args))
+        elif kw:
+            self._log.append((level, msg % kw))
+        else:
+            self._log.append((level, msg))
+    def debug(self, msg, *args, **kw):
+        self.log('DEBUG', msg, *args, **kw)
+    def error(self, msg, *args, **kw):
+        self.log('error', msg, *args, **kw)
+
+
 class Monkey(object):
     # context-manager for replacing module names in the scope of a test.
     def __init__(self, module, **kw):

Modified: transaction/branches/sphinx/transaction/tests/test__manager.py
===================================================================
--- transaction/branches/sphinx/transaction/tests/test__manager.py	2012-12-17 23:58:00 UTC (rev 128737)
+++ transaction/branches/sphinx/transaction/tests/test__manager.py	2012-12-17 23:58:00 UTC (rev 128738)
@@ -313,49 +313,58 @@
     # first the recoverable errors
 
     def test_abort_w_broken_jar(self):
+        from transaction import _transaction
+        from transaction.tests.common import DummyLogger
+        from transaction.tests.common import Monkey
+        logger = DummyLogger()
+        with Monkey(_transaction, _LOGGER=logger):
+            mgr, sub1, sub2, sub3, nosub1 = self._makePopulated()
+            sub1._p_jar = BasicJar(errors='abort')
+            nosub1.modify()
+            sub1.modify(nojar=1)
+            sub2.modify()
+            try:
+                mgr.abort()
+            except TestTxnException:
+                pass
 
-        mgr, sub1, sub2, sub3, nosub1 = self._makePopulated()
-        sub1._p_jar = BasicJar(errors='abort')
-
-        nosub1.modify()
-        sub1.modify(nojar=1)
-        sub2.modify()
-
-        try:
-            mgr.abort()
-        except TestTxnException: pass
-
         assert nosub1._p_jar.cabort == 1
         assert sub2._p_jar.cabort == 1
 
     def test_commit_w_broken_jar_commit(self):
+        from transaction import _transaction
+        from transaction.tests.common import DummyLogger
+        from transaction.tests.common import Monkey
+        logger = DummyLogger()
+        with Monkey(_transaction, _LOGGER=logger):
+            mgr, sub1, sub2, sub3, nosub1 = self._makePopulated()
+            sub1._p_jar = BasicJar(errors='commit')
+            nosub1.modify()
+            sub1.modify(nojar=1)
+            try:
+                mgr.commit()
+            except TestTxnException:
+                pass
 
-        mgr, sub1, sub2, sub3, nosub1 = self._makePopulated()
-        sub1._p_jar = BasicJar(errors='commit')
-
-        nosub1.modify()
-        sub1.modify(nojar=1)
-
-        try:
-            mgr.commit()
-        except TestTxnException: pass
-
         assert nosub1._p_jar.ctpc_finish == 0
         assert nosub1._p_jar.ccommit == 1
         assert nosub1._p_jar.ctpc_abort == 1
 
     def test_commit_w_broken_jar_tpc_vote(self):
+        from transaction import _transaction
+        from transaction.tests.common import DummyLogger
+        from transaction.tests.common import Monkey
+        logger = DummyLogger()
+        with Monkey(_transaction, _LOGGER=logger):
+            mgr, sub1, sub2, sub3, nosub1 = self._makePopulated()
+            sub1._p_jar = BasicJar(errors='tpc_vote')
+            nosub1.modify()
+            sub1.modify(nojar=1)
+            try:
+                mgr.commit()
+            except TestTxnException:
+                pass
 
-        mgr, sub1, sub2, sub3, nosub1 = self._makePopulated()
-        sub1._p_jar = BasicJar(errors='tpc_vote')
-
-        nosub1.modify()
-        sub1.modify(nojar=1)
-
-        try:
-            mgr.commit()
-        except TestTxnException: pass
-
         assert nosub1._p_jar.ctpc_finish == 0
         assert nosub1._p_jar.ccommit == 1
         assert nosub1._p_jar.ctpc_abort == 1
@@ -371,32 +380,38 @@
         # sub calling method abort
         # sub calling method tpc_abort
         # nosub calling method tpc_abort
-        mgr, sub1, sub2, sub3, nosub1 = self._makePopulated()
-        sub1._p_jar = BasicJar(errors='tpc_begin')
+        from transaction import _transaction
+        from transaction.tests.common import DummyLogger
+        from transaction.tests.common import Monkey
+        logger = DummyLogger()
+        with Monkey(_transaction, _LOGGER=logger):
+            mgr, sub1, sub2, sub3, nosub1 = self._makePopulated()
+            sub1._p_jar = BasicJar(errors='tpc_begin')
+            nosub1.modify()
+            sub1.modify(nojar=1)
+            try:
+                mgr.commit()
+            except TestTxnException:
+                pass
 
-        nosub1.modify()
-        sub1.modify(nojar=1)
-
-        try:
-            mgr.commit()
-        except TestTxnException:
-            pass
-
         assert nosub1._p_jar.ctpc_abort == 1
         assert sub1._p_jar.ctpc_abort == 1
 
     def test_commit_w_broken_jar_tpc_abort_tpc_vote(self):
-        mgr, sub1, sub2, sub3, nosub1 = self._makePopulated()
-        sub1._p_jar = BasicJar(errors=('tpc_abort', 'tpc_vote'))
+        from transaction import _transaction
+        from transaction.tests.common import DummyLogger
+        from transaction.tests.common import Monkey
+        logger = DummyLogger()
+        with Monkey(_transaction, _LOGGER=logger):
+            mgr, sub1, sub2, sub3, nosub1 = self._makePopulated()
+            sub1._p_jar = BasicJar(errors=('tpc_abort', 'tpc_vote'))
+            nosub1.modify()
+            sub1.modify(nojar=1)
+            try:
+                mgr.commit()
+            except TestTxnException:
+                pass
 
-        nosub1.modify()
-        sub1.modify(nojar=1)
-
-        try:
-            mgr.commit()
-        except TestTxnException:
-            pass
-
         assert nosub1._p_jar.ctpc_abort == 1
 
 

Modified: transaction/branches/sphinx/transaction/tests/test__transaction.py
===================================================================
--- transaction/branches/sphinx/transaction/tests/test__transaction.py	2012-12-17 23:58:00 UTC (rev 128737)
+++ transaction/branches/sphinx/transaction/tests/test__transaction.py	2012-12-17 23:58:00 UTC (rev 128738)
@@ -50,6 +50,7 @@
 
     def test_ctor_defaults(self):
         from transaction.weakset import WeakSet
+        from transaction.tests.common import DummyLogger
         from transaction.tests.common import Monkey
         from transaction import _transaction
         logger = DummyLogger()
@@ -198,6 +199,7 @@
         from weakref import WeakKeyDictionary
         from transaction import _transaction
         from transaction._transaction import Savepoint
+        from transaction.tests.common import DummyLogger
         from transaction.tests.common import Monkey
         logger = DummyLogger()
         with Monkey(_transaction, _LOGGER=logger):
@@ -214,6 +216,7 @@
         from transaction import _transaction
         from transaction._transaction import Status
         from transaction._compat import StringIO
+        from transaction.tests.common import DummyLogger
         from transaction.tests.common import Monkey
         logger = DummyLogger()
         with Monkey(_transaction, _LOGGER=logger):
@@ -255,6 +258,8 @@
             def __init__(self, t, index):
                 self.transaction = t
                 self._index = index
+            def __lt__(self, other):
+                return self._index < other._index
             def __repr__(self):
                 return '_SP: %d' % self._index
         holdme = []
@@ -385,24 +390,6 @@
         transaction.abort() # should do nothing
         self.assertEqual(list(dm.keys()), ['a'])
 
-
-class DummyLogger(object):
-    def __init__(self):
-        self._clear()
-    def _clear(self):
-        self._log = []
-    def log(self, level, msg, *args, **kw):
-        if args:
-            self._log.append((level, msg % args))
-        elif kw:
-            self._log.append((level, msg % kw))
-        else:
-            self._log.append((level, msg))
-    def debug(self, msg, *args, **kw):
-        self.log('DEBUG', msg, *args, **kw)
-    def error(self, msg, *args, **kw):
-        self.log('error', msg, *args, **kw)
-
 def test_suite():
     return unittest.TestSuite((
         unittest.makeSuite(TransactionTests),



More information about the checkins mailing list