[Zodb-checkins] CVS: Zope/lib/python/ZODB/tests - testTransaction.py:1.5

Kapil Thangavelu k_vertigo@yahoo.com
Tue, 12 Mar 2002 14:44:14 -0500


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

Added Files:
	testTransaction.py 
Log Message:
more extensive unittesting for the transaction framework. two tests currently 
don't pass, and have been prefixed by 'BUG'



=== Zope/lib/python/ZODB/tests/testTransaction.py 1.4 => 1.5 === (558/658 lines abridged)
+#
+# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+# 
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE
+# 
+##############################################################################
+
+"""
+Revision information:
+$Id$
+"""
+
+"""
+
+I wrote these unittests to investigate some odd transaction
+behavior when doing unittests of integrating non sub transaction
+aware objects, and to insure proper txn behavior. these
+tests test the transaction system independent of the rest of the
+zodb.
+
+you can see the method calls to a jar by passing the
+keyword arg tracing to the modify method of a dataobject.
+the value of the arg is a prefix used for tracing print calls
+to that objects jar.
+
+the number of times a jar method was called can be inspected
+by looking at an attribute of the jar that is the method
+name prefixed with a c (count/check).
+
+i've included some tracing examples for tests that i thought
+were illuminating as doc strings below.
+
+TODO
+
+    add in tests for objects which are modified multiple times,
+    for example an object that gets modified in multiple sub txns.
+    
+"""
+
+import unittest
+
+from types import TupleType
+
+from ZODB import Transaction

[-=- -=- -=- 558 lines omitted -=- -=- -=-]

+        
+        if (type(self.errors) is TupleType and method in self.errors) or \
+            method == self.errors:
+            
+            raise TestTxnException(" error %s"%method)
+
+    ## basic jar txn interface 
+
+    def abort(self, *args):
+        self.check('abort')
+        self.cabort += 1
+        
+    def commit(self, *args):
+        self.check('commit')
+        self.ccommit += 1
+
+    def tpc_begin(self, txn, sub=0):
+        self.check('tpc_begin')
+        self.ctpc_begin += 1
+
+    def tpc_vote(self, *args):
+        self.check('tpc_vote')
+        self.ctpc_vote += 1
+
+    def tpc_abort(self, *args):
+        self.check('tpc_abort')
+        self.ctpc_abort += 1
+
+    def tpc_finish(self, *args):
+        self.check('tpc_finish')
+        self.ctpc_finish += 1
+
+class SubTransactionJar(BasicJar):
+
+    def abort_sub(self, txn):
+        self.check('abort_sub')
+        self.cabort_sub = 1
+    
+    def commit_sub(self, txn):
+        self.check('commit_sub')
+        self.ccommit_sub = 1
+        
+class NoSubTransactionJar(BasicJar): pass
+
+def test_suite():
+
+    return unittest.makeSuite(TransactionTests)
+
+if __name__ == '__main__':
+    unittest.TextTestRunner().run(test_suite())