Skip to content

Commit 94e2dea

Browse files
committed
ENH: minor fix and add test
1 parent 61e70a0 commit 94e2dea

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

fmriprep/interfaces/reports.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def _generate_segment(self):
154154
pet_series = self.inputs.pet or []
155155

156156
counts = Counter(
157-
BIDS_NAME.search(series).groupdict().get('task_id', 'task-<none>')[5:]
157+
(BIDS_NAME.search(series).groupdict().get('task_id') or 'task-<none>')[5:]
158158
for series in pet_series
159159
)
160160

fmriprep/interfaces/tests/test_reports.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,25 @@
5050
)
5151
def test_get_world_pedir(tmpdir, orientation, pe_dir, expected):
5252
assert get_world_pedir(orientation, pe_dir) == expected
53+
54+
55+
def test_subject_summary_handles_missing_task(tmp_path):
56+
from ..reports import SubjectSummary
57+
58+
t1w = tmp_path / 'sub-01_T1w.nii.gz'
59+
t1w.write_text('')
60+
pet1 = tmp_path / 'sub-01_task-rest_run-01_pet.nii.gz'
61+
pet1.write_text('')
62+
pet2 = tmp_path / 'sub-01_run-01_pet.nii.gz'
63+
pet2.write_text('')
64+
65+
summary = SubjectSummary(
66+
t1w=[str(t1w)],
67+
pet=[str(pet1), str(pet2)],
68+
std_spaces=[],
69+
nstd_spaces=[],
70+
)
71+
72+
segment = summary._generate_segment()
73+
assert 'Task: rest (1 run)' in segment
74+
assert 'Task: <none> (1 run)' in segment

0 commit comments

Comments
 (0)