Skip to content

Commit 1c0b225

Browse files
committed
TST: Add test for interface
1 parent 66aa596 commit 1c0b225

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import shutil
2+
from pathlib import Path
3+
4+
import pytest
5+
6+
from nibabies.interfaces.mcribs import MCRIBReconAll
7+
8+
SUBJECT_ID = 'X'
9+
10+
11+
@pytest.fixture
12+
def mcribs_directory(tmp_path):
13+
def make_tree(path, tree):
14+
for d, fls in tree.items():
15+
(path / d).mkdir(exist_ok=True)
16+
for f in fls:
17+
(path / d / f).touch()
18+
19+
root = tmp_path / 'mcribs'
20+
surfrecon = root / SUBJECT_ID / 'SurfReconDeformable' / SUBJECT_ID
21+
surfrecon.mkdir(parents=True, exist_ok=True)
22+
make_tree(surfrecon, MCRIBReconAll._expected_files['surfrecon'])
23+
autorecon = root / SUBJECT_ID / 'freesurfer' / SUBJECT_ID
24+
autorecon.mkdir(parents=True, exist_ok=True)
25+
make_tree(autorecon, MCRIBReconAll._expected_files['autorecon'])
26+
27+
yield root
28+
29+
shutil.rmtree(root)
30+
31+
32+
def test_MCRIBReconAll(mcribs_directory):
33+
t2w = Path('T2w.nii.gz')
34+
t2w.touch()
35+
36+
surfrecon = MCRIBReconAll(
37+
subject_id=SUBJECT_ID,
38+
surfrecon=True,
39+
surfrecon_method='Deformable',
40+
join_thresh=1.0,
41+
fast_collision=True,
42+
)
43+
44+
# Requires T2w input
45+
with pytest.raises(AttributeError):
46+
surfrecon.cmdline # noqa
47+
48+
surfrecon.inputs.t2w_file = t2w
49+
# Since no existing directory is found, will run fresh
50+
assert 'MCRIBReconAll --deformablefastcollision --deformablejointhresh' in surfrecon.cmdline
51+
52+
# But should not need to run again
53+
surfrecon.inputs.outdir = mcribs_directory
54+
assert surfrecon.cmdline == 'echo MCRIBReconAll: nothing to do'
55+
56+
t2w.unlink()
57+
58+
autorecon = MCRIBReconAll(
59+
subject_id=SUBJECT_ID,
60+
autorecon_after_surf=True,
61+
)
62+
# No need for T2w here
63+
assert autorecon.cmdline == 'MCRIBReconAll --autoreconaftersurf X'
64+
autorecon.inputs.outdir = mcribs_directory
65+
assert autorecon.cmdline == 'echo MCRIBReconAll: nothing to do'

0 commit comments

Comments
 (0)