292
def test_partial_decomp(self):
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
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
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)
292
337
class TestCaseWithGroupCompressVersionedFiles(tests.TestCaseWithTransport):