Skip to content

Commit

Permalink
minor updates to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisiacovella committed Sep 14, 2023
1 parent ef7d93d commit e9f33d4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
13 changes: 7 additions & 6 deletions modelforge/curation/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 = []
Expand All @@ -189,5 +189,6 @@ def str_to_float(x: str) -> float:
float
Float value of the string.
"""

xf = float(x.replace("*^", "e"))
return xf
11 changes: 11 additions & 0 deletions modelforge/tests/test_curation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit e9f33d4

Please sign in to comment.