Skip to content

Commit

Permalink
[nomenclature._finder_writer] don't fail if write_to_disk=True but fi…
Browse files Browse the repository at this point in the history
…le exists, tests added
  • Loading branch information
gph82 committed Jan 15, 2024
1 parent 273f327 commit 2192edc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
4 changes: 3 additions & 1 deletion mdciao/nomenclature/nomenclature.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,12 @@ def _finder_writer(full_local_path,
The URL or local path to
the file that was used
"""
found_locally = False
try:
return_name = full_local_path
_DF = local2DF_lambda(full_local_path)
print("%s found locally." % full_local_path)
found_locally=True
except FileNotFoundError as e:
_DF = e
if verbose:
Expand All @@ -232,7 +234,7 @@ def _finder_writer(full_local_path,
_DF = e

if isinstance(_DF, _DataFrame):
if write_to_disk:
if write_to_disk and not found_locally:
if _path.exists(full_local_path):
raise FileExistsError("Cannot overwrite existing file %s" % full_local_path)
if _path.splitext(full_local_path)[-1] == ".xlsx":
Expand Down
11 changes: 11 additions & 0 deletions tests/test_nomenclature.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,17 @@ def test_not_find_online_but_no_raise(self):
assert df is None
assert isinstance(filename, str)

def test_wont_fail_if_found_online_and_write_to_disk(self):
df, filename = nomenclature._GPCRdb_finder(test_filenames.GPCRmd_B2AR_nomenclature_test_xlsx,
try_web_lookup=False,
write_to_disk=True,
)

assert isinstance(df, DataFrame)
assert isinstance(filename, str)
_np.testing.assert_array_equal(list(df.keys())[:3], nomenclature._GPCR_mandatory_fields)
assert any([key in df.keys() for key in nomenclature._GPCR_mandatory_fields]) # at least one scheme


class Test_table2GPCR_by_AAcode(unittest.TestCase):
def setUp(self):
Expand Down

0 comments on commit 2192edc

Please sign in to comment.