Skip to content

Commit

Permalink
Add more non-BMP tests; fix test on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
vstinner committed Jan 17, 2025
1 parent 8f2ead7 commit f1c5232
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions Lib/test/test_threading.py
Original file line number Diff line number Diff line change
Expand Up @@ -2135,6 +2135,10 @@ def test_set_name(self):
# on Windows
"x" * (limit - 1) + "\U0010FFFF",
"x" * (limit - 2) + "\U0010FFFF" * 2,
"x" + "\U0001f40d" * limit,
"xx" + "\U0001f40d" * limit,
"xxx" + "\U0001f40d" * limit,
"xxxx" + "\U0001f40d" * limit,
]
if os_helper.FS_NONASCII:
tests.append(f"nonascii:{os_helper.FS_NONASCII}")
Expand Down Expand Up @@ -2162,11 +2166,18 @@ def work():
else:
expected = os.fsdecode(encoded)
else:
expected = name[:truncate]
if ord(expected[-1]) > 0xFFFF:
# truncate the last non-BMP character to omit a lone
# surrogate character
expected = expected[:-1]
size = 0
chars = []
for ch in name:
if ord(ch) > 0xFFFF:
size += 2
else:
size += 1
if size > truncate:
break
chars.append(ch)
expected = ''.join(chars)

if '\0' in expected:
expected = expected.split('\0', 1)[0]

Expand Down

0 comments on commit f1c5232

Please sign in to comment.