diff --git a/pysm3/tests/test_utils.py b/pysm3/tests/test_utils.py index 29be8e98..1fde71b0 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,8 @@ 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..b0b25552 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,11 @@ 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