Skip to content

test_zipfile fails on non-UTF-8 locale�?#91917

Closed
@serhiy-storchaka

Description

@serhiy-storchaka
$ LC_ALL=en_US.iso88591 ./python -m test -vuall test_zipfile -m EncodedMetadataTests
== CPython 3.11.0a7+ (heads/re-group-name:5026649f98, Apr 24 2022, 22:45:28) [GCC 9.4.0]
== Linux-5.4.0-109-generic-x86_64-with-glibc2.31 little-endian
== cwd: /home/serhiy/py/cpython/build/test_python_197650�
== CPU count: 8
== encodings: locale=ISO-8859-1, FS=iso8859-1
0:00:00 load avg: 1.01 Run tests sequentially
0:00:00 load avg: 1.01 [1/1] test_zipfile
test_cli_with_metadata_encoding (test.test_zipfile.EncodedMetadataTests.test_cli_with_metadata_encoding) ... ERROR
test_read_after_append (test.test_zipfile.EncodedMetadataTests.test_read_after_append) ... ok
test_read_with_incorrect_metadata_encoding (test.test_zipfile.EncodedMetadataTests.test_read_with_incorrect_metadata_encoding) ... ok
test_read_with_metadata_encoding (test.test_zipfile.EncodedMetadataTests.test_read_with_metadata_encoding) ... ok
test_read_with_unsuitable_metadata_encoding (test.test_zipfile.EncodedMetadataTests.test_read_with_unsuitable_metadata_encoding) ... ok
test_read_without_metadata_encoding (test.test_zipfile.EncodedMetadataTests.test_read_without_metadata_encoding) ... ok
test_write_with_metadata_encoding (test.test_zipfile.EncodedMetadataTests.test_write_with_metadata_encoding) ... ok

======================================================================
ERROR: test_cli_with_metadata_encoding (test.test_zipfile.EncodedMetadataTests.test_cli_with_metadata_encoding)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/serhiy/py/cpython/Lib/test/test_zipfile.py", line 3396, in test_cli_with_metadata_encoding
    zipfile.main(["--metadata-encoding=shift_jis", "-e", TESTFN, TESTFN2])
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/serhiy/py/cpython/Lib/zipfile.py", line 2511, in main
    zf.extractall(curdir)
    ^^^^^^^^^^^^^^^^^^^^^
  File "/home/serhiy/py/cpython/Lib/zipfile.py", line 1675, in extractall
    self._extract_member(zipinfo, path, pwd)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/serhiy/py/cpython/Lib/zipfile.py", line 1729, in _extract_member
    open(targetpath, "wb") as target:
    ^^^^^^^^^^^^^^^^^^^^^^
UnicodeEncodeError: 'latin-1' codec can't encode character '\u4e00' in position 19: ordinal not in range(256)

----------------------------------------------------------------------
Ran 7 tests in 0.018s

FAILED (errors=1)
test test_zipfile failed
test_zipfile failed (1 error)

== Tests result: FAILURE ==

1 test failed:
    test_zipfile

Total duration: 187 ms
Tests result: FAILURE

Metadata

Metadata

Labels

3.11only security fixestestsTests in the Lib/test dirtype-bugAn unexpected behavior, bug, or error

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions