Skip to content

Commit

Permalink
fix catching exceptions in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
grzanka committed Mar 12, 2024
1 parent 0e61f4a commit 6efa41e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
2 changes: 1 addition & 1 deletion tests/test_call_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def test_call_cmd_option(option_name: str):
with pytest.raises(SystemExit) as e:
logger.info("Catching {%s}", e)
run.main([f'--{option_name}'])
assert e.value == 0
assert e.value == 0


@pytest.mark.smoke
Expand Down
11 changes: 5 additions & 6 deletions tests/test_mcscripter.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,17 @@ def default_config_path() -> Path:
def test_call_cmd_option(option_name: str):
"""Description needed."""
with pytest.raises(SystemExit) as e:
logger.info("Catching {:s}".format(str(e)))
logger.info("Catching %s", e)
pymchelper.utils.mcscripter.main(['--' + option_name])
assert e.value == 0
assert e.value == 0


def test_call_cmd_no_option():
"""Description needed."""
with pytest.raises(SystemExit) as e:
logger.info("Catching {:s}".format(str(e)))
logger.info("Catching %s", e)
pymchelper.utils.mcscripter.main([])
assert e.value == 2
assert e.value == 2


@pytest.mark.parametrize("config_path", Configs.list(), ids=Configs.names())
Expand Down Expand Up @@ -106,8 +106,7 @@ def test_writing_template(config_path: Path, tmp_path: Path):


@pytest.mark.parametrize("config_path", Configs.list(), ids=Configs.names())
def test_execution(config_path: Path, monkeypatch: pytest.MonkeyPatch,
tmp_path: Path):
def test_execution(config_path: Path, monkeypatch: pytest.MonkeyPatch, tmp_path: Path):
"""Description needed."""
logger.debug(f"current working directory {os.getcwd()}")
full_path_to_config = config_path.resolve()
Expand Down
10 changes: 4 additions & 6 deletions tests/test_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def test_call_cmd_no_option():
with pytest.raises(SystemExit) as e:
logger.info("Catching: %s", e)
pymchelper.utils.radiotherapy.plan.main([])
assert e.value == 2
assert e.value == 2


@pytest.mark.parametrize("option_name", ["version", "help"])
Expand All @@ -33,16 +33,14 @@ def test_call_cmd_option(option_name: str):
with pytest.raises(SystemExit) as e:
logger.info("Catching: %s", e)
pymchelper.utils.radiotherapy.plan.main([])
assert e.value == 0
assert e.value == 0


@pytest.mark.parametrize("option_name", ["", "flip", "xflip", "yflip"])
@pytest.mark.parametrize("input_file_path", input_files.values(), ids=input_files.keys())
@pytest.mark.parametrize("beam_model_path", [beam_model_path, None], ids=[beam_model_path.stem, "no_beam_model"])
def test_generate_plan(input_file_path: Path, beam_model_path: Union[Path, None],
monkeypatch: pytest.MonkeyPatch,
tmp_path: Path, capsys: pytest.CaptureFixture,
option_name: str):
def test_generate_plan(input_file_path: Path, beam_model_path: Union[Path, None], monkeypatch: pytest.MonkeyPatch,
tmp_path: Path, capsys: pytest.CaptureFixture, option_name: str):
"""Test plan loading with and without beam model."""
expected_output_file_path = Path(output_file)

Expand Down

0 comments on commit 6efa41e

Please sign in to comment.