Skip to content

Commit

Permalink
update unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasGensollen committed Nov 8, 2024
1 parent 6325918 commit cfe3bfa
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 24 deletions.
10 changes: 8 additions & 2 deletions test/unittests/pipelines/pet/test_pet_volume_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ def test_pet_volume_info_loading(tmp_path):
from clinica.pipelines.pet.volume.pipeline import PETVolume

bids = build_bids_directory(tmp_path / "bids", {"sub-01": ["ses-M00"]})
pipeline = PETVolume(bids_directory=str(bids))
caps = tmp_path / "caps"
pipeline = PETVolume(
bids_directory=str(bids), caps_directory=str(caps), group_label="test"
)

assert pipeline.info == {
"id": "aramislab/pet-volume",
Expand All @@ -29,7 +32,10 @@ def test_pet_volume_dependencies(tmp_path, mocker):
return_value=Version("12.7219"),
)
bids = build_bids_directory(tmp_path / "bids", {"sub-01": ["ses-M00"]})
pipeline = PETVolume(bids_directory=str(bids))
caps = tmp_path / "caps"
pipeline = PETVolume(
bids_directory=str(bids), caps_directory=str(caps), group_label="test"
)

assert pipeline.dependencies == [
SoftwareDependency(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def test_t1_volume_create_dartel_info_loading(tmp_path):
"subjects": {"sub-01": ["ses-M000"]},
},
)
pipeline = T1VolumeCreateDartel(caps_directory=str(caps))
pipeline = T1VolumeCreateDartel(caps_directory=str(caps), group_label="test")

assert pipeline.info == {
"id": "aramislab/t1-volume-create-dartel",
Expand Down Expand Up @@ -45,7 +45,7 @@ def test_t1_volume_create_dartel_dependencies(tmp_path, mocker):
"subjects": {"sub-01": ["ses-M000"]},
},
)
pipeline = T1VolumeCreateDartel(caps_directory=str(caps))
pipeline = T1VolumeCreateDartel(caps_directory=str(caps), group_label="test")

assert pipeline.dependencies == [
SoftwareDependency(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def test_t1_volume_dartel2mni_info_loading(tmp_path):
tmp_path / "caps",
{"pipelines": ["t1-volume-dartel2mni"], "subjects": {"sub-01": ["ses-M000"]}},
)
pipeline = T1VolumeDartel2MNI(caps_directory=str(caps))
pipeline = T1VolumeDartel2MNI(caps_directory=str(caps), group_label="test")

assert pipeline.info == {
"id": "aramislab/t1-volume-dartel2mni",
Expand Down Expand Up @@ -39,7 +39,7 @@ def test_t1_volume_dartel2mni_dependencies(tmp_path, mocker):
tmp_path / "caps",
{"pipelines": ["t1-volume-dartel2mni"], "subjects": {"sub-01": ["ses-M000"]}},
)
pipeline = T1VolumeDartel2MNI(caps_directory=str(caps))
pipeline = T1VolumeDartel2MNI(caps_directory=str(caps), group_label="test")

assert pipeline.dependencies == [
SoftwareDependency(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def test_t1_volume_parcellation_info_loading(tmp_path):
tmp_path / "caps",
{"pipelines": ["t1-volume-parcellation"], "subjects": {"sub-01": ["ses-M000"]}},
)
pipeline = T1VolumeParcellation(caps_directory=str(caps))
pipeline = T1VolumeParcellation(caps_directory=str(caps), group_label="test")

assert pipeline.info == {
"id": "aramislab/t1-volume-parcellation",
Expand All @@ -31,6 +31,6 @@ def test_t1_volume_parcellation_dependencies(tmp_path):
tmp_path / "caps",
{"pipelines": ["t1-volume-parcellation"], "subjects": {"sub-01": ["ses-M000"]}},
)
pipeline = T1VolumeParcellation(caps_directory=str(caps))
pipeline = T1VolumeParcellation(caps_directory=str(caps), group_label="test")

assert pipeline.dependencies == []
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def test_t1_volume_register_dartel_info_loading(tmp_path):
"subjects": {"sub-01": ["ses-M000"]},
},
)
pipeline = T1VolumeRegisterDartel(caps_directory=str(caps))
pipeline = T1VolumeRegisterDartel(caps_directory=str(caps), group_label="test")

assert pipeline.info == {
"id": "aramislab/t1-volume-register-dartel",
Expand Down Expand Up @@ -45,7 +45,7 @@ def test_t1_volume_register_dartel_dependencies(tmp_path, mocker):
"subjects": {"sub-01": ["ses-M000"]},
},
)
pipeline = T1VolumeRegisterDartel(caps_directory=str(caps))
pipeline = T1VolumeRegisterDartel(caps_directory=str(caps), group_label="test")

assert pipeline.dependencies == [
SoftwareDependency(
Expand Down
37 changes: 23 additions & 14 deletions test/unittests/utils/test_group.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import re

import pytest


Expand All @@ -6,9 +8,11 @@
["A", "a1", "123", "0xY2", "mygroup"],
)
def test_check_group_label(label):
from clinica.utils.group import check_group_label
from clinica.utils.group import GroupLabel

label = GroupLabel(label)

assert check_group_label(label) is None
assert label == label


@pytest.mark.parametrize(
Expand All @@ -26,33 +30,37 @@ def test_check_group_label(label):
],
)
def test_check_group_label_errors(label):
from clinica.utils.group import check_group_label
from clinica.utils.group import GroupLabel

with pytest.raises(
ValueError,
match="Not valid group_label value",
match=re.escape(
f"Group label '{label}' is not a valid group label: it must be composed only by letters and/or numbers."
),
):
check_group_label(label)
GroupLabel(label)


@pytest.mark.parametrize("folder_name", ["group-AD", "group-foo", "group-foo12bar"])
def test_check_group_dir(tmp_path, folder_name):
from clinica.utils.group import _check_group_dir
def test_group_id(folder_name: str):
from clinica.utils.group import GroupID

assert _check_group_dir(tmp_path / folder_name) is None
assert GroupID(folder_name) == folder_name


@pytest.mark.parametrize(
"folder_name", ["foo", "foo-group", "groupfoo12bar", "foo.txt"]
"folder_name", ["foo bar", "", "foo$", "foo-group", "group_foo_12_bar", "foo.txt"]
)
def test_check_group_dir_errors(tmp_path, folder_name):
from clinica.utils.group import _check_group_dir
def test_group_id_errors(folder_name):
from clinica.utils.group import GroupID

with pytest.raises(
ValueError,
match="Group directory",
match=re.escape(
f"Group ID '{folder_name}' is not a valid group ID: it must start with 'group-'."
),
):
_check_group_dir(tmp_path / folder_name)
GroupID(folder_name)


def test_extract_group_ids_empty(tmp_path):
Expand Down Expand Up @@ -90,6 +98,7 @@ def test_extract_group_ids_errors(tmp_path):
(groups_folder / group_id).mkdir()

with pytest.raises(
ValueError, match=f"Group directory {groups_folder / 'foo'} is not valid"
ValueError,
match="Group ID 'foo' is not a valid group ID: it must start with 'group-'.",
):
extract_group_ids(tmp_path)

0 comments on commit cfe3bfa

Please sign in to comment.