pycompression / python-zlib-ng

A drop-in replacement for Python's zlib and gzip modules using zlib-ng
Other
7 stars 4 forks source link

Test failures on Python 3.13 due to read-only Gzip(NG)File #44

Closed musicinmybrain closed 2 months ago

musicinmybrain commented 4 months ago

With tox -e py312, all tests pass, but there is a warning:

tests/test_gzip_compliance.py::TestGzip::test_fileobj_mode
  /home/ben/src/forks/python-zlib-ng/.tox/py312/lib64/python3.12/site-packages/zlib_ng/gzip_ng.py:139: FutureWarning: GzipFile was opened for writing, but this will change in future Python releases.  Specify the mode argument for opening it for writing.
    super().__init__(filename, mode, compresslevel, fileobj, mtime)

With tox -e py313 (using Python 3.13.0b1 from updates-testing on Fedora 39), this warning appears to come to fruition:

========================================================================================== short test summary info ==========================================================================================
FAILED tests/test_gzip_compliance.py::TestGzip::test_append - OSError: [Errno 9] write() on read-only GzipNGFile object
FAILED tests/test_gzip_compliance.py::TestGzip::test_buffered_reader - OSError: [Errno 9] write() on read-only GzipNGFile object
FAILED tests/test_gzip_compliance.py::TestGzip::test_bytes_filename - OSError: [Errno 9] write() on read-only GzipNGFile object
FAILED tests/test_gzip_compliance.py::TestGzip::test_compresslevel_metadata - OSError: [Errno 9] write() on read-only GzipNGFile object
FAILED tests/test_gzip_compliance.py::TestGzip::test_decompress - OSError: [Errno 9] write() on read-only GzipNGFile object
FAILED tests/test_gzip_compliance.py::TestGzip::test_exclusive_write - OSError: [Errno 9] write() on read-only GzipNGFile object
FAILED tests/test_gzip_compliance.py::TestGzip::test_fileobj_mode - AssertionError: 'rb' != 1
FAILED tests/test_gzip_compliance.py::TestGzip::test_io_on_closed_object - OSError: [Errno 9] write() on read-only GzipNGFile object
FAILED tests/test_gzip_compliance.py::TestGzip::test_issue44439 - OSError: [Errno 9] write() on read-only GzipNGFile object
FAILED tests/test_gzip_compliance.py::TestGzip::test_many_append - OSError: [Errno 9] write() on read-only GzipNGFile object
FAILED tests/test_gzip_compliance.py::TestGzip::test_metadata - OSError: [Errno 9] write() on read-only GzipNGFile object
FAILED tests/test_gzip_compliance.py::TestGzip::test_metadata_ascii_name - OSError: [Errno 9] write() on read-only GzipNGFile object
FAILED tests/test_gzip_compliance.py::TestGzip::test_mode - OSError: [Errno 9] write() on read-only GzipNGFile object
FAILED tests/test_gzip_compliance.py::TestGzip::test_mtime - OSError: [Errno 9] write() on read-only GzipNGFile object
FAILED tests/test_gzip_compliance.py::TestGzip::test_non_seekable_file - OSError: [Errno 9] write() on read-only GzipNGFile object
FAILED tests/test_gzip_compliance.py::TestGzip::test_paddedfile_getattr - OSError: [Errno 9] write() on read-only GzipNGFile object
FAILED tests/test_gzip_compliance.py::TestGzip::test_peek - OSError: [Errno 9] write() on read-only GzipNGFile object
FAILED tests/test_gzip_compliance.py::TestGzip::test_read - OSError: [Errno 9] write() on read-only GzipNGFile object
FAILED tests/test_gzip_compliance.py::TestGzip::test_read1 - OSError: [Errno 9] write() on read-only GzipNGFile object
FAILED tests/test_gzip_compliance.py::TestGzip::test_readline - OSError: [Errno 9] write() on read-only GzipNGFile object
FAILED tests/test_gzip_compliance.py::TestGzip::test_readlines - OSError: [Errno 9] write() on read-only GzipNGFile object
FAILED tests/test_gzip_compliance.py::TestGzip::test_seek_read - OSError: [Errno 9] write() on read-only GzipNGFile object
FAILED tests/test_gzip_compliance.py::TestGzip::test_seek_whence - OSError: [Errno 9] write() on read-only GzipNGFile object
FAILED tests/test_gzip_compliance.py::TestGzip::test_seek_write - OSError: [Errno 9] write() on read-only GzipNGFile object
FAILED tests/test_gzip_compliance.py::TestGzip::test_textio_readlines - OSError: [Errno 9] write() on read-only GzipNGFile object
FAILED tests/test_gzip_compliance.py::TestGzip::test_with_open - OSError: [Errno 9] write() on read-only GzipNGFile object
FAILED tests/test_gzip_compliance.py::TestGzip::test_write - OSError: [Errno 9] write() on read-only GzipNGFile object
FAILED tests/test_gzip_compliance.py::TestGzip::test_write_array - OSError: [Errno 9] write() on read-only GzipNGFile object
FAILED tests/test_gzip_compliance.py::TestGzip::test_write_bytearray - OSError: [Errno 9] write() on read-only GzipNGFile object
FAILED tests/test_gzip_compliance.py::TestGzip::test_write_incompatible_type - OSError: [Errno 9] write() on read-only GzipNGFile object
FAILED tests/test_gzip_compliance.py::TestGzip::test_write_memoryview - OSError: [Errno 9] write() on read-only GzipNGFile object
FAILED tests/test_gzip_compliance.py::TestGzip::test_write_read_with_pathlike_file - OSError: [Errno 9] write() on read-only GzipNGFile object
FAILED tests/test_gzip_compliance.py::TestGzip::test_zero_padded_file - OSError: [Errno 9] write() on read-only GzipNGFile object
FAILED tests/test_gzip_compliance.py::TestOpen::test_binary_modes - OSError: [Errno 9] write() on read-only GzipNGFile object
FAILED tests/test_gzip_compliance.py::TestOpen::test_encoding - OSError: [Errno 9] write() on read-only GzipNGFile object
FAILED tests/test_gzip_compliance.py::TestOpen::test_encoding_error_handler - OSError: [Errno 9] write() on read-only GzipNGFile object
FAILED tests/test_gzip_compliance.py::TestOpen::test_implicit_binary_modes - OSError: [Errno 9] write() on read-only GzipNGFile object
FAILED tests/test_gzip_compliance.py::TestOpen::test_newline - OSError: [Errno 9] write() on read-only GzipNGFile object
FAILED tests/test_gzip_compliance.py::TestOpen::test_pathlike_file - OSError: [Errno 9] write() on read-only GzipNGFile object
FAILED tests/test_gzip_compliance.py::TestOpen::test_text_modes - OSError: [Errno 9] write() on read-only GzipNGFile object
FAILED tests/test_gzip_compliance.py::TestCommandLine::test_compress_infile_outfile - AssertionError: Process return code is 1
FAILED tests/test_gzip_compliance.py::TestCommandLine::test_compress_infile_outfile_default - AssertionError: Process return code is 1
FAILED tests/test_gzip_compliance.py::TestCommandLine::test_compress_stdin_outfile - AssertionError: b'Traceback (most recent call last):\n  Fil[689 chars]ct\n' != b''
FAILED tests/test_gzip_compliance.py::TestCommandLine::test_decompress_infile_outfile - OSError: [Errno 9] write() on read-only GzipNGFile object
FAILED tests/test_gzip_compliance.py::TestCommandLine::test_decompress_stdin_stdout - OSError: [Errno 9] write() on read-only GzipNGFile object
FAILED tests/test_gzip_ng.py::test_compress_stdin_stdout[1] - OSError: [Errno 9] write() on read-only GzipNGFile object
FAILED tests/test_gzip_ng.py::test_compress_stdin_stdout[2] - OSError: [Errno 9] write() on read-only GzipNGFile object
FAILED tests/test_gzip_ng.py::test_compress_stdin_stdout[3] - OSError: [Errno 9] write() on read-only GzipNGFile object
FAILED tests/test_gzip_ng.py::test_compress_stdin_stdout[4] - OSError: [Errno 9] write() on read-only GzipNGFile object
FAILED tests/test_gzip_ng.py::test_compress_stdin_stdout[5] - OSError: [Errno 9] write() on read-only GzipNGFile object
FAILED tests/test_gzip_ng.py::test_compress_stdin_stdout[6] - OSError: [Errno 9] write() on read-only GzipNGFile object
FAILED tests/test_gzip_ng.py::test_compress_stdin_stdout[7] - OSError: [Errno 9] write() on read-only GzipNGFile object
FAILED tests/test_gzip_ng.py::test_compress_stdin_stdout[8] - OSError: [Errno 9] write() on read-only GzipNGFile object
FAILED tests/test_gzip_ng.py::test_compress_stdin_stdout[9] - OSError: [Errno 9] write() on read-only GzipNGFile object
FAILED tests/test_gzip_ng.py::test_compress_infile_outfile - OSError: [Errno 9] write() on read-only GzipNGFile object
FAILED tests/test_gzip_ng.py::test_compress_infile_stdout - OSError: [Errno 9] write() on read-only GzipNGFile object
FAILED tests/test_gzip_ng.py::test_compress_infile_out_file - OSError: [Errno 9] write() on read-only GzipNGFile object
FAILED tests/test_gzip_ng.py::test_compress_infile_out_file_force - OSError: [Errno 9] write() on read-only GzipNGFile object
FAILED tests/test_gzip_ng.py::test_compress_infile_out_file_inmplicit_name_prompt_accept - OSError: [Errno 9] write() on read-only GzipNGFile object
FAILED tests/test_gzip_ng.py::test_compress_infile_out_file_no_name - OSError: [Errno 9] write() on read-only GzipNGFile object
FAILED tests/test_gzip_ng.py::test_decompress_on_long_input - OSError: [Errno 9] write() on read-only GzipNGFile object
========================================================================== 61 failed, 14484 passed, 2 skipped in 71.46s (0:01:11) ===========================================================================
musicinmybrain commented 4 months ago

Detailed output for the first failure:

___________________________________________________________________________________________ TestGzip.test_append ____________________________________________________________________________________________

self = <test_gzip_compliance.TestGzip testMethod=test_append>

    def test_append(self):
>       self.test_write()

tests/test_gzip_compliance.py:198:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
tests/test_gzip_compliance.py:87: in test_write
    f.write(data1 * 50)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <gzip_ng on 0x7f0bb7774e60>
data = b'  int length=DEFAULTALLOC, err = Z_OK;\n  PyObject *RetVal;\n  int flushmode = Z_FINISH;\n  unsigned long start_tota...ngth=DEFAULTALLOC, err = Z_OK;\n  PyObject *RetVal;\n  int flushmode = Z_FINISH;\n  unsigned long start_total_out;\n\n'

    def write(self, data):
        self._check_not_closed()
        if self.mode != WRITE:
            import errno
>           raise OSError(errno.EBADF, "write() on read-only GzipNGFile object")
E           OSError: [Errno 9] write() on read-only GzipNGFile object

.tox/py313/lib64/python3.13/site-packages/zlib_ng/gzip_ng.py:158: OSError
musicinmybrain commented 4 months ago

One interesting change is that gzip.GzipFile.mode has changed from an integer 1 or 2 to 'rb' or 'wb'. However, gzip.READ and gzip.WRITE reflect this change, and at a glance it doesn’t look like this particular change is responsible for any of these test failures.

musicinmybrain commented 4 months ago

One interesting change is that gzip.GzipFile.mode has changed from an integer 1 or 2 to 'rb' or 'wb'. However, gzip.READ and gzip.WRITE reflect this change, and at a glance it doesn’t look like this particular change is responsible for any of these test failures.

Aha, this is it after all! We have

https://github.com/pycompression/python-zlib-ng/blob/8373d7dff85b18e0ce3cd5b630cc743dec3f82b7/src/zlib_ng/gzip_ng.py#L44

which in Python 3.13 no longer match the values in gzip.

Changing this line to

READ, WRITE = gzip.READ, gzip.WRITE

fixes all of the test failures. I’ll open a PR.