diff --git a/rex/utilities/utilities.py b/rex/utilities/utilities.py index 8f53537df..09e32eb6f 100644 --- a/rex/utilities/utilities.py +++ b/rex/utilities/utilities.py @@ -344,8 +344,11 @@ def check_res_file(res_file): raise FileInputError(msg) else: - multi_h5_res, hsds = check_hsds_file(res_file) - bad = not hsds + try: + multi_h5_res, hsds = check_hsds_file(res_file) + bad = not hsds + except (OSError, ValueError): # cannot connect to HSDS + bad = True if bad: msg = ("{} is not a valid file path, and HSDS " diff --git a/rex/version.py b/rex/version.py index 886bbf11c..64025e847 100644 --- a/rex/version.py +++ b/rex/version.py @@ -1,3 +1,3 @@ """rex Version number""" -__version__ = "0.3.4" +__version__ = "0.3.5" diff --git a/tests/test_utilities.py b/tests/test_utilities.py index 593d8c554..9f52be1fc 100644 --- a/tests/test_utilities.py +++ b/tests/test_utilities.py @@ -9,7 +9,7 @@ import pandas as pd import pytest -from rex.utilities import parse_table +from rex.utilities import parse_table, check_res_file from rex import TESTDATADIR NSRDB_DIR = os.path.join(TESTDATADIR, 'nsrdb') @@ -50,6 +50,25 @@ def test_parse_table(): parse_table([0, 1, 2]) +def test_check_res_file_dne(): + """Test check_res_file() when file does not exist""" + with TemporaryDirectory() as td: + test_file = os.path.join(td, "gen.h5") + + with pytest.raises(FileNotFoundError) as error: + check_res_file(test_file) + + expected_msg = ("gen.h5 is not a valid file path, and HSDS cannot " + "be checked for a file at this path!") + assert expected_msg in str(error) + + open(test_file, "w").close() # pylint: disable=consider-using-with + multi_file, hsds = check_res_file(test_file) + + assert not multi_file + assert not hsds + + def execute_pytest(capture='all', flags='-rapP'): """Execute module as pytest with detailed summary report.