]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-91917: Fix test_zipfile on non-UTF-8 locale (GH-91921)
authorSerhiy Storchaka <storchaka@gmail.com>
Tue, 26 Apr 2022 05:01:33 +0000 (08:01 +0300)
committerGitHub <noreply@github.com>
Tue, 26 Apr 2022 05:01:33 +0000 (08:01 +0300)
Skip the extraction test if file names are not encodable.

Lib/test/test_zipfile.py

index 17111b3a40fef9357ee95852da1fb611ba4384d9..848bf4f76d4536d08e197591ec417c133429f3cc 100644 (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: