Skip to content

Commit eacc366

Browse files
committed
enh: add cli tests
1 parent 6a06cdc commit eacc366

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

nitransforms/tests/test_cli.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
from textwrap import dedent
2+
3+
import pytest
4+
5+
from ..cli import cli_apply, main as ntcli
6+
7+
8+
def test_cli():
9+
# empty command
10+
with pytest.raises(SystemExit):
11+
ntcli()
12+
# invalid command
13+
with pytest.raises(SystemExit):
14+
ntcli(['idk'])
15+
16+
17+
def test_help(capsys):
18+
with pytest.raises(SystemExit) as sysexit:
19+
ntcli(['-h'])
20+
console = capsys.readouterr()
21+
assert sysexit.value.code == 0
22+
# possible commands
23+
assert r"{apply}" in console.out
24+
25+
with pytest.raises(SystemExit):
26+
ntcli(['apply', '-h'])
27+
console = capsys.readouterr()
28+
assert dedent(cli_apply.__doc__) in console.out
29+
30+
31+
def test_apply_linear(tmpdir, data_path, get_testdata):
32+
tmpdir.chdir()
33+
img = 'img.nii.gz'
34+
get_testdata['RAS'].to_filename(img)
35+
lin_xform = str(data_path / 'affine-RAS.itk.tfm')
36+
37+
# unknown transformation format
38+
with pytest.raises(ValueError):
39+
ntcli(['apply', 'unsupported.xform', 'img.nii.gz'])
40+
41+
# linear transform arguments
42+
largs = ['apply', lin_xform, img, '--ref', img]
43+
ntcli(largs)
44+
output = 'nt_img.nii.gz'
45+
assert (tmpdir / output).check()
46+
47+
48+
def test_apply_nl(tmpdir, data_path):
49+
tmpdir.chdir()
50+
img = str(data_path / 'tpl-OASIS30ANTs_T1w.nii.gz')
51+
nl_xform = str(data_path / 'ds-005_sub-01_from-OASIS_to-T1_warp_afni.nii.gz')
52+
53+
nlargs = ['apply', nl_xform, img]
54+
# format not specified
55+
with pytest.raises(ValueError):
56+
ntcli(nlargs)
57+
58+
nlargs.extend(['--fmt', 'afni'])
59+
# no linear afni support
60+
with pytest.raises(NotImplementedError):
61+
ntcli(nlargs)
62+
63+
output = 'moved_from_warp.nii.gz'
64+
nlargs.extend(['--nonlinear', '--out', output])
65+
ntcli(nlargs)
66+
assert (tmpdir / output).check()

0 commit comments

Comments
 (0)