https://github.com/python/cpython/commit/d9d8e9a00c485241208a277003feb8ab9303ebae
commit: d9d8e9a00c485241208a277003feb8ab9303ebae
branch: 3.13
author: Serhiy Storchaka <storch...@gmail.com>
committer: serhiy-storchaka <storch...@gmail.com>
date: 2025-05-12T17:02:19Z
summary:

[3.13] gh-133677: Fix tests when running in non-UTF-8 locale (GH-133865) 
(GH-133939)

(cherry picked from commit 14305a83d381ccdcae814abd9e2c28dda066720b)

files:
M Lib/test/test_pathlib/test_pathlib.py
M Lib/test/test_urllib.py
M Lib/test/test_zipfile/test_core.py

diff --git a/Lib/test/test_pathlib/test_pathlib.py 
b/Lib/test/test_pathlib/test_pathlib.py
index 2b9aad14263c27..aa2498f7e08543 100644
--- a/Lib/test/test_pathlib/test_pathlib.py
+++ b/Lib/test/test_pathlib/test_pathlib.py
@@ -17,7 +17,7 @@
 from test.support import is_emscripten, is_wasi
 from test.support import infinite_recursion
 from test.support import os_helper
-from test.support.os_helper import TESTFN, FakePath
+from test.support.os_helper import TESTFN, FS_NONASCII, FakePath
 from test.test_pathlib import test_pathlib_abc
 from test.test_pathlib.test_pathlib_abc import needs_posix, needs_windows, 
needs_symlinks
 
@@ -479,12 +479,16 @@ def test_as_uri_windows(self):
         self.assertEqual(P('c:/').as_uri(), 'file:///c:/')
         self.assertEqual(P('c:/a/b.c').as_uri(), 'file:///c:/a/b.c')
         self.assertEqual(P('c:/a/b%#c').as_uri(), 'file:///c:/a/b%25%23c')
-        self.assertEqual(P('c:/a/b\xe9').as_uri(), 'file:///c:/a/b%C3%A9')
         self.assertEqual(P('//some/share/').as_uri(), 'file://some/share/')
         self.assertEqual(P('//some/share/a/b.c').as_uri(),
                          'file://some/share/a/b.c')
-        self.assertEqual(P('//some/share/a/b%#c\xe9').as_uri(),
-                         'file://some/share/a/b%25%23c%C3%A9')
+
+        from urllib.parse import quote_from_bytes
+        QUOTED_FS_NONASCII = quote_from_bytes(os.fsencode(FS_NONASCII))
+        self.assertEqual(P('c:/a/b' + FS_NONASCII).as_uri(),
+                         'file:///c:/a/b' + QUOTED_FS_NONASCII)
+        self.assertEqual(P('//some/share/a/b%#c' + FS_NONASCII).as_uri(),
+                         'file://some/share/a/b%25%23c' + QUOTED_FS_NONASCII)
 
     @needs_windows
     def test_ordering_windows(self):
diff --git a/Lib/test/test_urllib.py b/Lib/test/test_urllib.py
index fbdb8548e1ad4f..beb18f88c4c6e4 100644
--- a/Lib/test/test_urllib.py
+++ b/Lib/test/test_urllib.py
@@ -157,7 +157,7 @@ def setUp(self):
         finally:
             f.close()
         self.pathname = os_helper.TESTFN
-        self.quoted_pathname = urllib.parse.quote(self.pathname)
+        self.quoted_pathname = urllib.parse.quote(os.fsencode(self.pathname))
         self.returned_obj = urlopen("file:%s" % self.quoted_pathname)
 
     def tearDown(self):
diff --git a/Lib/test/test_zipfile/test_core.py 
b/Lib/test/test_zipfile/test_core.py
index 4ffccb15dd963b..41ec6a437ba917 100644
--- a/Lib/test/test_zipfile/test_core.py
+++ b/Lib/test/test_zipfile/test_core.py
@@ -3489,7 +3489,7 @@ def test_cli_with_metadata_encoding_extract(self):
             except OSError:
                 pass
             except UnicodeEncodeError:
-                self.skipTest(f'cannot encode file name {fn!r}')
+                self.skipTest(f'cannot encode file name {fn!a}')
 
         zipfile.main(["--metadata-encoding=shift_jis", "-e", TESTFN, TESTFN2])
         listing = os.listdir(TESTFN2)

_______________________________________________
Python-checkins mailing list -- python-checkins@python.org
To unsubscribe send an email to python-checkins-le...@python.org
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: arch...@mail-archive.com

Reply via email to