From b9c4b7ccf342e86ea5f6f029a5e87f20e2af3afd Mon Sep 17 00:00:00 2001 From: Andrea Zonca Date: Fri, 9 Jun 2023 09:29:31 -0700 Subject: [PATCH] suggest to update PySM 3 in case file not found See https://github.com/galsci/pysm/pull/164 --- pysm3/tests/test_utils.py | 5 +++++ pysm3/utils/data.py | 8 +++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/pysm3/tests/test_utils.py b/pysm3/tests/test_utils.py index 29be8e98..df9aaf42 100644 --- a/pysm3/tests/test_utils.py +++ b/pysm3/tests/test_utils.py @@ -5,6 +5,7 @@ from astropy.io import fits from astropy.tests.helper import assert_quantity_allclose from pysm3 import utils +from urllib.error import URLError def test_get_relevant_frequencies(): @@ -148,3 +149,7 @@ def test_add_metadata_different_units(test_fits_file): assert f[1].header["TUNIT2"] == "mK_RJ" assert f[1].header["TUNIT3"] == "K_CMB" assert f[1].header["REF_FREQ"] == "353 GHz" + +def test_data_raise(): + with pytest.raises(URLError): + pysm3.utils.RemoteData().get("doesntexist.txt") diff --git a/pysm3/utils/data.py b/pysm3/utils/data.py index 890e2ee4..58d16412 100644 --- a/pysm3/utils/data.py +++ b/pysm3/utils/data.py @@ -1,5 +1,7 @@ import os import logging +from urllib.error import URLError + from astropy.utils import data @@ -46,5 +48,9 @@ def get(self, filename): "remote_timeout", 90 ): log.info(f"Retrieve data for {filename} (if not cached already)") - full_path = data.get_pkg_data_filename(filename, show_progress=True) + try: + full_path = data.get_pkg_data_filename(filename, show_progress=True) + except URLError as e: + log.error("File not found, please make sure you are using the latest version of PySM 3") + raise e return full_path