99
1010import matplotlib .pyplot as plt
1111from bids .layout .writing import build_path
12+ from bids .layout import BIDSLayout
1213
1314import pytest
1415
@@ -24,26 +25,28 @@ def bids_sessions(tmpdir_factory):
2425 pattern = (
2526 "sub-{subject}[/ses-{session}]/{datatype<anat|func>}/"
2627 "sub-{subject}[_ses-{session}][_task-{task}][_acq-{acquisition}]"
27- "[_ce-{contrast }][_dir-{direction}][_rec-{reconstruction}]"
28+ "[_ce-{ceagent }][_dir-{direction}][_rec-{reconstruction}]"
2829 "[_mod-{modality}][_run-{run}][_echo-{echo}][_space-{space}]"
2930 "[_desc-{desc}]_{suffix<dseg|T1w|bold>}.{extension<svg>}"
3031 )
3132 subjects = ['01' ]
3233 tasks = ['t1' , 't2' , 't3' ]
3334 runs = ['01' , '02' , None ]
35+ ces = ['none' , 'Gd' ]
3436 descs = ['aroma' , 'bbregister' , 'carpetplot' , 'rois' ]
3537 # create functional data for both sessions
36- ses1_combos = product (subjects , ['1' ], tasks , runs , descs )
37- ses2_combos = product (subjects , ['2' ], tasks , [None ], descs )
38+ ses1_combos = product (subjects , ['1' ], tasks , [ None ], runs , descs )
39+ ses2_combos = product (subjects , ['2' ], tasks , ces , [None ], descs )
3840 # have no runs in the second session (ex: dmriprep test data)
3941 # https://github.com/nipreps/dmriprep/pull/59
4042 all_combos = list (ses1_combos ) + list (ses2_combos )
4143
42- for subject , session , task , run , desc in all_combos :
44+ for subject , session , task , ce , run , desc in all_combos :
4345 entities = {
4446 'subject' : subject ,
4547 'session' : session ,
4648 'task' : task ,
49+ 'ceagent' : ce ,
4750 'run' : run ,
4851 'desc' : desc ,
4952 'extension' : 'svg' ,
@@ -143,10 +146,10 @@ def test_process_orderings_small(test_report1, orderings,
143146@pytest .mark .parametrize (
144147 "orderings,expected_entities,first_value_combo,last_value_combo" ,
145148 [
146- (['session' , 'task' , 'run' ],
147- ['session' , 'task' , 'run' ],
148- ('1' , 't1' , None ),
149- ('2' , 't3' , None ),
149+ (['session' , 'task' , 'ceagent' , ' run' ],
150+ ['session' , 'task' , 'ceagent' , ' run' ],
151+ ('1' , 't1' , None , None ),
152+ ('2' , 't3' , 'none' , None ),
150153 ),
151154 (['run' , 'task' , 'session' ],
152155 ['run' , 'task' , 'session' ],
@@ -182,6 +185,7 @@ def test_process_orderings_large(test_report2, orderings,
182185 ("run" ),
183186 ("session,task" ),
184187 ("session,task,run" ),
188+ ("session,task,ceagent,run" ),
185189 ("session,task,acquisition,ceagent,reconstruction,direction,run,echo" ),
186190 ("session,task,run,madeupentity" ),
187191 ])
@@ -198,12 +202,15 @@ def test_generated_reportlets(bids_sessions, ordering):
198202 # expected number of reportlets
199203 expected_reportlets_num = len (report .layout .get (extension = 'svg' ))
200204 # bids_session uses these entities
201- needed_entities = ['session' , 'task' , 'run' ]
205+ needed_entities = ['session' , 'task' , 'ceagent' , ' run' ]
202206 # the last section is the most recently run
203207 reportlets_num = len (report .sections [- 1 ].reportlets )
208+ # get the number of figures in the output directory
209+ out_layout = BIDSLayout (out_dir , config = 'figures' , validate = False )
210+ out_figs = len (out_layout .get ())
204211 # if ordering does not contain all the relevent entities
205212 # then there should be fewer reportlets than expected
206213 if all (ent in ordering for ent in needed_entities ):
207- assert reportlets_num == expected_reportlets_num
214+ assert reportlets_num == expected_reportlets_num == out_figs
208215 else :
209- assert reportlets_num < expected_reportlets_num
216+ assert reportlets_num < expected_reportlets_num == out_figs
0 commit comments