Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 842076d

Browse filesBrowse files
gh-133677: Fix tests when running in non-UTF-8 locale
1 parent 70f9b3d commit 842076d
Copy full SHA for 842076d

File tree

6 files changed

+17
-13
lines changed
Filter options

6 files changed

+17
-13
lines changed

‎Lib/test/support/strace_helper.py

Copy file name to clipboardExpand all lines: Lib/test/support/strace_helper.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def events(self):
3838
3939
This assumes the program under inspection doesn't print any non-utf8
4040
strings which would mix into the strace output."""
41-
decoded_events = self.event_bytes.decode('utf-8')
41+
decoded_events = self.event_bytes.decode('utf-8', 'surrogateescape')
4242
matches = [
4343
_syscall_regex.match(event)
4444
for event in decoded_events.splitlines()

‎Lib/test/test_argparse.py

Copy file name to clipboardExpand all lines: Lib/test/test_argparse.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6972,8 +6972,8 @@ def make_zip_script(self, script_name, name_in_zip=None):
69726972
return zip_name
69736973

69746974
def check_usage(self, expected, *args, **kwargs):
6975-
res = script_helper.assert_python_ok('-Xutf8', *args, '-h', **kwargs)
6976-
self.assertEqual(res.out.splitlines()[0].decode(),
6975+
res = script_helper.assert_python_ok(*args, '-h', **kwargs)
6976+
self.assertEqual(os.fsdecode(res.out.splitlines()[0]),
69776977
f'usage: {expected} [-h]')
69786978

69796979
def test_script(self, compiled=False):

‎Lib/test/test_asyncio/test_tools.py

Copy file name to clipboardExpand all lines: Lib/test/test_asyncio/test_tools.py
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -791,21 +791,21 @@ def test_table_output_format(self):
791791
class TestAsyncioToolsEdgeCases(unittest.TestCase):
792792

793793
def test_task_awaits_self(self):
794-
"""A task directly awaits itself should raise a cycle."""
794+
"""A task directly awaits itself - should raise a cycle."""
795795
input_ = [(1, [(1, "Self-Awaiter", [[["loopback"], 1]])])]
796796
with self.assertRaises(tools.CycleFoundException) as ctx:
797797
tools.build_async_tree(input_)
798798
self.assertIn([1, 1], ctx.exception.cycles)
799799

800800
def test_task_with_missing_awaiter_id(self):
801-
"""Awaiter ID not in task list should not crash, just show 'Unknown'."""
801+
"""Awaiter ID not in task list - should not crash, just show 'Unknown'."""
802802
input_ = [(1, [(1, "Task-A", [[["coro"], 999]])])] # 999 not defined
803803
table = tools.build_task_table(input_)
804804
self.assertEqual(len(table), 1)
805805
self.assertEqual(table[0][4], "Unknown")
806806

807807
def test_duplicate_coroutine_frames(self):
808-
"""Same coroutine frame repeated under a parent should deduplicate."""
808+
"""Same coroutine frame repeated under a parent - should deduplicate."""
809809
input_ = [
810810
(
811811
1,
@@ -829,7 +829,7 @@ def test_duplicate_coroutine_frames(self):
829829
self.assertIn("Task-1", flat)
830830

831831
def test_task_with_no_name(self):
832-
"""Task with no name in id2name should still render with fallback."""
832+
"""Task with no name in id2name - should still render with fallback."""
833833
input_ = [(1, [(1, "root", [[["f1"], 2]]), (2, None, [])])]
834834
# If name is None, fallback to string should not crash
835835
tree = tools.build_async_tree(input_)

‎Lib/test/test_pathlib/test_pathlib.py

Copy file name to clipboardExpand all lines: Lib/test/test_pathlib/test_pathlib.py
+8-4Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from test.support import is_emscripten, is_wasi
2121
from test.support import infinite_recursion
2222
from test.support import os_helper
23-
from test.support.os_helper import TESTFN, FakePath
23+
from test.support.os_helper import TESTFN, FS_NONASCII, FakePath
2424
try:
2525
import fcntl
2626
except ImportError:
@@ -770,12 +770,16 @@ def test_as_uri_windows(self):
770770
self.assertEqual(self.make_uri(P('c:/')), 'file:///c:/')
771771
self.assertEqual(self.make_uri(P('c:/a/b.c')), 'file:///c:/a/b.c')
772772
self.assertEqual(self.make_uri(P('c:/a/b%#c')), 'file:///c:/a/b%25%23c')
773-
self.assertEqual(self.make_uri(P('c:/a/b\xe9')), 'file:///c:/a/b%C3%A9')
774773
self.assertEqual(self.make_uri(P('//some/share/')), 'file://some/share/')
775774
self.assertEqual(self.make_uri(P('//some/share/a/b.c')),
776775
'file://some/share/a/b.c')
777-
self.assertEqual(self.make_uri(P('//some/share/a/b%#c\xe9')),
778-
'file://some/share/a/b%25%23c%C3%A9')
776+
777+
from urllib.parse import quote_from_bytes
778+
QUOTED_FS_NONASCII = quote_from_bytes(os.fsencode(FS_NONASCII))
779+
self.assertEqual(self.make_uri(P('c:/a/b' + FS_NONASCII)),
780+
'file:///c:/a/b' + QUOTED_FS_NONASCII)
781+
self.assertEqual(self.make_uri(P('//some/share/a/b%#c' + FS_NONASCII)),
782+
'file://some/share/a/b%25%23c' + QUOTED_FS_NONASCII)
779783

780784
@needs_windows
781785
def test_ordering_windows(self):

‎Lib/test/test_urllib.py

Copy file name to clipboardExpand all lines: Lib/test/test_urllib.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def setUp(self):
109109
finally:
110110
f.close()
111111
self.pathname = os_helper.TESTFN
112-
self.quoted_pathname = urllib.parse.quote(self.pathname)
112+
self.quoted_pathname = urllib.parse.quote(os.fsencode(self.pathname))
113113
self.returned_obj = urllib.request.urlopen("file:%s" % self.quoted_pathname)
114114

115115
def tearDown(self):

‎Lib/test/test_zipfile/test_core.py

Copy file name to clipboardExpand all lines: Lib/test/test_zipfile/test_core.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3642,7 +3642,7 @@ def test_cli_with_metadata_encoding_extract(self):
36423642
except OSError:
36433643
pass
36443644
except UnicodeEncodeError:
3645-
self.skipTest(f'cannot encode file name {fn!r}')
3645+
self.skipTest(f'cannot encode file name {fn!a}')
36463646

36473647
zipfile.main(["--metadata-encoding=shift_jis", "-e", TESTFN, TESTFN2])
36483648
listing = os.listdir(TESTFN2)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.