Rev 4796: Add tests that we handle the 'empty' edge cases. in http://bazaar.launchpad.net/~jameinel/bzr/chk-index
John Arbash Meinel
john at arbash-meinel.com
Wed Oct 28 18:15:10 GMT 2009
At http://bazaar.launchpad.net/~jameinel/bzr/chk-index
------------------------------------------------------------
revno: 4796
revision-id: john at arbash-meinel.com-20091028181501-1p9w2fa9y8owsrjl
parent: john at arbash-meinel.com-20091028180725-z4890ne9xvf7vyys
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: chk-index
timestamp: Wed 2009-10-28 13:15:01 -0500
message:
Add tests that we handle the 'empty' edge cases.
-------------- next part --------------
=== modified file 'bzrlib/tests/test_chk_index.py'
--- a/bzrlib/tests/test_chk_index.py 2009-10-28 18:07:25 +0000
+++ b/bzrlib/tests/test_chk_index.py 2009-10-28 18:15:01 +0000
@@ -145,7 +145,17 @@
'01200000' '00200000',
]), '\n'.join([binascii.b2a_hex(b) for b in bytes]))
- # TODO: Test the _empty case
+ def test__build_group_bytes_empty(self):
+ builder = chk_index.CHKIndexBuilder()
+ h = builder._build_header()
+ self.assertEqual(1, h.group_index_start_bytes)
+ self.assertEqual(1, h.group_index_length_bytes)
+ self.assertEqual('>BB', h.group_coder.format)
+ bytes = builder._build_group_index(h)
+ self.assertEqualDiff('\n'.join([
+ '00' '00',
+ ]), '\n'.join([binascii.b2a_hex(b) for b in bytes]))
+
def test__build_group_bytes_tiny(self):
builder = chk_index.CHKIndexBuilder()
builder._ensure_group((0, 2345))
@@ -157,10 +167,10 @@
self.assertEqual('>HH', h.group_coder.format)
bytes = builder._build_group_index(h)
self.assertEqualDiff('\n'.join([
- '00000000',
- '00000929',
- '09291388',
- '1cb10080',
+ '0000' '0000',
+ '0000' '0929',
+ '0929' '1388',
+ '1cb1' '0080',
]), '\n'.join([binascii.b2a_hex(b) for b in bytes]))
def test__build_group_bytes_enormous(self):
@@ -198,6 +208,16 @@
b2a_hex(builder._entry_to_bytes(bit_k2, h.entry_coder)))
# TODO: Test the _empty case
+ def test__build_mini_index_and_entries_empty(self):
+ builder = chk_index.CHKIndexBuilder()
+ h = builder._build_header()
+ builder._sort_groups()
+ self.assertEqual(0, h.num_mini_index_entries)
+ mini_index_bytes, entry_bytes = builder._build_mini_index_and_entries(
+ h)
+ self.assertEqual([], mini_index_bytes)
+ self.assertEqual([], entry_bytes)
+
def test__build_mini_index_and_entries_tiny(self):
builder = chk_index.CHKIndexBuilder()
builder.add_node(k1, 0, 1000, 0, 1)
@@ -296,7 +316,24 @@
self.assertEqual(0x00b6, h.entry_offset + len(entry_bytes[0])
+ len(entry_bytes[1]))
- # TODO: Test the _empty case
+ def test_build_empty_index(self):
+ builder = chk_index.CHKIndexBuilder()
+ entry_offset, bytes = builder.finish()
+ bytes = ''.join(bytes)
+ header = """Groupcompress CHK Index 1
+hash=sha1 20
+mini_index=120 0 1
+groups=120 1 1 1
+entry=0 20 1 1 1
+"""
+ self.assertEqualDiff(header, bytes[:len(header)])
+ self.assertEqual('\n'*(120-len(header)), bytes[len(header):120])
+ self.assertEqual(120+1*(1+1), entry_offset)
+ self.assertEqualDiff(
+ # Only 1 group record, the null record
+ '00' '00',
+ binascii.b2a_hex(bytes[120:]))
+
def test_build_tiny_index(self):
builder = chk_index.CHKIndexBuilder()
builder.add_node(k1, 0, 1000, 0, 1)
@@ -635,7 +672,26 @@
self.assertEqual(header.group_index_offset + 10*(4+4),
header.entry_offset)
- # TODO: Test the _empty case
+ def test_build_header_for_empty(self):
+ # There is always the (0,0) group
+ header = chk_index.CHKIndexHeader.build_header_for(
+ num_groups=1, max_group_offset=0, max_group_length=0,
+ num_entries=0, max_inner_start=0, max_inner_length=0)
+ self.assertEqual(header._RESERVED_HEADER_BYTES,
+ header.mini_index_offset)
+ self.assertEqual(0, header.num_mini_index_entries)
+ self.assertEqual(1, header.mini_index_entry_offset_bytes)
+ self.assertEqual(1, header.num_groups)
+ self.assertEqual(header._RESERVED_HEADER_BYTES,
+ header.group_index_offset)
+ self.assertEqual(1, header.group_index_start_bytes)
+ self.assertEqual(1, header.group_index_length_bytes)
+ self.assertEqual(0, header.num_entries)
+ self.assertEqual(20, header.entry_hash_bytes)
+ self.assertEqual(1, header.entry_group_offset_bytes)
+ self.assertEqual(header.group_index_offset + (1*(1+1)),
+ header.entry_offset)
+
def test_build_header_for_tiny(self):
header = chk_index.CHKIndexHeader.build_header_for(
num_groups=3, max_group_offset=40000,
@@ -644,8 +700,8 @@
self.assertEqual(header._RESERVED_HEADER_BYTES,
header.mini_index_offset)
self.assertEqual(0, header.num_mini_index_entries)
+ self.assertEqual(1, header.mini_index_entry_offset_bytes)
self.assertEqual(3, header.num_groups)
- self.assertEqual(1, header.mini_index_entry_offset_bytes)
self.assertEqual(header._RESERVED_HEADER_BYTES,
header.group_index_offset)
self.assertEqual(2, header.group_index_start_bytes)
@@ -690,7 +746,16 @@
size = trans.put_bytes('index', ''.join(bytes))
return chk_index.CHKIndex(trans, 'index', entry_offset, size)
- # TODO: Test the _empty case
+ def test__ensure_header_empty(self):
+ index = self.make_index([])
+ index._ensure_header()
+ self.assertIsNot(None, index._header)
+ self.assertEqual(0, index._header.num_entries)
+ self.assertEqual(1, index._header.num_groups)
+ self.assertIsNot(None, index._groups)
+ self.assertEqual([(0, 0)], index._groups)
+ self.assertEqual([(122, False)], index._mini_index)
+
def test__ensure_header_tiny(self):
index = self.make_index([(k1, 0, 1000, 0, 10),
(k2, 0, 1000, 10, 9),
More information about the bazaar-commits
mailing list