Skip to content

Commit c4e7694

Browse files
committed
Get tests running.
1 parent 39deaa4 commit c4e7694

File tree

2 files changed

+119
-20
lines changed

2 files changed

+119
-20
lines changed

cubids/tests/test_apply.py

Lines changed: 118 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
},
4343
],
4444
}
45-
4645
bidsuri_longitudinal_intendedfor = {
4746
'01': [
4847
{
@@ -81,11 +80,85 @@
8180
},
8281
],
8382
}
83+
relpath_cs_intendedfor = {
84+
'01': [
85+
{
86+
'anat': [{'suffix': 'T1w', 'metadata': {'EchoTime': 1}}],
87+
'fmap': [
88+
{
89+
'dir': 'AP',
90+
'suffix': 'epi',
91+
'metadata': {
92+
'IntendedFor': [
93+
'dwi/sub-01_dir-AP_run-01_dwi.nii.gz'
94+
]
95+
}
96+
},
97+
{
98+
'dir': 'PA',
99+
'suffix': 'epi',
100+
'metadata': {
101+
'IntendedFor': [
102+
'dwi/sub-01_dir-AP_run-01_dwi.nii.gz'
103+
]
104+
}
105+
},
106+
],
107+
'dwi': [
108+
{
109+
'dir': 'AP',
110+
'run': '01',
111+
'suffix': 'dwi',
112+
'metadata': {
113+
'RepetitionTime': 0.8,
114+
},
115+
}
116+
],
117+
},
118+
],
119+
}
120+
bidsuri_cs_intendedfor = {
121+
'01': [
122+
{
123+
'anat': [{'suffix': 'T1w', 'metadata': {'EchoTime': 1}}],
124+
'fmap': [
125+
{
126+
'dir': 'AP',
127+
'suffix': 'epi',
128+
'metadata': {
129+
'IntendedFor': [
130+
'bids::sub-01/dwi/sub-01_dir-AP_run-01_dwi.nii.gz'
131+
]
132+
}
133+
},
134+
{
135+
'dir': 'PA',
136+
'suffix': 'epi',
137+
'metadata': {
138+
'IntendedFor': [
139+
'bids::sub-01/dwi/sub-01_dir-AP_run-01_dwi.nii.gz'
140+
]
141+
}
142+
},
143+
],
144+
'dwi': [
145+
{
146+
'dir': 'AP',
147+
'run': '01',
148+
'suffix': 'dwi',
149+
'metadata': {
150+
'RepetitionTime': 0.8,
151+
},
152+
}
153+
],
154+
},
155+
],
156+
}
84157

85158
summary_data = {
86159
'RenameEntitySet': [
87160
None,
88-
"acquisition-VARIANT_datatype-dwi_direction-AP_run-01_suffix-dwi",
161+
"acquisition-VAR_datatype-dwi_direction-AP_run-01_suffix-dwi",
89162
None,
90163
None
91164
],
@@ -107,14 +180,14 @@
107180
'ParamGroup': [1, 1, 1, 1]
108181
}
109182

110-
files_data = {
183+
files_data_longitudinal = {
111184
'ParamGroup': [1, 1, 1, 1],
112185
'EntitySet': [
113186
"datatype-anat_suffix-T1w",
114187
"datatype-dwi_direction-AP_run-01_suffix-dwi",
115188
"datatype-fmap_direction-AP_fmap-epi_suffix-epi",
116189
"datatype-fmap_direction-PA_fmap-epi_suffix-epi"
117-
],
190+
],
118191
'FilePath': [
119192
"/sub-01/ses-01/anat/sub-01_ses-01_T1w.nii.gz",
120193
"/sub-01/ses-01/dwi/sub-01_ses-01_dir-AP_run-01_dwi.nii.gz",
@@ -129,20 +202,46 @@
129202
]
130203
}
131204

205+
files_data_cs = {
206+
'ParamGroup': [1, 1, 1, 1],
207+
'EntitySet': [
208+
"datatype-anat_suffix-T1w",
209+
"datatype-dwi_direction-AP_run-01_suffix-dwi",
210+
"datatype-fmap_direction-AP_fmap-epi_suffix-epi",
211+
"datatype-fmap_direction-PA_fmap-epi_suffix-epi"
212+
],
213+
'FilePath': [
214+
"/sub-01/anat/sub-01_T1w.nii.gz",
215+
"/sub-01/dwi/sub-01_dir-AP_run-01_dwi.nii.gz",
216+
"/sub-01/fmap/sub-01_dir-AP_epi.nii.gz",
217+
"/sub-01/fmap/sub-01_dir-PA_epi.nii.gz"
218+
],
219+
'KeyParamGroup': [
220+
"datatype-anat_suffix-T1w__1",
221+
"datatype-dwi_direction-AP_run-01_suffix-dwi__1",
222+
"datatype-fmap_direction-AP_fmap-epi_suffix-epi__1",
223+
"datatype-fmap_direction-PA_fmap-epi_suffix-epi__1"
224+
]
225+
}
226+
132227
@pytest.mark.parametrize(
133228
('name', 'skeleton', 'summary_data', 'files_data', 'expected'),
134229
[
135-
('relpath_longitudinal', relpath_longitudinal_intendedfor, summary_data, files_data, 'pass'),
136-
('bidsuri_longitudinal', bidsuri_longitudinal_intendedfor, summary_data, files_data, 'error'),
230+
('relpath_longitudinal', relpath_longitudinal_intendedfor, summary_data, files_data_longitudinal, 'ses-01/dwi/sub-01_ses-01_acq-VAR_dir-AP_run-001_dwi.nii.gz'),
231+
('bidsuri_longitudinal', bidsuri_longitudinal_intendedfor, summary_data, files_data_longitudinal, 'bids::sub-01/ses-01/dwi/sub-01_ses-01_acq-VAR_dir-AP_run-001_dwi.nii.gz'),
232+
('relpath_cs', relpath_cs_intendedfor, summary_data, files_data_cs, 'dwi/sub-01_acq-VAR_dir-AP_run-001_dwi.nii.gz'),
233+
('bidsuri_cs', bidsuri_cs_intendedfor, summary_data, files_data_cs, 'bids::sub-01/dwi/sub-01_acq-VAR_dir-AP_run-001_dwi.nii.gz'),
137234
],
138235
)
139236
def test_cubids_apply_intendedfor(tmpdir, name, skeleton, summary_data, files_data, expected):
140237
"""Test cubids apply with different IntendedFor types."""
238+
import json
239+
141240
from cubids.workflows import apply
142241

143242
# Generate a BIDS dataset
144-
bids_dir = str(tmpdir / name)
145-
generate_bids_skeleton(bids_dir, skeleton)
243+
bids_dir = tmpdir / name
244+
generate_bids_skeleton(str(bids_dir), skeleton)
146245

147246
# Create a summary tsv
148247
summary_tsv = tmpdir / 'summary.tsv'
@@ -155,22 +254,22 @@ def test_cubids_apply_intendedfor(tmpdir, name, skeleton, summary_data, files_da
155254

156255
# Run cubids apply
157256
apply(
158-
bids_dir=bids_dir,
257+
bids_dir=str(bids_dir),
159258
use_datalad=False,
160259
acq_group_level='subject',
161260
config=None,
162261
edited_summary_tsv=summary_tsv,
163262
files_tsv=files_tsv,
164263
new_tsv_prefix=None,
165-
container=False,
264+
container=None,
166265
)
167-
168-
# Check the results
169-
if expected == 'pass':
170-
# Look at the IntendedFor in the renamed files and it should be correct
171-
assert True
172-
elif expected == 'error':
173-
# Look at the IntendedFor in the renamed files and it should NOT be correct
174-
assert False
266+
if 'longitudinal' in name:
267+
fmap_json = bids_dir / 'sub-01/ses-01/fmap/sub-01_ses-01_dir-AP_epi.json'
175268
else:
176-
raise ValueError(f'Unknown expected value: {expected}')
269+
fmap_json = bids_dir / 'sub-01/fmap/sub-01_dir-AP_epi.json'
270+
271+
with open(fmap_json) as f:
272+
metadata = json.load(f)
273+
274+
# XXX: Should not have extra leading zero in run entity, but that's a known bug.
275+
assert metadata['IntendedFor'] == [expected]

cubids/workflows.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ def apply(
467467
str(new_tsv_prefix),
468468
raise_on_error=False,
469469
)
470-
sys.exit(0)
470+
return
471471

472472
# Run it through a container
473473
container_type = _get_container_type(container)

0 commit comments

Comments
 (0)