Skip to content

Commit

Permalink
fixed unit test for file_path
Browse files Browse the repository at this point in the history
  • Loading branch information
SamCox822 committed Feb 22, 2024
1 parent 40761c4 commit e05111c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
9 changes: 9 additions & 0 deletions mdagent/tools/base_tools/preprocess_tools/pdb_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -1406,6 +1406,15 @@ def molname2smiles(
"One possible cause is that the input is incorrect, "
"input one molecule at a time."
)
except IndexError:
print("The smiles property was not found for this molecule.")
except TypeError:
print(
"The information from the PubChem database is "
"not in the expected format."
)
except ValueError:
print("The requested value is not in the expected format.")
# remove salts
return Chem.CanonSmiles(self.largest_mol(smi))

Expand Down
4 changes: 3 additions & 1 deletion mdagent/utils/general_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ def find_file_path(file_name: str, exact_match: bool = True):
if (exact_match and filename == file_name) or (
not exact_match and file_name in filename
):
return os.path.join(dirpath, filename)
path_full = os.path.join(dirpath, filename)
# make sure its absolute
return os.path.abspath(path_full)

return None
9 changes: 5 additions & 4 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,12 @@ def test_init_path_registry(path_registry_with_mocked_fs):

def test_find_file_path():
file_name = "test_utils.py"
file_path_current = os.path.abspath(file_name)
# current directory won't include folders
cwd = os.getcwd()
file_path_current = os.path.join(cwd, "tests", file_name)
file_path_test = find_file_path(file_name, exact_match=True)
assert file_path_current == file_path_test

file_name_short = file_name[-4]
file_path_current_short = os.path.abspath(file_name_short)
file_name_short = "test_util"
file_path_test_short = find_file_path(file_name_short, exact_match=False)
assert file_path_current_short == file_path_test_short
assert file_path_current == file_path_test_short

0 comments on commit e05111c

Please sign in to comment.