-
-
Notifications
You must be signed in to change notification settings - Fork 34.7k
gh-76183: Fix legacy locale coercion tests on platforms that already have a default C.UTF-8 locale #4361
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
gh-76183: Fix legacy locale coercion tests on platforms that already have a default C.UTF-8 locale #4361
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -160,11 +160,13 @@ def get_child_details(cls, env_vars): | |
| AVAILABLE_TARGETS = None | ||
| CLI_COERCION_TARGET = None | ||
| CLI_COERCION_WARNING = None | ||
| DEFAULT_LC_CTYPE = None | ||
|
|
||
| def setUpModule(): | ||
| global AVAILABLE_TARGETS | ||
| global CLI_COERCION_TARGET | ||
| global CLI_COERCION_WARNING | ||
| global DEFAULT_LC_CTYPE | ||
|
|
||
| if AVAILABLE_TARGETS is not None: | ||
| # initialization already done | ||
|
|
@@ -181,6 +183,22 @@ def setUpModule(): | |
| CLI_COERCION_TARGET = AVAILABLE_TARGETS[0] | ||
| CLI_COERCION_WARNING = CLI_COERCION_WARNING_FMT.format(CLI_COERCION_TARGET) | ||
|
|
||
| # Determine the platform's default LC_CTYPE from the default locale. | ||
| # POSIX provides that there *exists* a default locale to provide when | ||
| # no environment variables are set, or are set to empty strings. However, | ||
| # it does not specify that this default *must* be the "POSIX" locale, or | ||
| # how the platform selects the default. In most cases it will be set to | ||
| # "C"/"POSIX" but this is not necessarily the case. | ||
| result, py_cmd = run_python_until_end( | ||
| "-c", "import locale; print(locale.setlocale(locale.LC_CTYPE))", | ||
| __isolated=True, | ||
| LANG="", LC_ALL="", LC_CTYPE="", PYTHONCOERCECLOCALE="0" | ||
| ) | ||
| if not result.rc == 0: | ||
| result.fail(py_cmd) | ||
|
|
||
| DEFAULT_LC_CTYPE = result.out.decode("ascii").strip().upper() | ||
|
|
||
|
|
||
| class _LocaleHandlingTestCase(unittest.TestCase): | ||
| # Base class to check expected locale handling behaviour | ||
|
|
@@ -301,6 +319,11 @@ def _check_c_locale_coercion(self, | |
| # See https://bugs.python.org/issue30672 for discussion | ||
| if locale_to_set == "POSIX": | ||
| continue | ||
| elif locale_to_set == "" and DEFAULT_LC_CTYPE == "C.UTF-8": | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The condition is too restrictive:
|
||
| # The default locale is already C.UTF-8 so the subsequent tests | ||
| # don't behave as expected (they assume the default LC_CTYPE will | ||
| # be "C") | ||
| continue | ||
| with self.subTest(env_var=env_var, | ||
| nominal_locale=locale_to_set, | ||
| PYTHONCOERCECLOCALE=coerce_c_locale): | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you try setting
C_LOCALE_STREAM_ENCODINGto"utf-8"instead ?