Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions Lib/test/test_c_locale_coercion.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def _handle_output_variations(data):
return data

@classmethod
def get_child_details(cls, env_vars, xoption=None):
def get_child_details(cls, env_vars, xoption=None, ignore_env=False):
"""Retrieves fsencoding and standard stream details from a child process

Returns (encoding_details, stderr_lines):
Expand All @@ -151,6 +151,8 @@ def get_child_details(cls, env_vars, xoption=None):
that.
"""
args = []
if ignore_env:
args.append('-E')
if xoption:
args.extend(("-X", f"coerce_c_locale={xoption}"))
args.extend(("-X", "utf8=0", "-c", cls.CHILD_PROCESS_SCRIPT))
Expand Down Expand Up @@ -214,15 +216,17 @@ def _check_child_encoding_details(self,
expected_stream_encoding,
expected_warnings,
coercion_expected,
xoption=None):
xoption=None,
ignore_env=False):
"""Check the C locale handling for the given process environment

Parameters:
expected_fs_encoding: expected sys.getfilesystemencoding() result
expected_stream_encoding: expected encoding for standard streams
expected_warning: stderr output to expect (if any)
"""
result = EncodingDetails.get_child_details(env_vars, xoption)
result = EncodingDetails.get_child_details(env_vars, xoption,
ignore_env)
encoding_details, stderr_lines = result
expected_details = EncodingDetails.get_expected_details(
coercion_expected,
Expand Down Expand Up @@ -293,6 +297,7 @@ def _check_c_locale_coercion(self,
expected_warnings=None,
coercion_expected=True,
use_xoption=False,
ignore_env=False,
**extra_vars):
"""Check the C locale handling for various configurations

Expand Down Expand Up @@ -350,7 +355,8 @@ def _check_c_locale_coercion(self,
stream_encoding,
_expected_warnings,
_coercion_expected,
xoption=xoption)
xoption=xoption,
ignore_env=ignore_env)

# Check behaviour for explicitly configured locales
for locale_to_set in EXPECTED_C_LOCALE_EQUIVALENTS:
Expand All @@ -366,7 +372,8 @@ def _check_c_locale_coercion(self,
stream_encoding,
expected_warnings,
coercion_expected,
xoption=xoption)
xoption=xoption,
ignore_env=ignore_env)

def test_PYTHONCOERCECLOCALE_not_set(self):
# This should coerce to the first available target locale by default
Expand Down Expand Up @@ -398,6 +405,14 @@ def test_PYTHONCOERCECLOCALE_set_to_zero(self):
LC_ALL="C",
coercion_expected=False)

def test_PYTHONCOERCECLOCALE_ignored(self):
# The -E command line option must ignore
# the PYTHONCOERCECLOCALE environment variable
for value in ("0", "1", "warn"):
self._check_c_locale_coercion("utf-8", "utf-8",
coerce_c_locale=value,
ignore_env=True)

def test_LC_ALL_set_to_C(self):
# Setting LC_ALL should render the locale coercion ineffective
self._check_c_locale_coercion(EXPECTED_C_LOCALE_FS_ENCODING,
Expand Down