-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
reorganized tool-existing related tests
- Loading branch information
Showing
4 changed files
with
108 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import os | ||
|
||
import pytest | ||
|
||
from mdagent.tools.base_tools.preprocess_tools import CleaningTools, get_pdb | ||
from mdagent.utils import PathRegistry | ||
|
||
# Test functions in preprocess tools | ||
|
||
|
||
@pytest.fixture | ||
def get_registry(): | ||
return PathRegistry() | ||
|
||
|
||
@pytest.fixture | ||
def path_to_cif(): | ||
# Save original working directory | ||
original_cwd = os.getcwd() | ||
|
||
# Change current working directory to the directory where the CIF file is located | ||
tests_dir = os.path.dirname(os.path.abspath(__file__)) | ||
os.chdir(tests_dir) | ||
|
||
# Yield the filename only | ||
filename_only = "3pqr.cif" | ||
yield filename_only | ||
|
||
# Restore original working directory after the test is done | ||
os.chdir(original_cwd) | ||
|
||
|
||
# test get pdb file | ||
@pytest.fixture | ||
def fibronectin(): | ||
return "fibronectin pdb" | ||
|
||
|
||
def test_getpdb(fibronectin, get_registry): | ||
name = get_pdb(fibronectin, get_registry) | ||
assert name.endswith(".pdb") | ||
|
||
|
||
# test cleaning functions | ||
@pytest.fixture | ||
def cleaning_fxns(): | ||
return CleaningTools() | ||
|
||
|
||
def test_add_hydrogens_and_remove_water(path_to_cif, cleaning_fxns, get_registry): | ||
result = cleaning_fxns._add_hydrogens_and_remove_water(path_to_cif, get_registry) | ||
assert "Cleaned File" in result # just want to make sur the function ran |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from unittest.mock import mock_open, patch | ||
|
||
import pytest | ||
|
||
from mdagent.tools.base_tools.simulation_tools import SimulationFunctions | ||
|
||
# Test functions in simulation tools | ||
|
||
|
||
@pytest.fixture | ||
def sim_fxns(): | ||
return SimulationFunctions() | ||
|
||
|
||
@patch("os.path.exists") | ||
@patch("os.listdir") | ||
def test_extract_parameters_path(mock_listdir, mock_exists, sim_fxns): | ||
# Test when parameters.json exists | ||
mock_exists.return_value = True | ||
assert sim_fxns._extract_parameters_path() == "simulation_parameters_summary.json" | ||
mock_exists.assert_called_once_with("simulation_parameters_summary.json") | ||
mock_exists.reset_mock() # Reset the mock for the next scenario | ||
|
||
# Test when parameters.json does not exist, but some_parameters.json does | ||
mock_exists.return_value = False | ||
mock_listdir.return_value = ["some_parameters.json", "other_file.txt"] | ||
assert sim_fxns._extract_parameters_path() == "some_parameters.json" | ||
|
||
# Test when no appropriate file exists | ||
mock_listdir.return_value = ["other_file.json", "other_file.txt"] | ||
with pytest.raises(ValueError) as e: | ||
sim_fxns._extract_parameters_path() | ||
assert str(e.value) == "No parameters.json file found in directory." | ||
|
||
|
||
@patch( | ||
"builtins.open", | ||
new_callable=mock_open, | ||
read_data='{"param1": "value1", "param2": "value2"}', | ||
) | ||
@patch("json.load") | ||
def test_setup_simulation_from_json(mock_json_load, mock_file_open, sim_fxns): | ||
# Define the mock behavior for json.load | ||
mock_json_load.return_value = {"param1": "value1", "param2": "value2"} | ||
params = sim_fxns._setup_simulation_from_json("test_file.json") | ||
mock_file_open.assert_called_once_with("test_file.json", "r") | ||
mock_json_load.assert_called_once() | ||
assert params == {"param1": "value1", "param2": "value2"} |
Empty file.