From ea770f58852c89d5dbac55bb14f5b1371512c820 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 18 Sep 2018 04:01:05 +0200 Subject: [PATCH] bpo-34589: Add test_PYTHONCOERCECLOCALE_ignored() The -E command line option must ignore the PYTHONCOERCECLOCALE environment variable. --- Lib/test/test_c_locale_coercion.py | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/Lib/test/test_c_locale_coercion.py b/Lib/test/test_c_locale_coercion.py index f62208ab2006f3..3ea7346ca75917 100644 --- a/Lib/test/test_c_locale_coercion.py +++ b/Lib/test/test_c_locale_coercion.py @@ -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): @@ -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)) @@ -214,7 +216,8 @@ 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: @@ -222,7 +225,8 @@ def _check_child_encoding_details(self, 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, @@ -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 @@ -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: @@ -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 @@ -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,