From: Serhiy Storchaka Date: Mon, 12 May 2025 17:02:19 +0000 (+0300) Subject: [3.13] gh-133677: Fix tests when running in non-UTF-8 locale (GH-133865) (GH-133939) X-Git-Tag: v3.13.4~120 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d9d8e9a00c485241208a277003feb8ab9303ebae;p=thirdparty%2FPython%2Fcpython.git [3.13] gh-133677: Fix tests when running in non-UTF-8 locale (GH-133865) (GH-133939) (cherry picked from commit 14305a83d381ccdcae814abd9e2c28dda066720b) --- diff --git a/Lib/test/test_pathlib/test_pathlib.py b/Lib/test/test_pathlib/test_pathlib.py index 2b9aad14263c..aa2498f7e085 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 import_helper 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 @@ class PurePathTest(test_pathlib_abc.DummyPurePathTest): 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 fbdb8548e1ad..beb18f88c4c6 100644 --- a/Lib/test/test_urllib.py +++ b/Lib/test/test_urllib.py @@ -157,7 +157,7 @@ class urlopen_FileTests(unittest.TestCase): 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 4ffccb15dd96..41ec6a437ba9 100644 --- a/Lib/test/test_zipfile/test_core.py +++ b/Lib/test/test_zipfile/test_core.py @@ -3489,7 +3489,7 @@ class EncodedMetadataTests(unittest.TestCase): 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)