Skip to content

Commit 0d8843b

Browse files
committed
add tests for nib-conform command
1 parent 3911610 commit 0d8843b

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

nibabel/cmdline/tests/test_conform.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!python
2+
# emacs: -*- mode: python-mode; py-indent-offset: 4; indent-tabs-mode: nil -*-
3+
# vi: set ft=python sts=4 ts=4 sw=4 et:
4+
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##
5+
#
6+
# See COPYING file distributed along with the NiBabel package for the
7+
# copyright and license terms.
8+
#
9+
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##
10+
11+
import pytest
12+
13+
import nibabel as nib
14+
from nibabel.testing import test_data
15+
from nibabel.cmdline.conform import main
16+
17+
18+
def test_default(tmpdir):
19+
infile = test_data(fname="anatomical.nii")
20+
outfile = tmpdir / "output.nii.gz"
21+
main([str(infile), str(outfile)])
22+
assert outfile.isfile()
23+
c = nib.load(outfile)
24+
assert c.shape == (256, 256, 256)
25+
assert c.header.get_zooms() == (1, 1, 1)
26+
assert nib.orientations.aff2axcodes(c.affine) == ('R', 'A', 'S')
27+
28+
29+
def test_nondefault(tmpdir):
30+
infile = test_data(fname="anatomical.nii")
31+
outfile = tmpdir / "output.nii.gz"
32+
out_shape = (100, 100, 150)
33+
voxel_size = (1, 2, 4)
34+
orientation = "LAS"
35+
args = "{} {} --out-shape {} --voxel-size {} --orientation {}".format(
36+
infile, outfile, " ".join(map(str, out_shape)), " ".join(map(str, voxel_size)), orientation)
37+
main(args.split())
38+
assert outfile.isfile()
39+
c = nib.load(outfile)
40+
assert c.shape == out_shape
41+
assert c.header.get_zooms() == voxel_size
42+
assert nib.orientations.aff2axcodes(c.affine) == tuple(orientation)
43+
44+
45+
def test_non3d(tmpdir):
46+
infile = test_data(fname="functional.nii")
47+
outfile = tmpdir / "output.nii.gz"
48+
with pytest.raises(ValueError):
49+
main([str(infile), str(outfile)])

0 commit comments

Comments
 (0)