[Checkins] SVN: BTrees/branches/pure_python/ Coverage for _Tree._check.
Tres Seaver
cvs-admin at zope.org
Mon Nov 19 21:27:32 UTC 2012
Log message for revision 128358:
Coverage for _Tree._check.
Changed:
_U BTrees/branches/pure_python/
U BTrees/branches/pure_python/BTrees/_base.py
U BTrees/branches/pure_python/BTrees/tests/test__base.py
-=-
Modified: BTrees/branches/pure_python/BTrees/_base.py
===================================================================
--- BTrees/branches/pure_python/BTrees/_base.py 2012-11-19 21:27:29 UTC (rev 128357)
+++ BTrees/branches/pure_python/BTrees/_base.py 2012-11-19 21:27:31 UTC (rev 128358)
@@ -973,7 +973,7 @@
for i in data:
assert_(i.child is not None, "BTree has NULL child")
assert_(i.child.__class__ is child_class,
- "BTree children have different types");
+ "BTree children have different types")
assert_(i.child.size, "Bucket length < 1")
if child_class is self.__class__:
Modified: BTrees/branches/pure_python/BTrees/tests/test__base.py
===================================================================
--- BTrees/branches/pure_python/BTrees/tests/test__base.py 2012-11-19 21:27:29 UTC (rev 128357)
+++ BTrees/branches/pure_python/BTrees/tests/test__base.py 2012-11-19 21:27:31 UTC (rev 128358)
@@ -1960,7 +1960,82 @@
self.assertEqual(tree._data[1].child, b2)
self.assertTrue(tree._firstbucket is b1)
+ def test__check_empty_wo_firstbucket(self):
+ tree = self._makeOne()
+ tree._check() # no raise
+ def test__check_empty_w_firstbucket(self):
+ tree = self._makeOne()
+ tree._firstbucket = object()
+ e = self.assertRaises(AssertionError, tree._check)
+ self.assertEqual(str(e), "Empty BTree has non-NULL firstbucket")
+
+ def test__check_nonempty_wo_firstbucket(self):
+ tree = self._makeOne({'a': 'b'})
+ tree._firstbucket = None
+ e = self.assertRaises(AssertionError, tree._check)
+ self.assertEqual(str(e), "Non-empty BTree has NULL firstbucket")
+
+ def test__check_nonempty_w_null_child(self):
+ tree = self._makeOne({'a': 'b'})
+ tree._data.append(tree._data[0].__class__('c', None))
+ e = self.assertRaises(AssertionError, tree._check)
+ self.assertEqual(str(e), "BTree has NULL child")
+
+ def test__check_nonempty_w_heterogenous_child(self):
+ class Other(object):
+ pass
+ tree = self._makeOne({'a': 'b'})
+ tree._data.append(tree._data[0].__class__('c', Other()))
+ e = self.assertRaises(AssertionError, tree._check)
+ self.assertEqual(str(e), "BTree children have different types")
+
+ def test__check_nonempty_w_empty_child(self):
+ tree = self._makeOne({'a': 'b'})
+ first = tree._data[0]
+ tree._data.append(first.__class__('c', first.child.__class__()))
+ e = self.assertRaises(AssertionError, tree._check)
+ self.assertEqual(str(e), "Bucket length < 1")
+
+ def test__check_branch_w_mismatched_firstbucket(self):
+ tree = self._makeOne()
+ c_tree = tree.__class__({'a': 'b'})
+ c_first = c_tree._data[0]
+ tree._data.append(c_first.__class__('a', c_tree))
+ tree._firstbucket = object()
+ e = self.assertRaises(AssertionError, tree._check)
+ self.assertEqual(str(e), "BTree has firstbucket different than "
+ "its first child's firstbucket")
+
+ def test__check_nonempty_w_invalid_child(self):
+ class Invalid(object):
+ size = 2
+ tree = self._makeOne({'a': 'b'})
+ tree._data[0].child = Invalid()
+ e = self.assertRaises(AssertionError, tree._check)
+ self.assertEqual(str(e), "Incorrect child type")
+
+ def test__check_branch_traverse_bucket_pointers(self):
+ tree = self._makeOne()
+ t_first = tree.__class__({'a': 'b'})
+ c_first = t_first._data[0]
+ b_first = c_first.child
+ t_second = tree.__class__({'c': 'd'})
+ b_first._next = t_second._firstbucket
+ tree._data.append(c_first.__class__('a', t_first))
+ tree._data.append(c_first.__class__('c', t_second))
+ tree._firstbucket = t_first._firstbucket
+ tree._check() #no raise
+
+ def test__check_nonempty_leaf_traverse_bucket_pointers(self):
+ tree = self._makeOne({'a': 'b'})
+ first = tree._data[0]
+ first.child._next = b2 = first.child.__class__({'c': 'd'})
+ tree._data.append(first.__class__('c', b2))
+ tree._check() #no raise
+
+
+
class _Jar(object):
def __init__(self):
self._current = set()
More information about the checkins
mailing list