Skip to content

Commit 2f95eff

Browse files
committed
Update tests for bold ref template
1 parent 05f0b3e commit 2f95eff

2 files changed

Lines changed: 39 additions & 19 deletions

File tree

tests/unit/bids/test_longitudinal_functional.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ def _anat_row(
5959
sub: str,
6060
ses: str,
6161
suffix: str,
62+
res: str | None = None,
6263
desc: str | None = None,
6364
ext: str = ".nii.gz",
6465
extra: list[dict[str, str]] | None = None,
@@ -73,6 +74,7 @@ def _anat_row(
7374
"sub": sub,
7475
"ses": ses,
7576
"space": None,
77+
"res": res,
7678
"desc": desc,
7779
"root": "/data",
7880
"path": path,
@@ -143,7 +145,7 @@ def test_resolves_single_regressor(self, tmp_path: Path) -> None:
143145
),
144146
)
145147
tpl_df = _df(
146-
_anat_row(sub="01", ses="longitudinal", suffix="T1w"),
148+
_anat_row(sub="01", ses="longitudinal", res="bold", suffix="T1w"),
147149
_anat_row(
148150
sub="01",
149151
ses="longitudinal",
@@ -218,7 +220,7 @@ def test_resolves_multiple_regressors(self, tmp_path: Path) -> None:
218220
),
219221
)
220222
tpl_df = _df(
221-
_anat_row(sub="01", ses="longitudinal", suffix="T1w"),
223+
_anat_row(sub="01", ses="longitudinal", res="bold", suffix="T1w"),
222224
_anat_row(
223225
sub="01",
224226
ses="longitudinal",
@@ -275,7 +277,7 @@ def test_missing_regressor_raises(self, tmp_path: Path) -> None:
275277
),
276278
)
277279
tpl_df = _df(
278-
_anat_row(sub="01", ses="longitudinal", suffix="T1w"),
280+
_anat_row(sub="01", ses="longitudinal", res="bold", suffix="T1w"),
279281
_anat_row(
280282
sub="01",
281283
ses="longitudinal",
@@ -328,7 +330,7 @@ def test_bold_mask_mandatory(self, tmp_path: Path) -> None:
328330
),
329331
)
330332
tpl_df = _df(
331-
_anat_row(sub="01", ses="longitudinal", suffix="T1w"),
333+
_anat_row(sub="01", ses="longitudinal", res="bold", suffix="T1w"),
332334
_anat_row(
333335
sub="01",
334336
ses="longitudinal",

tests/unit/bids/test_longitudinal_template.py

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def _df(*rows: tuple) -> pl.DataFrame:
3535
return pl.DataFrame(dict(zip(_SCHEMA, zip(*rows, strict=True), strict=True)))
3636

3737

38-
def _brain_row(sub: str, ses: str, space: str | None = None) -> tuple:
38+
def _anat_row(sub: str, ses: str, space: str | None = None) -> tuple:
3939
space_part = f"_space-{space}" if space else ""
4040
path = (
4141
f"sub-{sub}/ses-{ses}/anat/"
@@ -56,16 +56,25 @@ def _brain_row(sub: str, ses: str, space: str | None = None) -> tuple:
5656
)
5757

5858

59+
def _func_row(sub: str, ses: str, task: str = "rest") -> tuple:
60+
path = f"sub-{sub}/ses-{ses}/func/sub-{sub}_ses-{ses}_task-{task}_bold.nii.gz"
61+
return ("func", "bold", ".nii.gz", sub, ses, None, task, None, None, "/data", path)
62+
63+
5964
class TestDiscoverTemplateInputs:
6065
"""Tests for :func:`discover_template_inputs`."""
6166

6267
def test_groups_by_subject(self) -> None:
6368
"""Multi-session subjects yield one TemplateInputs each."""
6469
df = _df(
65-
_brain_row("01", "baseline"),
66-
_brain_row("01", "vis2"),
67-
_brain_row("02", "baseline"),
68-
_brain_row("02", "vis2"),
70+
_anat_row("01", "baseline"),
71+
_anat_row("01", "vis2"),
72+
_anat_row("02", "baseline"),
73+
_anat_row("02", "vis2"),
74+
_func_row("01", "baseline"),
75+
_func_row("01", "vis2"),
76+
_func_row("02", "baseline"),
77+
_func_row("02", "vis2"),
6978
)
7079
inputs, skipped = discover_template_inputs(df)
7180
assert {ti.sub for ti in inputs} == {"01", "02"}
@@ -77,9 +86,12 @@ def test_groups_by_subject(self) -> None:
7786
def test_reports_single_session_subject(self) -> None:
7887
"""Single-session subjects are reported separately (bug #19)."""
7988
df = _df(
80-
_brain_row("01", "baseline"),
81-
_brain_row("01", "vis2"),
82-
_brain_row("02", "baseline"),
89+
_anat_row("01", "baseline"),
90+
_anat_row("01", "vis2"),
91+
_anat_row("02", "baseline"),
92+
_func_row("01", "baseline"),
93+
_func_row("01", "vis2"),
94+
_func_row("02", "baseline"),
8395
)
8496
inputs, skipped = discover_template_inputs(df)
8597
assert [ti.sub for ti in inputs] == ["01"]
@@ -88,9 +100,12 @@ def test_reports_single_session_subject(self) -> None:
88100
def test_excludes_existing_longitudinal(self) -> None:
89101
"""Pre-existing longitudinal templates are not re-included as inputs."""
90102
df = _df(
91-
_brain_row("01", "baseline"),
92-
_brain_row("01", "vis2"),
93-
_brain_row("01", "longitudinal"),
103+
_anat_row("01", "baseline"),
104+
_anat_row("01", "vis2"),
105+
_anat_row("01", "longitudinal"),
106+
_func_row("01", "baseline"),
107+
_func_row("01", "vis2"),
108+
_func_row("01", "longitudinal"),
94109
)
95110
inputs, skipped = discover_template_inputs(df)
96111
assert len(inputs) == 1
@@ -111,10 +126,10 @@ def test_excludes_mni_registered_brains(self) -> None:
111126
duplicate LTA filenames in the mri_robust_template invocation.
112127
"""
113128
df = _df(
114-
_brain_row("01", "test"),
115-
_brain_row("01", "test", space="MNI152NLin6Asym"),
116-
_brain_row("01", "retest"),
117-
_brain_row("01", "retest", space="MNI152NLin6Asym"),
129+
_anat_row("01", "test"),
130+
_anat_row("01", "test", space="MNI152NLin6Asym"),
131+
_anat_row("01", "retest"),
132+
_anat_row("01", "retest", space="MNI152NLin6Asym"),
118133
)
119134
inputs, skipped = discover_template_inputs(df)
120135
assert len(inputs) == 1
@@ -131,13 +146,16 @@ def test_writes_template_and_xfms(self, tmp_path: Path) -> None:
131146
"""Template + per-session xfms land at the expected BIDS paths."""
132147
template_src = tmp_path / "src_template.nii.gz"
133148
template_src.write_bytes(b"\x00")
149+
template_bold_src = tmp_path / "src_bold_template.nii.gz"
150+
template_bold_src.write_bytes(b"\x00")
134151
xfm_baseline = tmp_path / "xfm_baseline.txt"
135152
xfm_baseline.write_text("baseline")
136153
xfm_vis2 = tmp_path / "xfm_vis2.txt"
137154
xfm_vis2.write_text("vis2")
138155

139156
outputs = LongitudinalTemplateOutputs(
140157
template=template_src,
158+
bold_template=template_bold_src,
141159
sessions=["baseline", "vis2"],
142160
transforms=[xfm_baseline, xfm_vis2],
143161
)

0 commit comments

Comments
 (0)