1414 "dir" : "AP" ,
1515 "suffix" : "epi" ,
1616 "metadata" : {
17- "IntendedFor" : [
18- "ses-01/dwi/sub-01_ses-01_dir-AP_run-01_dwi.nii.gz"
19- ]
17+ "IntendedFor" : ["ses-01/dwi/sub-01_ses-01_dir-AP_run-01_dwi.nii.gz" ],
2018 },
2119 },
2220 {
2321 "dir" : "PA" ,
2422 "suffix" : "epi" ,
2523 "metadata" : {
26- "IntendedFor" : [
27- "ses-01/dwi/sub-01_ses-01_dir-AP_run-01_dwi.nii.gz"
28- ]
24+ "IntendedFor" : ["ses-01/dwi/sub-01_ses-01_dir-AP_run-01_dwi.nii.gz" ],
2925 },
3026 },
3127 ],
5450 "metadata" : {
5551 "IntendedFor" : [
5652 "bids::sub-01/ses-01/dwi/sub-01_ses-01_dir-AP_run-01_dwi.nii.gz"
57- ]
53+ ],
5854 },
5955 },
6056 {
6359 "metadata" : {
6460 "IntendedFor" : [
6561 "bids::sub-01/ses-01/dwi/sub-01_ses-01_dir-AP_run-01_dwi.nii.gz"
66- ]
62+ ],
6763 },
6864 },
6965 ],
8985 "dir" : "AP" ,
9086 "suffix" : "epi" ,
9187 "metadata" : {
92- "IntendedFor" : ["dwi/sub-01_dir-AP_run-01_dwi.nii.gz" ]
88+ "IntendedFor" : ["dwi/sub-01_dir-AP_run-01_dwi.nii.gz" ],
9389 },
9490 },
9591 {
9692 "dir" : "PA" ,
9793 "suffix" : "epi" ,
9894 "metadata" : {
99- "IntendedFor" : ["dwi/sub-01_dir-AP_run-01_dwi.nii.gz" ]
95+ "IntendedFor" : ["dwi/sub-01_dir-AP_run-01_dwi.nii.gz" ],
10096 },
10197 },
10298 ],
122118 "dir" : "AP" ,
123119 "suffix" : "epi" ,
124120 "metadata" : {
125- "IntendedFor" : [
126- "bids::sub-01/dwi/sub-01_dir-AP_run-01_dwi.nii.gz"
127- ]
121+ "IntendedFor" : ["bids::sub-01/dwi/sub-01_dir-AP_run-01_dwi.nii.gz" ],
128122 },
129123 },
130124 {
131125 "dir" : "PA" ,
132126 "suffix" : "epi" ,
133127 "metadata" : {
134- "IntendedFor" : [
135- "bids::sub-01/dwi/sub-01_dir-AP_run-01_dwi.nii.gz"
136- ]
128+ "IntendedFor" : ["bids::sub-01/dwi/sub-01_dir-AP_run-01_dwi.nii.gz" ],
137129 },
138130 },
139131 ],
@@ -233,38 +225,48 @@ def summary_data():
233225
234226
235227@pytest .mark .parametrize (
236- ("name" , "skeleton" , "expected" ),
228+ ("name" , "skeleton" , "intended_for" , " expected" ),
237229 [
238230 (
239231 "relpath_long" ,
240232 relpath_intendedfor_long ,
241233 # XXX: Should not have extra leading zero in run entity, but that's a known bug.
242234 "ses-01/dwi/sub-01_ses-01_acq-VAR_dir-AP_run-001_dwi.nii.gz" ,
235+ "pass" ,
243236 ),
244237 (
245238 "bidsuri_long" ,
246239 bidsuri_intendedfor_long ,
247240 # XXX: Should not have extra leading zero in run entity, but that's a known bug.
248241 "bids::sub-01/ses-01/dwi/sub-01_ses-01_acq-VAR_dir-AP_run-001_dwi.nii.gz" ,
242+ "pass" ,
249243 ),
250244 (
251245 "relpath_cs" ,
252246 relpath_intendedfor_cs ,
253247 # XXX: Should not have extra leading zero in run entity, but that's a known bug.
254248 # XXX: CuBIDS enforces longitudinal dataset, so this fails.
255249 "dwi/sub-01_acq-VAR_dir-AP_run-001_dwi.nii.gz" ,
250+ TypeError ,
256251 ),
257252 (
258253 "bidsuri_cs" ,
259254 bidsuri_intendedfor_cs ,
260255 # XXX: Should not have extra leading zero in run entity, but that's a known bug.
261256 # XXX: CuBIDS enforces longitudinal dataset, so this fails.
262257 "bids::sub-01/dwi/sub-01_acq-VAR_dir-AP_run-001_dwi.nii.gz" ,
258+ TypeError ,
263259 ),
264260 ],
265261)
266262def test_cubids_apply_intendedfor (
267- tmpdir , summary_data , files_data , name , skeleton , expected
263+ tmpdir ,
264+ summary_data ,
265+ files_data ,
266+ name ,
267+ skeleton ,
268+ intended_for ,
269+ expected ,
268270):
269271 """Test cubids apply with different IntendedFor types."""
270272 import json
@@ -275,36 +277,49 @@ def test_cubids_apply_intendedfor(
275277 bids_dir = tmpdir / name
276278 generate_bids_skeleton (str (bids_dir ), skeleton )
277279
278- # Create a summary tsv
280+ if "long" in name :
281+ fdata = files_data ["longitudinal" ]
282+ fmap_json = bids_dir / "sub-01/ses-01/fmap/sub-01_ses-01_dir-AP_epi.json"
283+ else :
284+ fdata = files_data ["cross-sectional" ]
285+ fmap_json = bids_dir / "sub-01/fmap/sub-01_dir-AP_epi.json"
286+
287+ # Create a CuBIDS summary tsv
279288 summary_tsv = tmpdir / "summary.tsv"
280289 df = pd .DataFrame (summary_data )
281290 df .to_csv (summary_tsv , sep = "\t " , index = False )
282291
292+ # Create a CuBIDS files tsv
283293 files_tsv = tmpdir / "files.tsv"
284- if "long" in name :
285- fdata = files_data ["longitudinal" ]
286- else :
287- fdata = files_data ["cross-sectional" ]
288294 df = pd .DataFrame (fdata )
289295 df .to_csv (files_tsv , sep = "\t " , index = False )
290296
291297 # Run cubids apply
292- apply (
293- bids_dir = str (bids_dir ),
294- use_datalad = False ,
295- acq_group_level = "subject" ,
296- config = None ,
297- edited_summary_tsv = summary_tsv ,
298- files_tsv = files_tsv ,
299- new_tsv_prefix = None ,
300- container = None ,
301- )
302- if "long" in name :
303- fmap_json = bids_dir / "sub-01/ses-01/fmap/sub-01_ses-01_dir-AP_epi.json"
304- else :
305- fmap_json = bids_dir / "sub-01/fmap/sub-01_dir-AP_epi.json"
298+ if isinstance (expected , str ):
299+ apply (
300+ bids_dir = str (bids_dir ),
301+ use_datalad = False ,
302+ acq_group_level = "subject" ,
303+ config = None ,
304+ edited_summary_tsv = summary_tsv ,
305+ files_tsv = files_tsv ,
306+ new_tsv_prefix = None ,
307+ container = None ,
308+ )
306309
307- with open (fmap_json ) as f :
308- metadata = json .load (f )
310+ with open (fmap_json ) as f :
311+ metadata = json .load (f )
309312
310- assert metadata ["IntendedFor" ] == [expected ]
313+ assert metadata ["IntendedFor" ] == [intended_for ]
314+ else :
315+ with pytest .raises (expected ):
316+ apply (
317+ bids_dir = str (bids_dir ),
318+ use_datalad = False ,
319+ acq_group_level = "subject" ,
320+ config = None ,
321+ edited_summary_tsv = summary_tsv ,
322+ files_tsv = files_tsv ,
323+ new_tsv_prefix = None ,
324+ container = None ,
325+ )
0 commit comments