Skip to content

Commit d338d0b

Browse files
gh-152905: Tolerate equivalent-space substitution in the encoding test
An 8-bit locale substitutes an equivalent for a space character it cannot encode: e.g. es_ES uses U+202F NARROW NO-BREAK SPACE in AM_STR/PM_STR in its UTF-8 locale but U+00A0 NO-BREAK SPACE in the ISO-8859-1 one. Fold space-separator characters together before comparing so the test ignores such substitutions. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 575cf43 commit d338d0b

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

Lib/test/test__locale.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import locale
99
import sys
10+
import unicodedata
1011
import unittest
1112
from platform import uname, libc_ver
1213

@@ -315,6 +316,14 @@ def test_nl_langinfo_encoding_independent(self):
315316
'zh_TW.BIG5',
316317
'th_TH.TIS-620',
317318
]
319+
320+
# An 8-bit locale substitutes an equivalent for a space it cannot
321+
# encode (e.g. es_ES has U+202F in UTF-8 but U+00A0 in ISO-8859-1),
322+
# so fold spaces before comparing.
323+
def fold_spaces(s):
324+
return ''.join(' ' if unicodedata.category(c) == 'Zs' else c
325+
for c in s)
326+
318327
tested = False
319328
for legacy_locale in legacy_locales:
320329
locs = (legacy_locale.partition('.')[0] + '.UTF-8', legacy_locale)
@@ -332,7 +341,8 @@ def test_nl_langinfo_encoding_independent(self):
332341
# The result must not depend on the locale encoding.
333342
for name, item in items:
334343
with self.subTest(locales=locs, name=name):
335-
self.assertEqual(values[0][name], values[1][name])
344+
self.assertEqual(fold_spaces(values[0][name]),
345+
fold_spaces(values[1][name]))
336346
if not tested:
337347
self.skipTest('no suitable locale pairs')
338348

0 commit comments

Comments
 (0)