|
| 1 | +import pytest |
| 2 | + |
| 3 | +from ..hbcd import main |
| 4 | + |
| 5 | + |
| 6 | +# create a FreeSurfer / MCRIBS directory structure |
| 7 | +@pytest.fixture |
| 8 | +def freesurfer(tmp_path): |
| 9 | + root = tmp_path / 'freesurfer' |
| 10 | + for s in ('fsaverage', 'sub-01_ses-1', 'sub-01_ses-2'): |
| 11 | + (root / s / 'mri').mkdir(parents=True, exist_ok=True) |
| 12 | + (root / s / 'mri' / 'T1.mgz').touch() |
| 13 | + (root / s / 'surf').mkdir(parents=True, exist_ok=True) |
| 14 | + (root / s / 'surf' / 'lh.pial').touch() |
| 15 | + return root |
| 16 | + |
| 17 | + |
| 18 | +@pytest.fixture |
| 19 | +def mcribs(tmp_path): |
| 20 | + root = tmp_path / 'mcribs' |
| 21 | + for s in ('sub-01_ses-1', 'sub-01_ses-2'): |
| 22 | + (root / s / 'TissueSeg').mkdir(parents=True, exist_ok=True) |
| 23 | + orig = root / s / 'TissueSeg' / f'{s}_all_labels.nii.gz' |
| 24 | + orig.touch() |
| 25 | + (root / s / 'TissueSeg' / f'{s}_all_labels_manedit.nii.gz').symlink_to(orig) |
| 26 | + return root |
| 27 | + |
| 28 | + |
| 29 | +def test_hbcd_restructure(freesurfer, mcribs): |
| 30 | + # running without options is fine |
| 31 | + main([]) |
| 32 | + |
| 33 | + main(['--fs', str(freesurfer), '--mcribs', str(mcribs)]) |
| 34 | + assert sorted(x.name for x in freesurfer.iterdir()) == ['fsaverage', 'sub-01'] |
| 35 | + assert sorted(x.name for x in (freesurfer / 'sub-01').iterdir()) == ['ses-1', 'ses-2'] |
| 36 | + |
| 37 | + assert [x.name for x in mcribs.iterdir()] == ['sub-01'] |
| 38 | + linkd = mcribs / 'sub-01' / 'ses-1' / 'TissueSeg' / 'sub-01_ses-1_all_labels_manedit.nii.gz' |
| 39 | + assert linkd.exists() |
| 40 | + assert not linkd.is_symlink() |
| 41 | + |
| 42 | + # and run again should not fail |
| 43 | + main(['--fs', str(freesurfer), '--mcribs', str(mcribs)]) |
0 commit comments