python / python/cpython

Add reproducibility test for `gzip.compress()`

Open
#131,697 3 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

tests type-feature
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

The issue https://github.com/python/cpython/issues/112346 was reported, which was a failure to keep reproducibility in gzip module output from Python 3.10 to 3.11.

There was a fix discussed and rejected in https://github.com/python/cpython/issues/112346

I think it makes sense not to actually change things back, but failing to merge the PR means we also failed to add unit tests.

Can we please add a general-purpose, fragile reproducibility test for the gzip module, so that this problem does not recur?

Ex. test that the output of gzip.compress("Hello world") remains stable

def test_gzip_reproducibility():
    """If this test fails, gzip.compress does not give reproducible output. Either fix that, or document the change in What's New and change the constant 'expected' below."""
    expected = b'\x1f\x8b\x08\x00\xa2\xd2\xe1g\x02\xff\xf3H\xcd\xc9\xc9W(\xcf/\xcaI\x01\x00R\x9e\xd6\x8b\x0b\x00\x00\x00'
    assert gzip.compress(b"Hello world") == expected

    expected = 
b'\x1f\x8b\x08\x00\x00\x00\x00\x00\x02\xff\xf3H\xcd\xc9\xc9W(\xcf/\xcaI\x01\x00R\x9e\xd6\x8b\x0b\x00\x00\x00'
    assert gzip.compress(b"Hello world", mtime=0) == expected    
Linked PRs
  • gh-151214

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Review linked PR gh-151214 and locate the existing gzip module tests before starting. Add the reproducibility checks for gzip.compress() shown in the issue, then confirm the expected outputs remain stable and account for any intentional change in What's New.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
testing-qa
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.