diff --git a/Lib/test/test_c_locale_coercion.py b/Lib/test/test_c_locale_coercion.py index b47adcd6ae..947b123247 100644 --- a/Lib/test/test_c_locale_coercion.py +++ b/Lib/test/test_c_locale_coercion.py @@ -27,10 +27,19 @@ EXPECT_COERCION_IN_DEFAULT_LOCALE = True # Apply some platform dependent overrides if sys.platform.startswith("linux"): - # Linux distros typically alias the POSIX locale directly to the C locale - # TODO: Once https://bugs.python.org/issue30672 is addressed, we'll be - # able to check this case unconditionally - EXPECTED_C_LOCALE_EQUIVALENTS.append("POSIX") + if test.support.is_android: + # Android defaults to using UTF-8 for all system interfaces + EXPECTED_C_LOCALE_STREAM_ENCODING = "utf-8" + EXPECTED_C_LOCALE_FS_ENCODING = "utf-8" + # XXX The command 'LC_ALL=C PYTHONCOERCECLOCALE=warn python' emits the + # warning on Android hence this change from False to True (actually to + # the default value but I wanted to point out the difference). + EXPECT_COERCION_IN_DEFAULT_LOCALE = True + else: + # Linux distros typically alias the POSIX locale directly to the C locale + # TODO: Once https://bugs.python.org/issue30672 is addressed, we'll be + # able to check this case unconditionally + EXPECTED_C_LOCALE_EQUIVALENTS.append("POSIX") elif sys.platform.startswith("aix"): # AIX uses iso8859-1 in the C locale, other *nix platforms use ASCII EXPECTED_C_LOCALE_STREAM_ENCODING = "iso8859-1" @@ -43,11 +52,6 @@ elif sys.platform == "cygwin": # TODO: Work out a robust dynamic test for this that doesn't rely on # CPython's own locale handling machinery EXPECT_COERCION_IN_DEFAULT_LOCALE = False -elif test.support.is_android: - # Android defaults to using UTF-8 for all system interfaces - EXPECTED_C_LOCALE_STREAM_ENCODING = "utf-8" - EXPECTED_C_LOCALE_FS_ENCODING = "utf-8" - EXPECT_COERCION_IN_DEFAULT_LOCALE = False # Note that the above expectations are still wrong in some cases, such as: # * Windows when PYTHONLEGACYWINDOWSFSENCODING is set @@ -329,6 +333,14 @@ class LocaleCoercionTests(_LocaleHandlingTestCase): else: _expected_warnings = None _coercion_expected = False + # XXX On Android _Py_LegacyLocaleDetected(void) returns 0 + # when no envt variable is set because + # _Py_SetLocaleFromEnv(LC_ALL) has been called before and has set + # the "C.UTF-8" locale. Therefore CLI_COERCION_WARNING is not + # printed in that case. + if (test.support.is_android and + _expected_warnings == [CLI_COERCION_WARNING]): + _expected_warnings = None self._check_child_encoding_details(base_var_dict, fs_encoding, stream_encoding,