gh-91917: Fix test_zipfile on non-UTF-8 locale (GH-91921)

Skip the extraction test if file names are not encodable.
This commit is contained in:
Serhiy Storchaka 2022-04-26 08:01:33 +03:00 committed by GitHub
parent a568585069
commit 4153f2cbcb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -3391,8 +3391,19 @@ class EncodedMetadataTests(unittest.TestCase):
for name in self.file_names:
self.assertIn(name, listing)
def test_cli_with_metadata_encoding_extract(self):
os.mkdir(TESTFN2)
self.addCleanup(rmtree, TESTFN2)
# Depending on locale, extracted file names can be not encodable
# with the filesystem encoding.
for fn in self.file_names:
try:
os.stat(os.path.join(TESTFN2, fn))
except OSError:
pass
except UnicodeEncodeError:
self.skipTest(f'cannot encode file name {fn!r}')
zipfile.main(["--metadata-encoding=shift_jis", "-e", TESTFN, TESTFN2])
listing = os.listdir(TESTFN2)
for name in self.file_names: