Skip to content

Commit 4563099

Browse files
authored
bpo-28180: assume UTF-8 for Mac OS X PEP 538 tests (GH-2130)
1 parent b070fd2 commit 4563099

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

Lib/test/test_c_locale_coercion.py

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,17 @@
1414
interpreter_requires_environment,
1515
)
1616

17+
# Set our expectation for the default encoding used in the C locale
18+
# for the filesystem encoding and the standard streams
19+
if sys.platform == "darwin":
20+
EXPECTED_C_LOCALE_FSENCODING = "utf-8"
21+
else:
22+
EXPECTED_C_LOCALE_FSENCODING = "ascii"
23+
24+
# XXX (ncoghlan): The above is probably still wrong for:
25+
# * Windows when PYTHONLEGACYWINDOWSFSENCODING is set
26+
# * AIX and any other platforms that use latin-1 in the C locale
27+
1728
# In order to get the warning messages to match up as expected, the candidate
1829
# order here must much the target locale order in Python/pylifecycle.c
1930
_C_UTF8_LOCALES = ("C.UTF-8", "C.utf8", "UTF-8")
@@ -134,7 +145,7 @@ def test_library_c_locale_warning(self):
134145
}
135146
with self.subTest(forced_locale=locale_to_set):
136147
self._check_child_encoding_details(var_dict,
137-
"ascii",
148+
EXPECTED_C_LOCALE_FSENCODING,
138149
[LIBRARY_C_LOCALE_WARNING])
139150

140151
# Details of the CLI locale coercion warning emitted at runtime
@@ -158,14 +169,16 @@ def setUpModule():
158169
for target_locale in _C_UTF8_LOCALES:
159170
if _set_locale_in_subprocess(target_locale):
160171
AVAILABLE_TARGETS.append(target_locale)
161-
if not AVAILABLE_TARGETS:
162-
raise unittest.SkipTest("No C-with-UTF-8 locale available")
163172

164173

165174

166175
class _LocaleCoercionTargetsTestCase(_ChildProcessEncodingTestCase):
167176
# Base class for test cases that rely on coercion targets being defined
168-
pass
177+
178+
@classmethod
179+
def setUpClass(cls):
180+
if not AVAILABLE_TARGETS:
181+
raise unittest.SkipTest("No C-with-UTF-8 locale available")
169182

170183

171184
class LocaleConfigurationTests(_LocaleCoercionTargetsTestCase):
@@ -186,6 +199,11 @@ def test_external_target_locale_configuration(self):
186199
}
187200
for env_var in ("LANG", "LC_CTYPE"):
188201
for locale_to_set in AVAILABLE_TARGETS:
202+
# XXX (ncoghlan): LANG=UTF-8 doesn't appear to work as
203+
# expected, so skip that combination for now
204+
if env_var == "LANG" and locale_to_set == "UTF-8":
205+
continue
206+
189207
with self.subTest(env_var=env_var,
190208
configured_locale=locale_to_set):
191209
var_dict = base_var_dict.copy()
@@ -251,7 +269,8 @@ def test_PYTHONCOERCECLOCALE_not_zero(self):
251269

252270
def test_PYTHONCOERCECLOCALE_set_to_zero(self):
253271
# The setting "0" should result in the locale coercion being disabled
254-
self._check_c_locale_coercion("ascii", coerce_c_locale="0")
272+
self._check_c_locale_coercion(EXPECTED_C_LOCALE_FSENCODING,
273+
coerce_c_locale="0")
255274

256275

257276
def test_main():

0 commit comments

Comments
 (0)