You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
BUG: astropy.time.update_leap_seconds doesn't warn for corrupt files passed as pathlib.Path objects #16929
In #16060 and #16923, we find that astropy/time.update_leap_seconds doesn't behave correctly if passed a corrupt file as Path instead of str.
This is visible in astropy/test/test_update_leap_second.py::test_auto_update_corrupt_file, as applying the following patch
diff --git a/astropy/time/tests/test_update_leap_seconds.py b/astropy/time/tests/test_update_leap_seconds.py
index a1027a0755..45250147c3 100644
--- a/astropy/time/tests/test_update_leap_seconds.py+++ b/astropy/time/tests/test_update_leap_seconds.py@@ -58,7 +58,7 @@ class TestUpdateLeapSeconds:
update_leap_seconds(["nonsense"])
def test_auto_update_corrupt_file(self, tmp_path):
- bad_file = str(tmp_path / "no_expiration")+ bad_file = tmp_path / "no_expiration"
with open(iers.IERS_LEAP_SECOND_FILE) as fh:
lines = fh.readlines()
with open(bad_file, "w") as fh:
leads to failing the test:
E Failed: DID NOT WARN. No warnings of type (<class 'astropy.utils.exceptions.AstropyWarning'>,) matching the regex were emitted.
Regex: ValueError.*did not find expiration
Emitted warnings: [ AstropyWarning('leap-second auto-update failed due to the following exception: AttributeError("\'PosixPath\' object has no attribute \'decode\'")')].
(or in other words: a different warning is emitted first)
The issue doesn't appear to be trivial enough to be fixed directly in #16023 (which is meant as a simple refactor), but it should be done as a follow up.
There should ideally be more than one test exercising passing Path arguments to this function.
Activity
pllim commentedon Sep 4, 2024
'PosixPath' object has no attribute 'decode'Hmm. Do you still have the full traceback?pllim commentedon Sep 4, 2024
Ah, okay, that error is actually from
urlparsehereastropy/astropy/utils/iers/iers.py
Line 261 in 1b563c2
that you can reproduce like this
so that probably means
openitself needs to support Path object (new feature) for this to work (#16931)astropy/astropy/utils/iers/iers.py
Line 225 in 1b563c2