Rev 5388: A __sizeof__ check that ensure we are getting what we are looking for. in http://bazaar.launchpad.net/~jameinel/bzr/2.3-btree-chk-leaf
John Arbash Meinel
john at arbash-meinel.com
Fri Aug 6 16:38:42 BST 2010
At http://bazaar.launchpad.net/~jameinel/bzr/2.3-btree-chk-leaf
------------------------------------------------------------
revno: 5388
revision-id: john at arbash-meinel.com-20100806153824-inx9xjyuzneci1qw
parent: john at arbash-meinel.com-20100805220549-1292et5s2bntvra0
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 2.3-btree-chk-leaf
timestamp: Fri 2010-08-06 10:38:24 -0500
message:
A __sizeof__ check that ensure we are getting what we are looking for.
It also checks that it grows appropriately for how many new entries are added.
-------------- next part --------------
=== modified file 'bzrlib/btree_index.py'
--- a/bzrlib/btree_index.py 2010-08-04 16:33:26 +0000
+++ b/bzrlib/btree_index.py 2010-08-06 15:38:24 +0000
@@ -605,7 +605,7 @@
class _LeafNode(dict):
"""A leaf node for a serialised B+Tree index."""
- __slots__ = ('min_key', 'max_key')
+ __slots__ = ('min_key', 'max_key', '_keys')
def __init__(self, bytes, key_length, ref_list_length):
"""Parse bytes to create a leaf node object."""
@@ -618,6 +618,7 @@
else:
self.min_key = self.max_key = None
super(_LeafNode, self).__init__(key_list)
+ self._keys = dict(self)
def all_items(self):
"""Return a sorted list of (key, (value, refs)) items"""
=== modified file 'bzrlib/tests/test__btree_serializer.py'
--- a/bzrlib/tests/test__btree_serializer.py 2010-08-04 16:08:12 +0000
+++ b/bzrlib/tests/test__btree_serializer.py 2010-08-06 15:38:24 +0000
@@ -291,3 +291,15 @@
self.assertEqual(lst.index(val), offsets[val])
for idx, key in enumerate(leaf.all_keys()):
self.assertEqual(str(idx), leaf[key][0].split()[0])
+
+ def test__sizeof__(self):
+ # We can't use the exact numbers because of platform variations, etc.
+ # But what we really care about is that it does get bigger with more
+ # content.
+ leaf0 = self.module._parse_into_chk('type=leaf\n', 1, 0)
+ leaf1 = self.module._parse_into_chk(_one_key_content, 1, 0)
+ leafN = self.module._parse_into_chk(_multi_key_content, 1, 0)
+ sizeof_1 = leaf1.__sizeof__() - leaf0.__sizeof__()
+ self.assertTrue(sizeof_1 > 0)
+ sizeof_N = leafN.__sizeof__() - leaf0.__sizeof__()
+ self.assertEqual(sizeof_1 * len(leafN), sizeof_N)
More information about the bazaar-commits
mailing list