Skip to content

Commit 2c878d1

Browse files
committed
testing arg errors
1 parent 9dc23b6 commit 2c878d1

2 files changed

Lines changed: 28 additions & 6 deletions

File tree

src/openfecli/commands/plan_rbfe_network.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,9 @@ def plan_rbfe_network(
189189
small_molecules = MOL_DIR.get(molecules)
190190
write("\t\tSmall Molecules: " + " ".join([str(sm) for sm in small_molecules]))
191191
if protein and protein_membrane:
192-
raise ValueError("Only --protein (-p) or --protein-membrane may be provided, not both.")
192+
raise click.UsageError(
193+
"Only --protein (-p) or --protein-membrane may be provided, not both."
194+
)
193195
elif protein:
194196
protein_component = PROTEIN.get(protein)
195197
write("\t\tProteinComponent: " + str(protein_component))

src/openfecli/tests/commands/test_plan_rbfe_network.py

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from importlib import resources
33
from unittest import mock
44

5+
import gufe
56
import numpy as np
67
import pytest
78
from click.testing import CliRunner
@@ -465,13 +466,32 @@ def test_custom_yaml_plan_radial_smoke_test(custom_yaml_radial, eg5_files, tmp_p
465466
assert result.exit_code == 0
466467

467468

468-
def test_plan_rbfe_network_invalid_membrane(eg5_files):
469+
def test_plan_rbfe_invalid_membrane(eg5_files):
469470
"""eg5_protein has box vectors but no membrane. ProteinMembraneComponent validation should catch this."""
470471

471-
runner = CliRunner()
472472
args = ["--protein-membrane", eg5_files[0], "-M", eg5_files[1]]
473+
runner = CliRunner()
474+
with pytest.raises(
475+
gufe.components.errors.ComponentValidationError,
476+
match="This usually indicates missing solvent or incorrect box vectors",
477+
):
478+
_ = runner.invoke(plan_rbfe_network, args, catch_exceptions=False)
473479

474-
with runner.isolated_filesystem():
475-
result = runner.invoke(plan_rbfe_network, args)
476480

477-
assert result.exit_code == 1
481+
def test_plan_rbfe_missing_protein_args(eg5_files):
482+
"""eg5_protein has box vectors but no membrane. ProteinMembraneComponent validation should catch this."""
483+
args = ["-M", eg5_files[1]]
484+
485+
runner = CliRunner(catch_exceptions=False)
486+
result = runner.invoke(plan_rbfe_network, args)
487+
assert result.exit_code == 2
488+
assert "Either --protein or --protein-membrane must be provided." in result.stderr
489+
490+
491+
def test_plan_rbfe_too_many_protein_error(eg5_files):
492+
"""eg5_protein has box vectors but no membrane. ProteinMembraneComponent validation should catch this."""
493+
args = ["-M", eg5_files[1], "--protein-membrane", eg5_files[0], "-p", eg5_files[0]]
494+
495+
runner = CliRunner(catch_exceptions=False)
496+
result = runner.invoke(plan_rbfe_network, args)
497+
assert "Only --protein (-p) or --protein-membrane may be provided, not both." in result.stderr

0 commit comments

Comments
 (0)