Skip to content

Commit

Permalink
add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasGensollen committed Nov 28, 2024
1 parent 388b194 commit 33245e6
Showing 1 changed file with 120 additions and 0 deletions.
120 changes: 120 additions & 0 deletions test/unittests/pipelines/t1_linear/test_anat_linear_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,3 +244,123 @@ def test_anat_linear_get_processed_visits_cropped_images(
# pipeline always find an empty list of processed images because we want cropped images
# and the CAPS folder only contains un-cropped images
assert pipeline.get_processed_images() == []


@pytest.mark.parametrize(
"config,remaining_subjects,remaining_sessions",
[
({}, ["sub-01", "sub-01", "sub-02"], ["ses-M000", "ses-M006", "ses-M000"]),
(
{
"pipelines": {"t1_linear": {"uncropped_image": False}},
"subjects": {"sub-01": ["ses-M006"]},
},
["sub-01", "sub-02"],
["ses-M000", "ses-M000"],
),
(
{
"pipelines": {"t1_linear": {"uncropped_image": False}},
"subjects": {"sub-01": ["ses-M000", "ses-M006"]},
},
["sub-02"],
["ses-M000"],
),
(
{
"pipelines": {"t1_linear": {"uncropped_image": False}},
"subjects": {
"sub-01": ["ses-M000", "ses-M006"],
"sub-02": ["ses-M000"],
},
},
[],
[],
),
],
)
def test_determine_subject_and_session_to_process(
tmp_path, mocker, config, remaining_subjects, remaining_sessions
):
from clinica.pipelines.t1_linear.anat_linear_pipeline import AnatLinear

mocker.patch(
"clinica.utils.check_dependency._get_ants_version",
return_value=Version("2.2.1"),
)
bids = build_bids_directory(
tmp_path / "bids", {"sub-01": ["ses-M000", "ses-M006"], "sub-02": ["ses-M000"]}
)
caps = build_caps_directory(tmp_path / "caps", config)
pipeline = AnatLinear(
bids_directory=str(bids),
caps_directory=str(caps),
parameters={"uncropped_image": False},
)
pipeline.determine_subject_and_session_to_process()
pipeline2 = AnatLinear(
bids_directory=str(bids),
caps_directory=str(caps),
parameters={"uncropped_image": True},
)
pipeline2.determine_subject_and_session_to_process()

assert pipeline.subjects == remaining_subjects
assert pipeline.sessions == remaining_sessions
assert pipeline2.subjects == ["sub-01", "sub-01", "sub-02"]
assert pipeline2.sessions == ["ses-M000", "ses-M006", "ses-M000"]


@pytest.mark.parametrize(
"configuration,expected_message",
[
(
{
"pipelines": {"t1_linear": {"uncropped_image": False}},
"subjects": {
"sub-01": ["ses-M000", "ses-M006"],
"sub-02": ["ses-M000"],
},
},
(
"Clinica found already processed images for 3 visit(s):"
"\n- sub-01 ses-M000\n- sub-01 ses-M006\n- sub-02 ses-M000"
"\nThose visits will be ignored by Clinica."
),
),
(
{
"pipelines": {"t1_linear": {"uncropped_image": False}},
"subjects": {"sub-01": ["ses-M000", "ses-M006"]},
},
(
"Clinica found already processed images for 2 visit(s):"
"\n- sub-01 ses-M000\n- sub-01 ses-M006"
"\nThose visits will be ignored by Clinica."
),
),
],
)
def test_determine_subject_and_session_to_process_warning(
tmp_path, mocker, configuration, expected_message
):
from clinica.pipelines.t1_linear.anat_linear_pipeline import AnatLinear

mocker.patch(
"clinica.utils.check_dependency._get_ants_version",
return_value=Version("2.2.1"),
)
bids = build_bids_directory(
tmp_path / "bids", {"sub-01": ["ses-M000", "ses-M006"], "sub-02": ["ses-M000"]}
)
caps = build_caps_directory(tmp_path / "caps", configuration)
pipeline = AnatLinear(
bids_directory=str(bids),
caps_directory=str(caps),
parameters={"uncropped_image": False},
)
with pytest.warns(
UserWarning,
match=re.escape(f"In the provided CAPS folder {caps}, {expected_message}"),
):
pipeline.determine_subject_and_session_to_process()

0 comments on commit 33245e6

Please sign in to comment.