167
167
self.assertEqual((['common\ndifferent\nmoredifferent\n'],
168
168
sha_2), compressor.extract(('newlabel',)))
171
class TestGroupCompressBlock(tests.TestCase):
173
def test_from_empty_bytes(self):
174
self.assertRaises(errors.InvalidGroupCompressBlock,
175
groupcompress.GroupCompressBlock.from_bytes, '')
177
def test_from_bytes(self):
178
block = groupcompress.GroupCompressBlock.from_bytes('gcb1p\n')
179
self.assertIsInstance(block, groupcompress.GroupCompressBlock)
181
def test_add_entry(self):
182
gcb = groupcompress.GroupCompressBlock()
183
e = gcb.add_entry(('foo', 'bar'), 'fulltext', 'abcd'*10, 0, 100)
184
self.assertIsInstance(e, groupcompress.GroupCompressBlockEntry)
185
self.assertEqual(('foo', 'bar'), e.key)
186
self.assertEqual('fulltext', e.type)
187
self.assertEqual('abcd'*10, e.sha1)
188
self.assertEqual(0, e.start)
189
self.assertEqual(100, e.length)
191
def test_to_bytes(self):
192
gcb = groupcompress.GroupCompressBlock()
193
gcb.add_entry(('foo', 'bar'), 'fulltext', 'abcd'*10, 0, 100)
194
gcb.add_entry(('bing',), 'fulltext', 'abcd'*10, 100, 100)
195
self.assertEqualDiff('gcb1p\n' # group compress block v1 plain
196
'183\n' # Length of all meta-info
199
'sha1:abcdabcdabcdabcdabcdabcdabcdabcdabcdabcd\n'
205
'sha1:abcdabcdabcdabcdabcdabcdabcdabcdabcdabcd\n'
208
'\n', gcb.to_bytes())