~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to tests/test_groupcompress.py

  • Committer: John Arbash Meinel
  • Date: 2009-03-04 18:31:31 UTC
  • mto: (0.17.34 trunk)
  • mto: This revision was merged to the branch mainline in revision 4280.
  • Revision ID: john@arbash-meinel.com-20090304183131-p433dz5coqrmv8pw
Now using a zlib compressed format.
We encode the length of the compressed and uncompressed content,
and then compress the actual content.
Need to do some testing with real data to see if this is efficient
or if another structure would be better.

Show diffs side-by-side

added added

removed removed

Lines of Context:
209
209
                          groupcompress.GroupCompressBlock.from_bytes, '')
210
210
 
211
211
    def test_from_minimal_bytes(self):
212
 
        block = groupcompress.GroupCompressBlock.from_bytes('gcb1p\n0\n')
 
212
        block = groupcompress.GroupCompressBlock.from_bytes('gcb1z\n0\n0\n')
213
213
        self.assertIsInstance(block, groupcompress.GroupCompressBlock)
214
214
        self.assertEqual({}, block._entries)
215
215
 
216
216
    def test_from_bytes(self):
217
217
        block = groupcompress.GroupCompressBlock.from_bytes(
218
 
            'gcb1p\n' # group compress block v1 plain
 
218
            'gcb1z\n' # group compress block v1 plain
 
219
            '76\n' # Length of zlib bytes
219
220
            '183\n' # Length of all meta-info
 
221
            + zlib.compress(
220
222
            'key:bing\n'
221
223
            'sha1:abcdabcdabcdabcdabcdabcdabcdabcdabcdabcd\n'
222
224
            'type:fulltext\n'
228
230
            'type:fulltext\n'
229
231
            'start:0\n'
230
232
            'length:100\n'
231
 
            '\n')
 
233
            '\n'))
232
234
        self.assertEqual([('bing',), ('foo', 'bar')], sorted(block._entries))
233
235
        bing = block._entries[('bing',)]
234
236
        self.assertEqual(('bing',), bing.key)
257
259
        gcb = groupcompress.GroupCompressBlock()
258
260
        gcb.add_entry(('foo', 'bar'), 'fulltext', 'abcd'*10, 0, 100)
259
261
        gcb.add_entry(('bing',), 'fulltext', 'abcd'*10, 100, 100)
260
 
        self.assertEqualDiff('gcb1p\n' # group compress block v1 plain
261
 
                             '183\n' # Length of all meta-info
262
 
                             'key:bing\n'
 
262
        bytes = gcb.to_bytes()
 
263
        self.assertStartsWith(bytes,
 
264
                              'gcb1z\n' # group compress block v1 zlib
 
265
                              '76\n' # Length of compressed bytes
 
266
                              '183\n' # Length of all meta-info
 
267
                             )
 
268
        remaining_bytes = bytes[13:]
 
269
        raw_bytes = zlib.decompress(remaining_bytes)
 
270
        self.assertEqualDiff('key:bing\n'
263
271
                             'sha1:abcdabcdabcdabcdabcdabcdabcdabcdabcdabcd\n'
264
272
                             'type:fulltext\n'
265
273
                             'start:100\n'
270
278
                             'type:fulltext\n'
271
279
                             'start:0\n'
272
280
                             'length:100\n'
273
 
                             '\n', gcb.to_bytes())
 
281
                             '\n', raw_bytes)