(self)
| 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. |
nothing calls this directly
no test coverage detected