From 028a71b1de9a08a0927b82ad53c6c3c9806e6e3f Mon Sep 17 00:00:00 2001 From: "Albert Y. Shih" Date: Tue, 12 Nov 2024 17:12:28 -0500 Subject: [PATCH] Respect auto_download even if IERS_Auto predictive values are stale --- astropy/utils/iers/iers.py | 10 ++++++++++ astropy/utils/iers/tests/test_iers.py | 14 ++++++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/astropy/utils/iers/iers.py b/astropy/utils/iers/iers.py index 4ba0fc646667..cba205babbfc 100644 --- a/astropy/utils/iers/iers.py +++ b/astropy/utils/iers/iers.py @@ -905,6 +905,16 @@ def _refresh_table_as_needed(self, mjd): if max_input_mjd > predictive_mjd and (now_mjd - predictive_mjd) > auto_max_age: all_urls = (conf.iers_auto_url, conf.iers_auto_url_mirror) + # Bail out with a warning if downloading is disabled + if not conf.auto_download: + warn( + IERSStaleWarning( + "IERS_Auto predictive values are older than" + f" {conf.auto_max_age} days but downloading is disabled" + ) + ) + return + # Get the latest version try: filename = download_file(all_urls[0], sources=all_urls, cache="update") diff --git a/astropy/utils/iers/tests/test_iers.py b/astropy/utils/iers/tests/test_iers.py index aed995ab1044..162b2f5e413a 100644 --- a/astropy/utils/iers/tests/test_iers.py +++ b/astropy/utils/iers/tests/test_iers.py @@ -341,12 +341,18 @@ def test_simple(self): dat.ut1_utc(Time(60000, format="mjd").jd) assert len(warns) == 1 - # Warning only if we are getting return status + # Warning only (i.e., no exception) if we are getting return status with pytest.warns( - iers.IERSStaleWarning, match="IERS_Auto predictive values are older" - ) as warns: + iers.IERSStaleWarning, match="IERS_Auto predictive values are older.*did not find newer values" + ): dat.ut1_utc(Time(60000, format="mjd").jd, return_status=True) - assert len(warns) == 1 + + # Confirm that the warning message is different if downloading is disabled + with pytest.warns( + iers.IERSStaleWarning, match=r"IERS_Auto predictive values are older.*downloading is disabled" + ): + with iers.conf.set_temp("auto_download", False): + dat.ut1_utc(Time(60000, format="mjd").jd, return_status=True) # Now set auto_max_age = None which says that we don't care how old the # available IERS-A file is. There should be no warnings or exceptions.