From 33245e6d5facfa1679190cb540d2c19999bde87d Mon Sep 17 00:00:00 2001 From: NicolasGensollen Date: Thu, 28 Nov 2024 14:51:25 +0100 Subject: [PATCH] add more tests --- .../t1_linear/test_anat_linear_pipeline.py | 120 ++++++++++++++++++ 1 file changed, 120 insertions(+) diff --git a/test/unittests/pipelines/t1_linear/test_anat_linear_pipeline.py b/test/unittests/pipelines/t1_linear/test_anat_linear_pipeline.py index 833b89002..a1068b085 100644 --- a/test/unittests/pipelines/t1_linear/test_anat_linear_pipeline.py +++ b/test/unittests/pipelines/t1_linear/test_anat_linear_pipeline.py @@ -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()