~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-16 19:21:06 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-20090316192106-iz7ccmx58s0ff3aa
Add tests for the ability to do partial decompression without knowing the final length.

Show diffs side-by-side

added added

removed removed

Lines of Context:
353
353
        # And the decompressor is finalized
354
354
        self.assertIs(None, block._z_content_decompressor)
355
355
 
 
356
    def test_partial_decomp_no_known_length(self):
 
357
        content_chunks = []
 
358
        for i in xrange(2048):
 
359
            next_content = '%d\nThis is a bit of duplicate text\n' % (i,)
 
360
            content_chunks.append(next_content)
 
361
            next_sha1 = osutils.sha_string(next_content)
 
362
            content_chunks.append(next_sha1 + '\n')
 
363
        content = ''.join(content_chunks)
 
364
        self.assertEqual(158634, len(content))
 
365
        z_content = zlib.compress(content)
 
366
        self.assertEqual(57182, len(z_content))
 
367
        block = groupcompress.GroupCompressBlock()
 
368
        block._z_content = z_content
 
369
        block._z_content_length = len(z_content)
 
370
        block._compressor_name = 'zlib'
 
371
        block._content_length = None # Don't tell the decompressed length
 
372
        self.assertIs(None, block._content)
 
373
        block._ensure_content(100)
 
374
        self.assertIsNot(None, block._content)
 
375
        # We have decompressed at least 100 bytes
 
376
        self.assertTrue(len(block._content) >= 100)
 
377
        # We have not decompressed the whole content
 
378
        self.assertTrue(len(block._content) < 158634)
 
379
        self.assertEqualDiff(content[:len(block._content)], block._content)
 
380
        # ensuring content that we already have shouldn't cause any more data
 
381
        # to be extracted
 
382
        cur_len = len(block._content)
 
383
        block._ensure_content(cur_len - 10)
 
384
        self.assertEqual(cur_len, len(block._content))
 
385
        # Now we want a bit more content
 
386
        cur_len += 10
 
387
        block._ensure_content(cur_len)
 
388
        self.assertTrue(len(block._content) >= cur_len)
 
389
        self.assertTrue(len(block._content) < 158634)
 
390
        self.assertEqualDiff(content[:len(block._content)], block._content)
 
391
        # And now lets finish
 
392
        block._ensure_content()
 
393
        self.assertEqualDiff(content, block._content)
 
394
        # And the decompressor is finalized
 
395
        self.assertIs(None, block._z_content_decompressor)
 
396
 
356
397
 
357
398
class TestCaseWithGroupCompressVersionedFiles(tests.TestCaseWithTransport):
358
399