-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtest_derivatives.py
More file actions
56 lines (50 loc) · 1.97 KB
/
test_derivatives.py
File metadata and controls
56 lines (50 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
"""Test BIDSValidator support for derivative filenames."""
import pytest
from bids_validator import BIDSValidator
@pytest.mark.parametrize(
'fname',
[
'/sub-04/anat/sub-04_space-MNI152_T1w.nii.gz', # space
'/sub-04/anat/sub-04_space-MNI152_desc-preproc_T1w.nii.gz', # space + desc
'/sub-04/ses-02/func/sub-04_ses-02_task-rest_space-MNI152NLin2009cAsym_desc-preproc_bold.nii', # space + desc
'/sub-04/ses-02/func/sub-04_ses-02_task-nback_run-02_space-T1w_label-brain_mask.nii', # space + label
'/sub-04/ses-01/func/sub-04_ses-01_task-nback_run-01_space-T1w_desc-preproc_bold.json', # space + desc
'/sub-01/anat/sub-01_res-1_T1w.nii.gz', # res
'/sub-01/anat/sub-01_space-MNI152_dseg.nii.gz', # dseg suffix
],
)
def test_derivative_filenames_are_bids(fname: str) -> None:
"""Test that derivative filenames are recognized as valid BIDS."""
assert BIDSValidator.is_bids(fname)
@pytest.mark.parametrize(
('fname', 'expected'),
[
(
'/sub-04/anat/sub-04_space-MNI152_desc-preproc_T1w.nii.gz',
{
'subject': '04',
'datatype': 'anat',
'space': 'MNI152',
'description': 'preproc',
'suffix': 'T1w',
'extension': '.nii.gz',
},
),
(
'/sub-04/ses-02/func/sub-04_ses-02_task-rest_space-MNI152NLin2009cAsym_desc-preproc_bold.nii',
{
'subject': '04',
'session': '02',
'datatype': 'func',
'task': 'rest',
'space': 'MNI152NLin2009cAsym',
'description': 'preproc',
'suffix': 'bold',
'extension': '.nii',
},
),
],
)
def test_parse_derivative_entities(fname: str, expected: dict[str, str]) -> None:
"""Test that parse() returns derivative-specific entities."""
assert BIDSValidator.parse(fname) == expected