Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issues in tests (also after accidental commit to the master) #720

Merged
merged 4 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pymchelper/estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def average_with_nan(estimator_list, error_estimate=ErrorEstimate.stderr):
if not estimator_list:
return None
result = copy.deepcopy(estimator_list[0])
result.number_of_primaries = sum([estimator.number_of_primaries for estimator in estimator_list])
result.number_of_primaries = sum(estimator.number_of_primaries for estimator in estimator_list)
for page_no, page in enumerate(result.pages):
page.data_raw = np.nanmean([estimator.pages[page_no].data_raw for estimator in estimator_list], axis=0)
result.file_counter = len(estimator_list)
Expand Down
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.args[0] == 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.args[0] == 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.args[0] == 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
12 changes: 5 additions & 7 deletions tests/test_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,23 @@ 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.args[0] == 2


@pytest.mark.parametrize("option_name", ["version", "help"])
def test_call_cmd_option(option_name: str):
"""Test calling pymchelper with no options."""
with pytest.raises(SystemExit) as e:
logger.info("Catching: %s", e)
pymchelper.utils.radiotherapy.plan.main([])
assert e.value == 0
pymchelper.utils.radiotherapy.plan.main(['--' + option_name])
assert e.value.args[0] == 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