MCPcopy Index your code
hub / github.com/python/cpython / test_odd_flush

Method test_odd_flush

Lib/test/test_zlib.py:629–648  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

627 @unittest.skipUnless(hasattr(zlib, 'Z_SYNC_FLUSH'),
628 'requires zlib.Z_SYNC_FLUSH')
629 def test_odd_flush(self):
630 # Test for odd flushing bugs noted in 2.0, and hopefully fixed in 2.1
631 import random
632 # Testing on 17K of "random" data
633
634 # Create compressor and decompressor objects
635 co = zlib.compressobj(zlib.Z_BEST_COMPRESSION)
636 dco = zlib.decompressobj()
637
638 # Try 17K of data
639 # generate random data stream
640 data = random.randbytes(17 * 1024)
641
642 # compress, sync-flush, and decompress
643 first = co.compress(data)
644 second = co.flush(zlib.Z_SYNC_FLUSH)
645 expanded = dco.decompress(first + second)
646
647 # if decompressed data is different from the input data, choke.
648 self.assertEqual(expanded, data, "17K random source doesn't match")
649
650 def test_empty_flush(self):
651 # Test that calling .flush() on unused objects works.

Callers

nothing calls this directly

Calls 5

decompressMethod · 0.80
randbytesMethod · 0.45
compressMethod · 0.45
flushMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected