Skip to content

Commit

Permalink
updating tests for new error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
atravitz committed Jan 29, 2025
1 parent 6b103cf commit 6bffeb4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 22 deletions.
3 changes: 1 addition & 2 deletions openfecli/commands/gather.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,7 @@ def legacy_get_type(res_fn:os.PathLike|str)->Literal['vacuum','solvent','complex
return 'complex'

def _generate_bad_legs_error_message(bad_legs:list[tuple[set[str], tuple[str]]])->str:
"""Attempt to determine whether the legs belong to a RHFE or RBFE calculation
and generate an error message accordingly.
"""Format output describing failed RBFE or RHFE legs.
Parameters
----------
Expand Down
25 changes: 5 additions & 20 deletions openfecli/tests/commands/test_gather.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,21 +179,6 @@ def test_gather(request, data_fixture, report):
actual_lines = set(result.stdout_bytes.split(b'\n'))
assert set(expected.split(b'\n')) == actual_lines


@pytest.mark.parametrize('include', ['complex', 'solvent', 'vacuum'])
def test_generate_bad_legs_error_message(include):
expected = {
'complex': ("Assuming this is an RBFE", "missing {'solvent'}"),
'vacuum': ("Assuming this is an RHFE", "missing {'solvent'}"),
'solvent': ("whether this edge belongs to an RBFE or an RHFE",
"'complex'", "'solvent'"),
}[include]
set_vals = {include}
ligpair = ('lig1', 'lig2')
msg = _generate_bad_legs_error_message([(set_vals, ligpair)])
for string in expected:
assert string in msg

class TestGatherFailedEdges:
@pytest.fixture()
def results_dir_serial_missing_legs(self, tmpdir)->str:
Expand All @@ -217,11 +202,11 @@ def test_missing_leg_error(self, results_dir_serial_missing_legs: str):

assert result.exit_code == 1
assert isinstance(result.exception, RuntimeError)
assert "Unable to determine" in str(result.exception)
assert "'lig_ejm_31'" in str(result.exception)
assert "'lig_ejm_42'" in str(result.exception)
assert "'lig_ejm_46'" in str(result.exception)
assert "'lig_jmc_28'" in str(result.exception)
assert "Some edge(s) are missing runs" in str(result.exception)
assert "('lig_ejm_31', 'lig_ejm_42'): solvent" in str(result.exception)
assert "('lig_ejm_46', 'lig_jmc_28'): complex" in str(result.exception)
assert "using the --allow-partial flag" in str(result.exception)


def test_missing_leg_allow_partial(self, results_dir_serial_missing_legs: str):
runner = CliRunner()
Expand Down

0 comments on commit 6bffeb4

Please sign in to comment.