|
1 | 1 | """Tests for fmriprep.interfaces.bids.""" |
2 | 2 |
|
| 3 | +import pytest |
| 4 | + |
3 | 5 |
|
4 | 6 | def test_BIDSURI(): |
5 | 7 | """Test the BIDSURI interface.""" |
@@ -70,3 +72,62 @@ def test_BIDSURI(): |
70 | 72 | 'bids:deriv-0:sub-01/func/sub-01_task-rest_bold.nii.gz', |
71 | 73 | '/out/sub-01/func/sub-01_task-rest_bold.nii.gz', # No change |
72 | 74 | ] |
| 75 | + |
| 76 | + |
| 77 | +bids_infos_anat = [ |
| 78 | + [{'t1w': ['sub-01/anat/sub-01_T1w.nii.gz']}, {}], |
| 79 | + [{'t2w': ['sub-01/anat/sub-01_T2w.nii.gz']}, {}], |
| 80 | + [ |
| 81 | + {'t1w': []}, |
| 82 | + {'t1w_preproc': ['sourcedata/smriprep/sub-01/anat/sub-01_desc-preproc_T1w.nii.gz']}, |
| 83 | + ], |
| 84 | + [ |
| 85 | + {'t2w': []}, |
| 86 | + {'t2w_preproc': ['sourcedata/smriprep/sub-01/anat/sub-01_desc-preproc_T2w.nii.gz']}, |
| 87 | + ], |
| 88 | +] |
| 89 | + |
| 90 | +bids_infos_func = { |
| 91 | + 'single-echo': { |
| 92 | + 'bold': ['sub-01/func/sub-01_task-rest_bold.nii.gz'], |
| 93 | + }, |
| 94 | + 'multi-echo': { |
| 95 | + 'bold': [ |
| 96 | + [ |
| 97 | + 'sub-01/func/sub-01_task-rest_echo-1_bold.nii.gz', |
| 98 | + 'sub-01/func/sub-01_task-rest_echo-2_bold.nii.gz', |
| 99 | + 'sub-01/func/sub-01_task-rest_echo-3_bold.nii.gz', |
| 100 | + ], |
| 101 | + ], |
| 102 | + }, |
| 103 | +} |
| 104 | + |
| 105 | + |
| 106 | +@pytest.mark.parametrize( |
| 107 | + ('bids_info_anat', 'bids_info_func', 'precomputed_infos'), |
| 108 | + [ |
| 109 | + (bids_info_anat, bids_info_func, precomputed_infos) |
| 110 | + for bids_info_anat, precomputed_infos in bids_infos_anat |
| 111 | + for func_case, bids_info_func in bids_infos_func.items() |
| 112 | + ], |
| 113 | +) |
| 114 | +def test_BIDSSourceFile(bids_info_anat, bids_info_func, precomputed_infos): |
| 115 | + """Test the BIDSSourceFile interface""" |
| 116 | + from fmriprep.interfaces.bids import BIDSSourceFile |
| 117 | + |
| 118 | + interface = BIDSSourceFile() |
| 119 | + anat_type = next(iter(bids_info_anat)) |
| 120 | + interface.inputs.anat_type = anat_type |
| 121 | + interface.inputs.bids_info = {**bids_info_anat, **bids_info_func} |
| 122 | + interface.inputs.precomputed = precomputed_infos |
| 123 | + results = interface.run() |
| 124 | + |
| 125 | + if precomputed_infos: |
| 126 | + bold = ( |
| 127 | + 'sub-01/func/sub-01_bold.nii.gz' |
| 128 | + if isinstance(bids_info_func['bold'][0], list) |
| 129 | + else 'sub-01/func/sub-01_task-rest_bold.nii.gz' |
| 130 | + ) |
| 131 | + assert results.outputs.source_file == bold |
| 132 | + else: |
| 133 | + assert results.outputs.source_file == bids_info_anat[anat_type][0] |
0 commit comments