-
Notifications
You must be signed in to change notification settings - Fork 49
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
Avoid issues with LC_NUMERIC locale #436
Conversation
The CI failures appear unrelated to this pull request. |
@bjlittle can you spare this some attention? Looks simple enough to me, but I'm about to be unavailable for a couple of weeks.. |
hi folks, this would be nice if you guys had a mo to approve and get it in the new 3.11 🍺 |
I'm guessing the fails will be fixed by rebasing onto current main. |
All checks are green now 🚀 |
Great work @bouweandela and sorry it has taken so long to respond ! One minor follow-on question : Is there any reasonable way of testing this to show it really works ? |
Testing that it really works would require installing a locale with the issue on the test system, e.g.
so that seems unpractical. As an alternative, I tried adding a test in def test_import(monkeypatch):
"""Test that locale is not set.
The locale should not be set when creating a system object at module
import time. See https://github.com/SciTools/cf-units/issues/435 for
additional information.
"""
def mock_read_xml(*args, **kwargs):
assert locale.getlocale(locale.LC_NUMERIC) == (None, None)
with monkeypatch.context():
monkeypatch.setattr(_ud, "read_xml", mock_read_xml)
locale.setlocale(locale.LC_ALL, "")
importlib.reload(cf_units)
importlib.reload(cf_units) when running
the second test fails, while separately they pass fine. Would you know how to restore the state after |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #436 +/- ##
=======================================
Coverage ? 90.50%
=======================================
Files ? 6
Lines ? 811
Branches ? 93
=======================================
Hits ? 734
Misses ? 64
Partials ? 13 ☔ View full report in Codecov by Sentry. |
OK this sounds like too much trouble to test -- the relevant scope is not appropriate for a unit test anyway. |
🚀 Pull Request
Avoid a crash when importing the library as described in #435.
Closes #435.