353
353
# And the decompressor is finalized
354
354
self.assertIs(None, block._z_content_decompressor)
356
def test_partial_decomp_no_known_length(self):
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
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
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)
357
398
class TestCaseWithGroupCompressVersionedFiles(tests.TestCaseWithTransport):