-
-
Notifications
You must be signed in to change notification settings - Fork 30.4k
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
bpo-32002: Refactor C locale coercion tests #4369
bpo-32002: Refactor C locale coercion tests #4369
Conversation
@@ -15,27 +15,36 @@ | |||
interpreter_requires_environment, | |||
) | |||
|
|||
# Set the list of ways we expect to be able to ask for the "C" locale | |||
EXPECTED_C_LOCALE_EQUIVALENTS = ["C", "invalid.ascii"] |
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.
I think ""
should be included in this list otherwise the case where all the locale envt variables are set to ""
may not be tested. On Android it is only the tests that have coerce_c_locale="warn"
that must be skipped when all locale envt variables are set to ""
.
There is currently no test run for when none of these variables is defined and AFAIK it seems correct since it is equivalent to having all locale envt variables set to ""
. But since it is such a common case, testing with all locale envt variables set to ""
should be mandatory for all platforms.
Maybe EXPECTED_C_LOCALE_EQUIVALENTS
could be replaced with LOCALES_TO_TEST
.
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.
That makes sense. If we go that way, then what I'd actually suggest we do is give the empty locale a dedicated test case, separate from the C locale equivalents.
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.
And a dedicated test case for the empty locale would be more explicit.
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.
+1 to a dedicated test case for empty locale.
Lib/test/test_c_locale_coercion.py
Outdated
@@ -45,7 +54,7 @@ | |||
# There's no reliable cross-platform way of checking locale alias | |||
# lists, so the only way of knowing which of these locales will work | |||
# is to try them with locale.setlocale(). We do that in a subprocess | |||
# to avoid altering the locale of the test runner. | |||
# in setupModule() below to avoid altering the locale of the test runner. |
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.
s/setupModule/setUpModule/
Lib/test/test_c_locale_coercion.py
Outdated
@@ -215,7 +224,8 @@ def _check_child_encoding_details(self, | |||
class LocaleConfigurationTests(_LocaleHandlingTestCase): | |||
# Test explicit external configuration via the process environment | |||
|
|||
def setUpClass(): | |||
@classmethod | |||
def setUpClass(cls): |
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.
In the comment below:
s/setupModule/setUpModule/
OK, I've factored out the default case to its own subtest. @embray, would you mind trying this patch out on Cygwin and seeing how it breaks? I'm thinking the right order to do things will be to get #4334 merged for Android, rebase this test case change on top of that one, and then figure out a reasonable way to make the expected behaviour in the default locale automatically adjust itself (without making the test case tautological). |
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.
The tests are successfull on Android when the following changes are made.
Lib/test/test_c_locale_coercion.py
Outdated
# | ||
# Options for dealing with this: | ||
# * Don't set PYTHON_COERCE_C_LOCALE on such platforms (e.g. Windows doesn't) | ||
# * Don't set the PYTHON_COERCE_C_LOCALE preprocessor definition on |
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.
s/PYTHON_COERCE_C_LOCALE/PY_COERCE_C_LOCALE/
Lib/test/test_c_locale_coercion.py
Outdated
# Check behaviour for the default locale | ||
with self.subTest(default_locale=True, | ||
PYTHONCOERCECLOCALE=coerce_c_locale): | ||
var_dict = base_var_dict.copy() |
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.
base_var_dict
can be used directly without a copy here.
Lib/test/test_c_locale_coercion.py
Outdated
|
||
# Check behaviour for the default locale | ||
with self.subTest(default_locale=True, |
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.
This block can only be run if the following conditional is true, otherwise some test results may not match the expected results:
if set(base_var_dict).isdisjoint(extra_vars):
For clarity, this statement written above may be moved down, when checking for explicitly configured locales:
base_var_dict.update(extra_vars)
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.
The expectation is that the test case that passes in extra_vars
will also set expected_warnings
and coercion_expected
appropriately.
The current use case is the tests that sets LC_ALL='C'
, and expects that to both disable coercion, and potentially result in a warning (for the PYTHONCOERCECLOCALE=warn
case).
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase And if you don't make the requested changes, you will be put in the comfy chair! |
I also think that this is one of those cases where seemingly tautological test cases may still be worth running, due to non-trivial interactions between the interpreter, the environment, libc, libintl, etc... |
I'm actually starting to wonder if we should put together a configure check that reports back the result of:
That way we could query |
This test still fails on Cygwin because it assumes that by default the locale will be "C" and that coercion will happen (which results in the
In #4361 I just skipped the cases didn't explicitly set one of the LC_ vars to |
@ncoghlan I think the configure-time check is a good idea. It could still be disabled when cross-compiling, in which case a fallback is needed. But it might be useful to have as a first pass, especially for use by the test suite. |
On problem I have noticed, at least on Cygwin, is that |
I think we should limit the use of configure for setting the platform type instead and hard code the specific expectations for a platform in For example Android had an entry in the |
@embray what are the test results if you replace |
@xdegaye That fails all the same on Cygwin. The difference between Cygwin and Android here are different. On Cygwin the meaning of the In other words, |
Exactly which locale requests will end up giving you the "C" locale is actually platform dependent. A blank locale and "POSIX" will translate to "C" on most Linux distros, but may not do so on other platforms, so this adjusts the way the tests are structured accordingly. This may also prove sufficient to fix a current test failure on Cygwin (hence the issue reference)
90b8bb5
to
05abe72
Compare
@xdegaye @embray I'm going to merge this once the current CI run finishes (so I can build a patch for https://bugs.python.org/issue30672 on top of it), but I'll leave the tracker issue as "pending" until you've confirmed that this works as intended on Cygwin and Android |
Although it would help not to overwrite the Android fixes when rebasing the patch :) So change of plan: I'll hold off on merging until you've both given the thumbs up. If it looks good, @xdegaye can merge it, otherwise I'll deal with it after I get back from NZ. |
The test_c_locale_coercion.log file is the output of running
|
My phone is essentially my only computer until January, but I believe
@xdegaye should have permission to push to my PR branch as a CPython
maintainer.
|
# this code path is run with environ['LC_ALL'] == 'C', then | ||
# LEGACY_LOCALE_WARNING is printed. | ||
if (test.support.is_android and | ||
_expected_warnings == [CLI_COERCION_WARNING]): |
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.
I need to study this a bit more carefully, but I believe this condition may apply for Cygwin as well (or anywhere that the default locale has UTF-8 encoding).
I still get the following failures on Cygwin:
But +1 to going ahead and merging, if you want, as this is significantly cleaned up, and I can look into addressing the final Cygwin-related bits on top of this. |
Merged! Thanks for the reviews and updates, folks :) |
Exactly which locale requests will end up giving
you the "C" locale is actually platform dependent.
A blank locale and "POSIX" will translate to "C"
on most Linux distros, but may not do so on other
platforms, so this adjusts the way the tests are
structured accordingly.
This may also prove sufficient to fix a current
test failure on Cygwin (hence the issue reference)
https://bugs.python.org/issue32002