~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_groupcompress.py

  • Committer: John Arbash Meinel
  • Date: 2009-03-14 18:26:31 UTC
  • mto: (3735.2.156 brisbane-core)
  • mto: This revision was merged to the branch mainline in revision 4280.
  • Revision ID: john@arbash-meinel.com-20090314182631-54snfqil79ckzz42
ImplementĀ partialĀ decompressionĀ support.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
from bzrlib import (
22
22
    groupcompress,
 
23
    osutils,
23
24
    tests,
24
25
    )
25
26
from bzrlib.osutils import sha_string
288
289
                             'length:100\n'
289
290
                             '\n', raw_bytes)
290
291
 
 
292
    def test_partial_decomp(self):
 
293
        content_chunks = []
 
294
        # We need a sufficient amount of data so that zlib.decompress has
 
295
        # partial decompression to work with. Most auto-generated data
 
296
        # compresses a bit too well, we want a combination, so we combine a sha
 
297
        # hash with compressible data.
 
298
        for i in xrange(2048):
 
299
            next_content = '%d\nThis is a bit of duplicate text\n' % (i,)
 
300
            content_chunks.append(next_content)
 
301
            next_sha1 = osutils.sha_string(next_content)
 
302
            content_chunks.append(next_sha1 + '\n')
 
303
        content = ''.join(content_chunks)
 
304
        self.assertEqual(158634, len(content))
 
305
        z_content = zlib.compress(content)
 
306
        self.assertEqual(57182, len(z_content))
 
307
        block = groupcompress.GroupCompressBlock()
 
308
        block._z_content = z_content
 
309
        block._z_content_length = len(z_content)
 
310
        block._content_length = 158634
 
311
        self.assertIs(None, block._content)
 
312
        block._ensure_content(100)
 
313
        self.assertIsNot(None, block._content)
 
314
        # We have decompressed at least 100 bytes
 
315
        self.assertTrue(len(block._content) >= 100)
 
316
        # We have not decompressed the whole content
 
317
        self.assertTrue(len(block._content) < 158634)
 
318
        self.assertEqualDiff(content[:len(block._content)], block._content)
 
319
        # ensuring content that we already have shouldn't cause any more data
 
320
        # to be extracted
 
321
        cur_len = len(block._content)
 
322
        block._ensure_content(cur_len - 10)
 
323
        self.assertEqual(cur_len, len(block._content))
 
324
        # Now we want a bit more content
 
325
        cur_len += 10
 
326
        block._ensure_content(cur_len)
 
327
        self.assertTrue(len(block._content) >= cur_len)
 
328
        self.assertTrue(len(block._content) < 158634)
 
329
        self.assertEqualDiff(content[:len(block._content)], block._content)
 
330
        # And now lets finish
 
331
        block._ensure_content(158634)
 
332
        self.assertEqualDiff(content, block._content)
 
333
        # And the decompressor is finalized 
 
334
        self.assertIs(None, block._z_content_decompressor)
 
335
 
291
336
 
292
337
class TestCaseWithGroupCompressVersionedFiles(tests.TestCaseWithTransport):
293
338