From e9f33d449f21ff47c6b4107bb4aa8d628ea277c9 Mon Sep 17 00:00:00 2001 From: chrisiacovella Date: Thu, 14 Sep 2023 12:24:13 -0700 Subject: [PATCH] minor updates to tests --- modelforge/curation/utils.py | 13 +++++++------ modelforge/tests/test_curation.py | 11 +++++++++++ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/modelforge/curation/utils.py b/modelforge/curation/utils.py index e250b3b4..5d383894 100644 --- a/modelforge/curation/utils.py +++ b/modelforge/curation/utils.py @@ -63,11 +63,8 @@ def dict_to_hdf5(file_name: str, data: list, series_info: dict, id_key: str) -> def mkdir(path: str) -> bool: if not os.path.exists(path): - try: - os.makedirs(path) - return True - except Exception: - print("Could not create directory {path}.") + os.makedirs(path) + return True else: return False @@ -135,7 +132,7 @@ def download_from_figshare(url: str, output_path: str, force_download=False) -> else: # if the file exists and we don't set force_download to True, just use the cached version logger.debug(f"Datafile {name} already exists in {output_path}.") logger.debug( - "Using already downloaded file; use force_download=True to re-download." + "Using already downloaded file; set force_download=True to re-download." ) return name @@ -163,6 +160,9 @@ def list_files(directory: str, extension: str) -> list: >>> files = list_files('test_directory', '.xyz') """ + if not os.path.exists(directory): + raise Exception(f"{directory} not found") + logger.debug(f"Gathering {extension} files in {directory}.") files = [] @@ -189,5 +189,6 @@ def str_to_float(x: str) -> float: float Float value of the string. """ + xf = float(x.replace("*^", "e")) return xf diff --git a/modelforge/tests/test_curation.py b/modelforge/tests/test_curation.py index 320ba914..3518b18d 100644 --- a/modelforge/tests/test_curation.py +++ b/modelforge/tests/test_curation.py @@ -100,6 +100,14 @@ def test_dict_to_hdf5(prep_temp_dir): else: assert records[i][key] == test_data[i][key] + with pytest.raises(Exception): + dict_to_hdf5( + file_name=file_name_path, + data=test_data, + series_info=record_entries_series, + id_key="name_should_fail", + ) + def test_series_dict_to_hdf5(prep_temp_dir): # generate an hdf5 file from simple test data @@ -230,6 +238,9 @@ def test_list_files(prep_temp_dir): # check to see if test.hdf5 is in the files assert "test.hdf5" in files + with pytest.raises(Exception): + list_files("/path/that/should/not/exist/", ".hdf5") + def test_str_to_float(prep_temp_dir): val = str_to_float("1*^6")