-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Fix Python2 test failures in certain locales #22213
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -417,6 +417,32 @@ def test_numpy_errstate_is_default(): | |
assert np.geterr() == expected | ||
|
||
|
||
@td.skip_if_windows | ||
def test_can_set_locale_valid_set(): | ||
# Setting the default locale should return True | ||
assert tm.can_set_locale('') is True | ||
|
||
|
||
@td.skip_if_windows | ||
def test_can_set_locale_invalid_set(): | ||
# Setting an invalid locale should return False | ||
assert tm.can_set_locale('non-existent_locale') is False | ||
|
||
|
||
@td.skip_if_windows | ||
def test_can_set_locale_invalid_get(monkeypatch): | ||
# In some cases, an invalid locale can be set, | ||
# but a subsequent getlocale() raises a ValueError | ||
# See GH 22129 | ||
|
||
def mockgetlocale(): | ||
raise ValueError() | ||
|
||
with monkeypatch.context() as m: | ||
m.setattr(locale, 'getlocale', mockgetlocale) | ||
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. Do we need to patch this? From the comment above, shouldn't it naturally raise a ValueError after setting 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. If locale.Error is raised while setting The second test needs to simulate successfully setting 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. Hmm so does 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.
In the second test I am trying to simulate the behaviour of 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. Right - so isn't the patch to 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. On my system (Ubuntu 18.04), Python2 gives me:
Whereas Python3 gives me:
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. This works (in Python2 and Python3):
So shall we rather go with 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. Are you saying 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 documentation gives this an example.
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. Ah OK that's fair - thanks for pointing there! |
||
assert tm.can_set_locale('') is False | ||
|
||
|
||
@td.skip_if_windows | ||
class TestLocaleUtils(object): | ||
|
||
|
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.
Have these skips always been in place or is this a new addition in latest push?
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.
They've been there since I first added the tests.
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.
OK thanks. Can you move these into the
TestLocaleUtils
class? It seems like they should logically be grouped in there and that class already has the decorator to skip windows.Should be the last change - thanks for hanging with the updates!
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.
OK, will do. Unfortunately I'll only be able to get to it tomorrow.