Repository navigation
Commit f65beb0
committed
gh-107862: Add Hypothesis tests for the compression modules
The incremental decompressors in bz2, lzma, zlib and compression.zstd,
the older zlib.decompressobj protocol, and the DecompressReader file
layer are CPython code sharing one contract, but the existing tests only
exercise them with fixed chunk sizes. This adds property tests that feed
random data through them in random pieces with random max_length values,
with the module-level one-shot functions as the oracle, plus a stateful
test per backend for the decompressor protocol and for the read-mode file
objects. The strategies avoid filters so the tests can also be used as
fuzz targets.
Writing these turned up three bugs, each pinned by an expectedFailure
test with the minimal reproducer as an example:
- bz2.BZ2Decompressor and zlib._ZlibDecompressor report needs_input=True
when max_length cut the output and more is still buffered.
- lzma.LZMADecompressor raises LZMAError("Insufficient buffer space") on
the second of two consecutive max_length=0 calls with no new input;
the other backends return b''. The broad lzma tests leave out
max_length=0 so that they keep checking everything else.
- zlib._ZlibDecompressor(zdict=...) raises SystemError on a zlib-wrapped
stream, because the Z_NEED_DICT path returns NULL without setting an
exception.1 parent c3b2240 commit f65beb0
1 file changed
Lines changed: 994 additions & 0 deletions
0 commit comments