|
| 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