From 1d9a2a42e44002aa5ddc26aa66cba8145b0ba377 Mon Sep 17 00:00:00 2001 From: ppinchuk Date: Fri, 23 May 2025 17:10:06 -0600 Subject: [PATCH 1/5] Add fallback if HSDS cannot be reached or folder does not exist --- rex/utilities/utilities.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/rex/utilities/utilities.py b/rex/utilities/utilities.py index 8f53537df..86ce2581b 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: # cannot connect to HSDS + bad = True if bad: msg = ("{} is not a valid file path, and HSDS " From e300b680467c2f88c8b660e4f4d2f9351d64852b Mon Sep 17 00:00:00 2001 From: ppinchuk Date: Fri, 23 May 2025 17:10:21 -0600 Subject: [PATCH 2/5] Bump version --- rex/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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" From 73a1f91fb2a82dd8b68cade07d1c9867c6b5f068 Mon Sep 17 00:00:00 2001 From: ppinchuk Date: Fri, 23 May 2025 17:16:34 -0600 Subject: [PATCH 3/5] Add test --- tests/test_utilities.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/tests/test_utilities.py b/tests/test_utilities.py index 593d8c554..adc73723f 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() + 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. From c2d0412604fb34f17c89bb55f7e0c50f9851515d Mon Sep 17 00:00:00 2001 From: ppinchuk Date: Fri, 23 May 2025 17:19:11 -0600 Subject: [PATCH 4/5] Address linter error --- tests/test_utilities.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_utilities.py b/tests/test_utilities.py index adc73723f..9f52be1fc 100644 --- a/tests/test_utilities.py +++ b/tests/test_utilities.py @@ -62,7 +62,7 @@ def test_check_res_file_dne(): "be checked for a file at this path!") assert expected_msg in str(error) - open(test_file, "w").close() + open(test_file, "w").close() # pylint: disable=consider-using-with multi_file, hsds = check_res_file(test_file) assert not multi_file From e2f5b56d19df7ce6beb99ce6c7ced1bc23fffb63 Mon Sep 17 00:00:00 2001 From: ppinchuk Date: Fri, 23 May 2025 17:29:23 -0600 Subject: [PATCH 5/5] Catch extra exception --- rex/utilities/utilities.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rex/utilities/utilities.py b/rex/utilities/utilities.py index 86ce2581b..09e32eb6f 100644 --- a/rex/utilities/utilities.py +++ b/rex/utilities/utilities.py @@ -347,7 +347,7 @@ def check_res_file(res_file): try: multi_h5_res, hsds = check_hsds_file(res_file) bad = not hsds - except OSError: # cannot connect to HSDS + except (OSError, ValueError): # cannot connect to HSDS bad = True if bad: