|
1 | 1 | import pytest |
2 | 2 | from bids import BIDSLayout |
3 | 3 |
|
| 4 | +import json |
| 5 | + |
4 | 6 | from ..testing import generate_bids_skeleton |
5 | 7 |
|
6 | 8 |
|
|
107 | 109 | "04": "*", |
108 | 110 | } |
109 | 111 |
|
| 112 | +bids_dir_deriv = { |
| 113 | + "dataset_description": { |
| 114 | + "Name": "derivs", |
| 115 | + "DatasetType": "derivative", |
| 116 | + "BIDSVersion": "1.9.0", |
| 117 | + "GeneratedBy": [ |
| 118 | + {"Name": "Niworkflows"} |
| 119 | + ] |
| 120 | + }, |
| 121 | + "01": { |
| 122 | + "anat": [ |
| 123 | + {"suffix": "white", "hemi": "L", "extension": ".surf.gii"}, |
| 124 | + {"suffix": "white", "hemi": "R", "extension": ".surf.gii"}, |
| 125 | + {"suffix": "xfm", "to": "MNI152NLin2009cAsym", "from": "T1w", "extension": ".h5"} |
| 126 | + ] |
| 127 | + } |
| 128 | +} |
| 129 | + |
110 | 130 |
|
111 | 131 | @pytest.mark.parametrize( |
112 | 132 | "test_id,json_layout,n_files,n_subjects,n_sessions", |
113 | 133 | [ |
114 | 134 | ('sessions', bids_dir_sessions, 31, 3, 2), |
115 | 135 | ('nosession', bids_dir_session_less, 25, 4, 0), |
| 136 | + ('derivatives', bids_dir_deriv, 4, 1, 0) |
116 | 137 | ], |
117 | 138 | ) |
118 | 139 | def test_generate_bids_skeleton(tmp_path, test_id, json_layout, n_files, n_subjects, n_sessions): |
119 | 140 | root = tmp_path / test_id |
120 | 141 | generate_bids_skeleton(root, json_layout) |
121 | 142 | datadesc = root / "dataset_description.json" |
122 | 143 | assert datadesc.exists() |
123 | | - assert "BIDSVersion" in datadesc.read_text() |
| 144 | + desc = json.loads(datadesc.read_text()) |
| 145 | + assert "BIDSVersion" in desc |
| 146 | + if test_id == 'derivatives': |
| 147 | + assert desc["DatasetType"] == "derivative" |
124 | 148 |
|
125 | 149 | assert len([x for x in root.glob("**/*") if x.is_file()]) == n_files |
126 | 150 |
|
127 | 151 | # ensure layout is valid |
128 | | - layout = BIDSLayout(root) |
| 152 | + layout = BIDSLayout(root, validate=False) |
129 | 153 | assert len(layout.get_subjects()) == n_subjects |
130 | 154 | assert len(layout.get_sessions()) == n_sessions |
131 | 155 |
|
132 | | - anat = layout.get(suffix="T1w", extension="nii.gz")[0] |
133 | | - bold = layout.get(suffix="bold", extension="nii.gz")[0] |
134 | | - assert anat.get_metadata() |
135 | | - assert bold.get_metadata() |
| 156 | + if test_id != 'derivatives': |
| 157 | + anat = layout.get(suffix="T1w", extension=".nii.gz")[0] |
| 158 | + bold = layout.get(suffix="bold", extension=".nii.gz")[0] |
| 159 | + assert anat.get_metadata() |
| 160 | + assert bold.get_metadata() |
| 161 | + else: |
| 162 | + white = layout.get(suffix="white") |
| 163 | + assert len(white) == 2 |
| 164 | + xfm = layout.get(suffix="xfm")[0] |
| 165 | + assert xfm |
0 commit comments