Skip to content

Commit

Permalink
add unit tests for anat pipeline (might change to more general later...)
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasGensollen committed Jul 11, 2024
1 parent 124a61f commit 2fb77c9
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions test/unittests/pipelines/t1_linear/test_anat_linear_pipeline.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import re

import pytest


def test_anat_linear_pipeline_no_input_error(tmp_path):
from clinica.pipelines.t1_linear.anat_linear_pipeline import AnatLinear

with pytest.raises(
RuntimeError,
match=(
"The AnatLinear pipeline does not contain BIDS "
"nor CAPS directory at the initialization."
),
):
AnatLinear()


def test_anat_linear_pipeline_single_bids_input_error(tmp_path):
from clinica.pipelines.t1_linear.anat_linear_pipeline import AnatLinear
from clinica.utils.exceptions import ClinicaBIDSError

with pytest.raises(
ClinicaBIDSError,
match=re.escape(
f"The BIDS directory ({tmp_path}) you provided "
"is missing a dataset_description.json file."
),
):
AnatLinear(bids_directory=str(tmp_path))


def test_anat_linear_pipeline_single_caps_input_error(tmp_path):
from clinica.pipelines.t1_linear.anat_linear_pipeline import AnatLinear
from clinica.utils.exceptions import ClinicaCAPSError

with pytest.raises(
ClinicaCAPSError,
match=re.escape(
f"The CAPS directory ({tmp_path}) you provided "
"is missing a dataset_description.json file."
),
):
AnatLinear(caps_directory=str(tmp_path))


def test_anat_linear_pipeline_write_caps_dataset_description(tmp_path):
from clinica.pipelines.t1_linear.anat_linear_pipeline import AnatLinear
from clinica.utils.caps import CAPSDatasetDescription, DatasetType

bids = tmp_path / "bids"
caps = tmp_path / "caps"
bids.mkdir()
caps.mkdir()
(bids / "dataset_description.json").touch()
(bids / "sub-01").mkdir()

AnatLinear(bids_directory=str(bids), caps_directory=str(caps))

files = [f for f in caps.iterdir()]
assert len(files) == 1

desc = CAPSDatasetDescription.from_file(caps / "dataset_description.json")

assert desc.name == "AnatLinear"
assert desc.bids_version == "1.7.0"
assert desc.caps_version == "1.0.0"
assert desc.dataset_type == DatasetType.DERIVATIVE

0 comments on commit 2fb77c9

Please sign in to comment.