[Checkins] SVN: BTrees/trunk/ Run functests only if ZODB is importable.

Tres Seaver cvs-admin at zope.org
Thu Oct 18 15:13:51 UTC 2012


Log message for revision 128061:
  Run functests only if ZODB is importable.

Changed:
  _U  BTrees/trunk/
  U   BTrees/trunk/BTrees/tests/testBTrees.py
  U   BTrees/trunk/BTrees/tests/testConflict.py

-=-
Modified: BTrees/trunk/BTrees/tests/testBTrees.py
===================================================================
--- BTrees/trunk/BTrees/tests/testBTrees.py	2012-10-18 12:21:52 UTC (rev 128060)
+++ BTrees/trunk/BTrees/tests/testBTrees.py	2012-10-18 15:13:47 UTC (rev 128061)
@@ -13,7 +13,17 @@
 ##############################################################################
 import unittest
 
+def _skip_wo_ZODB(test_method): #pragma NO COVER
+    try:
+        import ZODB
+    except ImportError: # skip this test if ZODB is not available
+        def _dummy(*args):
+            pass
+        return _dummy
+    else:
+        return test_method
 
+
 class Base(object):
     # Tests common to all types: sets, buckets, and BTrees 
 
@@ -43,7 +53,8 @@
     def _closeRoot(self, root):
         root._p_jar.close()
 
-    def functestLoadAndStore(self):
+    @_skip_wo_ZODB
+    def testLoadAndStore(self):
         import transaction
         for i in 0, 10, 1000:
             t = self._makeOne()
@@ -70,7 +81,8 @@
         else:
             raise AssertionError("Expected exception")
 
-    def functestGhostUnghost(self):
+    @_skip_wo_ZODB
+    def testGhostUnghost(self):
         import transaction
         for i in 0, 10, 1000:
             t = self._makeOne()
@@ -126,7 +138,8 @@
         self.assertEqual(list(t.keys(0, 2, excludemin=True, excludemax=True)),
                          [1])
 
-    def functest_UpdatesDoReadChecksOnInternalNodes(self):
+    @_skip_wo_ZODB
+    def test_UpdatesDoReadChecksOnInternalNodes(self):
         import transaction
         from ZODB import DB
         from ZODB.MappingStorage import MappingStorage
@@ -2176,7 +2189,8 @@
     def add_key(self, tree, key):
         tree[key] = key
 
-    def functest_internal_keys_after_deletion(self):
+    @_skip_wo_ZODB
+    def test_internal_keys_after_deletion(self):
         # Make sure when a key's deleted, it's not an internal key
         #
         # We'll leverage __getstate__ to introspect the internal structures.

Modified: BTrees/trunk/BTrees/tests/testConflict.py
===================================================================
--- BTrees/trunk/BTrees/tests/testConflict.py	2012-10-18 12:21:52 UTC (rev 128060)
+++ BTrees/trunk/BTrees/tests/testConflict.py	2012-10-18 15:13:47 UTC (rev 128061)
@@ -14,7 +14,17 @@
 import unittest
 
 
+def _skip_wo_ZODB(test_method): #pragma NO COVER
+    try:
+        import ZODB
+    except ImportError: # skip this test if ZODB is not available
+        def _dummy(*args):
+            pass
+        return _dummy
+    else:
+        return test_method
 
+
 class Base:
     """ Tests common to all types: sets, buckets, and BTrees """
 
@@ -67,30 +77,6 @@
 
         return  base, b1, b2, bm, e1, e2, items
 
-    def functestSimpleConflict(self):
-        # Unlike all the other tests, invoke conflict resolution
-        # by committing a transaction and catching a conflict
-        # in the storage.
-        import transaction
-        self.openDB()
-
-        r1 = self.db.open().root()
-        r1["t"] = t = self._makeOne()
-        transaction.commit()
-
-        r2 = self.db.open().root()
-        copy = r2["t"]
-        list(copy)    # unghostify
-
-        self.assertEqual(t._p_serial, copy._p_serial)
-
-        t.update({1:2, 2:3})
-        transaction.commit()
-
-        copy.update({3:4})
-        transaction.commit()
-
-
     def testMergeDelete(self):
         base, b1, b2, bm, e1, e2, items = self._setupConflict()
         del b1[items[1][0]]
@@ -512,19 +498,44 @@
         return LFSet
 
 
-class NastyConfict(Base, unittest.TestCase):
+class NastyConfictFunctionalTests(Base, unittest.TestCase):
+    # Provoke various conflict scenarios using ZODB + transaction
 
     def _getTargetClass(self):
         from BTrees.OOBTree import OOBTree
         return OOBTree
 
+    @_skip_wo_ZODB
+    def testSimpleConflict(self):
+        # Invoke conflict resolution by committing a transaction and
+        # catching a conflict in the storage.
+        import transaction
+        self.openDB()
+
+        r1 = self.db.open().root()
+        r1["t"] = t = self._makeOne()
+        transaction.commit()
+
+        r2 = self.db.open().root()
+        copy = r2["t"]
+        list(copy)    # unghostify
+
+        self.assertEqual(t._p_serial, copy._p_serial)
+
+        t.update({1:2, 2:3})
+        transaction.commit()
+
+        copy.update({3:4})
+        transaction.commit()
+
     # This tests a problem that cropped up while trying to write
     # testBucketSplitConflict (below):  conflict resolution wasn't
     # working at all in non-trivial cases.  Symptoms varied from
     # strange complaints about pickling (despite that the test isn't
     # doing any *directly*), thru SystemErrors from Python and
     # AssertionErrors inside the BTree code.
-    def functestResolutionBlowsUp(self):
+    @_skip_wo_ZODB
+    def testResolutionBlowsUp(self):
         import transaction
         b = self._makeOne()
         for i in range(0, 200, 4):
@@ -562,7 +573,8 @@
         transaction.commit()  # if this doesn't blow up
         list(copy.values())         # and this doesn't either, then fine
 
-    def functestBucketSplitConflict(self):
+    @_skip_wo_ZODB
+    def testBucketSplitConflict(self):
         # Tests that a bucket split is viewed as a conflict.
         # It's (almost necessarily) a white-box test, and sensitive to
         # implementation details.
@@ -642,7 +654,8 @@
 
         self.assertRaises(BTreesConflictError, tm2.commit)
 
-    def functestEmptyBucketConflict(self):
+    @_skip_wo_ZODB
+    def testEmptyBucketConflict(self):
         # Tests that an emptied bucket *created by* conflict resolution is
         # viewed as a conflict:  conflict resolution doesn't have enough
         # info to unlink the empty bucket from the BTree correctly.
@@ -717,8 +730,8 @@
         # expect, and segfaults result).
         self.assertRaises(BTreesConflictError, tm2.commit)
 
-
-    def functestEmptyBucketNoConflict(self):
+    @_skip_wo_ZODB
+    def testEmptyBucketNoConflict(self):
         # Tests that a plain empty bucket (on input) is not viewed as a
         # conflict.
         import transaction
@@ -809,7 +822,8 @@
         self.assertRaises(BTreesConflictError, bucket._p_resolveConflict,
                           None, None, None)
 
-    def functestCantResolveBTreeConflict(self):
+    @_skip_wo_ZODB
+    def testCantResolveBTreeConflict(self):
         # Test that a conflict involving two different changes to
         # an internal BTree node is unresolvable.  An internal node
         # only changes when there are enough additions or deletions
@@ -865,7 +879,8 @@
         else:
             self.fail("expected BTreesConflictError")
 
-    def functestConflictWithOneEmptyBucket(self):
+    @_skip_wo_ZODB
+    def testConflictWithOneEmptyBucket(self):
         # If one transaction empties a bucket, while another adds an item
         # to the bucket, all the changes "look resolvable":  bucket conflict
         # resolution returns a bucket containing (only) the item added by
@@ -953,7 +968,8 @@
         else:
             self.fail("expected BTreesConflictError")
 
-    def functestConflictOfInsertAndDeleteOfFirstBucketItem(self):
+    @_skip_wo_ZODB
+    def testConflictOfInsertAndDeleteOfFirstBucketItem(self):
         """
         Recently, BTrees became careful about removing internal keys
         (keys in internal aka BTree nodes) when they were deleted from
@@ -1019,8 +1035,9 @@
         tm1.abort()
 
 
+
 def test_suite():
-    return unittest.TestSuite((
+    suite = unittest.TestSuite((
         unittest.makeSuite(OOBTreeTests),
         unittest.makeSuite(OOBucketTests),
         unittest.makeSuite(OOTreeSetTests),
@@ -1066,5 +1083,7 @@
         unittest.makeSuite(LFTreeSetTests),
         unittest.makeSuite(LFSetTests),
 
-        unittest.makeSuite(NastyConfict),
+        unittest.makeSuite(NastyConfictFunctionalTests),
     ))
+
+    return suite



More information about the checkins mailing list