Skip to content

Add reproducibility test for gzip.compress()Β #131697

@za3k

Description

@za3k

The issue #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 #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    

Metadata

Metadata

Assignees

No one assigned

    Labels

    testsTests in the Lib/test dirtype-featureA feature request or enhancement

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions