[Zope-CVS] CVS: Products/BTreeFolder2/tests - testBTreeFolder2.py:1.6

Shane Hathaway shane at zope.com
Wed Aug 27 11:06:56 EDT 2003


Update of /cvs-repository/Products/BTreeFolder2/tests
In directory cvs.zope.org:/tmp/cvs-serv23448/tests

Modified Files:
	testBTreeFolder2.py 
Log Message:
Added a manage_cleanup to BTreeFolder2.

Certain ZODB bugs have caused BTrees to become slightly insane.
manage_cleanup detects damage and fixes it.



=== Products/BTreeFolder2/tests/testBTreeFolder2.py 1.5 => 1.6 ===
--- Products/BTreeFolder2/tests/testBTreeFolder2.py:1.5	Thu Aug 22 09:50:18 2002
+++ Products/BTreeFolder2/tests/testBTreeFolder2.py	Wed Aug 27 10:06:55 2003
@@ -17,6 +17,7 @@
 """
 
 import unittest
+import ZODB
 import Testing
 import Zope
 from Products.BTreeFolder2.BTreeFolder2 \
@@ -178,6 +179,38 @@
         self.assertEqual(info['next_batch_url'], '')
         self.assert_(info['formatted_list'].find('item') < 0)
         self.assert_(info['formatted_list'].find('somefolder') > 0)
+
+    def testCleanup(self):
+        self.assert_(self.f._cleanup())
+        key = TrojanKey('a')
+        self.f._tree[key] = 'b'
+        self.assert_(self.f._cleanup())
+        key.value = 'z'
+
+        # With a key in the wrong place, there should now be damage.
+        self.assert_(not self.f._cleanup())
+        # Now it's fixed.
+        self.assert_(self.f._cleanup())
+        # Verify the management interface also works,
+        # but don't test return values.
+        self.f.manage_cleanup()
+        key.value = 'a'
+        self.f.manage_cleanup()
+
+
+class TrojanKey:
+    """Pretends to be a consistent, immutable, humble citizen...
+
+    then sweeps the rug out from under the BTree.
+    """
+    def __init__(self, value):
+        self.value = value
+
+    def __cmp__(self, other):
+        return cmp(self.value, other)
+
+    def __hash__(self):
+        return hash(self.value)
 
 
 def test_suite():




More information about the Zope-CVS mailing list