|
| 1 | +import json |
| 2 | +from pathlib import Path |
| 3 | + |
| 4 | +import pytest |
| 5 | + |
| 6 | +from fmriprep.data import load as load_data |
| 7 | +from fmriprep.utils import bids |
| 8 | + |
| 9 | + |
| 10 | +@pytest.mark.parametrize('xfm', ['boldref2fmap', 'boldref2anat', 'hmc']) |
| 11 | +def test_transforms_found_as_str(tmp_path: Path, xfm: str): |
| 12 | + spec = ( |
| 13 | + json.loads(load_data.readable('io_spec.json').read_text()) |
| 14 | + .get('queries') |
| 15 | + .get('transforms') |
| 16 | + .get(xfm) |
| 17 | + ) |
| 18 | + entities = { |
| 19 | + 'subject': '0', |
| 20 | + 'task': 'rest', |
| 21 | + 'suffix': 'bold', |
| 22 | + 'extension': '.nii.gz', |
| 23 | + } |
| 24 | + if xfm == 'boldref2fmap': |
| 25 | + to_find = f'sub-{entities['subject']}_task-{entities['task']} \ |
| 26 | + _from-{spec['from']}_to-auto00000_mode-image_xfm.txt' |
| 27 | + else: |
| 28 | + to_find = f'sub-{entities['subject']}_task-{entities['task']} \ |
| 29 | + _from-{spec['from']}_to-{spec['to']}_mode-image_xfm.txt' |
| 30 | + |
| 31 | + funcd = tmp_path / f'sub-{entities['subject']}' / 'func' |
| 32 | + funcd.mkdir(parents=True) |
| 33 | + (funcd / to_find).touch() |
| 34 | + |
| 35 | + derivs = bids.collect_derivatives( |
| 36 | + derivatives_dir=tmp_path, |
| 37 | + entities=entities, |
| 38 | + fieldmap_id='auto_00000', |
| 39 | + ) |
| 40 | + transforms_in_derivs = 'transforms' in derivs |
| 41 | + xfm_in_transforms = xfm in derivs.get('transforms') |
| 42 | + transform_is_str = isinstance(derivs.get('transforms').get(xfm), str) |
| 43 | + assert all((transforms_in_derivs, xfm_in_transforms, transform_is_str)) |
| 44 | + |
0 commit comments