(self)
| 520 | @unittest.skipUnless(hasattr(zlib, 'Z_SYNC_FLUSH'), |
| 521 | 'requires zlib.Z_SYNC_FLUSH') |
| 522 | def test_odd_flush(self): |
| 523 | # Test for odd flushing bugs noted in 2.0, and hopefully fixed in 2.1 |
| 524 | import random |
| 525 | # Testing on 17K of "random" data |
| 526 | |
| 527 | # Create compressor and decompressor objects |
| 528 | co = zlib.compressobj(zlib.Z_BEST_COMPRESSION) |
| 529 | dco = zlib.decompressobj() |
| 530 | |
| 531 | # Try 17K of data |
| 532 | # generate random data stream |
| 533 | data = random.randbytes(17 * 1024) |
| 534 | |
| 535 | # compress, sync-flush, and decompress |
| 536 | first = co.compress(data) |
| 537 | second = co.flush(zlib.Z_SYNC_FLUSH) |
| 538 | expanded = dco.decompress(first + second) |
| 539 | |
| 540 | # if decompressed data is different from the input data, choke. |
| 541 | self.assertEqual(expanded, data, "17K random source doesn't match") |
| 542 | |
| 543 | def test_empty_flush(self): |
| 544 | # Test that calling .flush() on unused objects works. |
nothing calls this directly
no test coverage detected