|
6 | 6 | """
|
7 | 7 |
|
8 | 8 | from nose.tools import assert_equal
|
| 9 | +from numpy.testing import assert_raises |
9 | 10 |
|
10 | 11 | import nibabel as nib
|
11 | 12 | import numpy as np
|
12 | 13 | from nibabel.cmdline.utils import *
|
13 |
| -from nibabel.cmdline.diff import get_headers_diff, display_diff |
| 14 | +from nibabel.cmdline.diff import get_headers_diff, display_diff, main |
14 | 15 | from os.path import (join as pjoin)
|
15 | 16 | from nibabel.testing import data_path
|
16 | 17 | from collections import OrderedDict
|
@@ -106,3 +107,44 @@ def test_display_diff():
|
106 | 107 | "\n"
|
107 | 108 |
|
108 | 109 | assert_equal(display_diff(bogus_names, dict_values), expected_output)
|
| 110 | + |
| 111 | + |
| 112 | +def test_main(): |
| 113 | + test_names = [pjoin(data_path, f) |
| 114 | + for f in ('standard.nii.gz', 'example4d.nii.gz')] |
| 115 | + expected_difference = OrderedDict([ |
| 116 | + ("regular", [np.asarray("".encode("utf-8")), np.asarray("r".encode("utf-8"))]), |
| 117 | + ("dim_info", [np.asarray(0).astype(dtype="uint8"), np.asarray(57).astype(dtype="uint8")]), |
| 118 | + ("dim", [np.array([3, 4, 5, 7, 1, 1, 1, 1]).astype(dtype="int16"), |
| 119 | + np.array([4, 128, 96, 24, 2, 1, 1, 1]).astype(dtype="int16")]), |
| 120 | + ("datatype", [np.array(2).astype(dtype="uint8"), np.array(4).astype(dtype="uint8")]), |
| 121 | + ("bitpix", [np.array(8).astype(dtype="uint8"), np.array(16).astype(dtype="uint8")]), |
| 122 | + ("pixdim", [np.array([1., 1., 3., 2., 1., 1., 1., 1.]).astype(dtype="float32"), np.array( |
| 123 | + [-1.00000000e+00, 2.00000000e+00, 2.00000000e+00, 2.19999909e+00, 2.00000000e+03, 1.00000000e+00, |
| 124 | + 1.00000000e+00, 1.00000000e+00]).astype(dtype="float32")]), |
| 125 | + ("slice_end", [np.array(0).astype(dtype="uint8"), np.array(23).astype(dtype="uint8")]), |
| 126 | + ("xyzt_units", [np.array(0).astype(dtype="uint8"), np.array(10).astype(dtype="uint8")]), |
| 127 | + ("cal_max", [np.array(0.0).astype(dtype="float32"), np.asarray(1162.0).astype(dtype="float32")]), |
| 128 | + ("descrip", [np.array("".encode("utf-8")).astype(dtype="S80"), |
| 129 | + np.array("FSL3.3\x00 v2.25 NIfTI-1 Single file format".encode("utf-8")).astype(dtype="S80")]), |
| 130 | + ("qform_code", [np.array(0).astype(dtype="int16"), np.array(1).astype(dtype="int16")]), |
| 131 | + ("sform_code", [np.array(2).astype(dtype="int16"), np.array(1).astype(dtype="int16")]), |
| 132 | + ("quatern_b", [np.array(0.0).astype(dtype="float32"), |
| 133 | + np.array(-1.9451068140294884e-26).astype(dtype="float32")]), |
| 134 | + ("quatern_c", [np.array(0.0).astype(dtype="float32"), np.array(-0.9967085123062134).astype(dtype="float32")]), |
| 135 | + ("quatern_d", [np.array(0.0).astype(dtype="float32"), np.array(-0.0810687392950058).astype(dtype="float32")]), |
| 136 | + ("qoffset_x", [np.array(0.0).astype(dtype="float32"), np.array(117.8551025390625).astype(dtype="float32")]), |
| 137 | + ("qoffset_y", [np.array(0.0).astype(dtype="float32"), np.array(-35.72294235229492).astype(dtype="float32")]), |
| 138 | + ("qoffset_z", [np.array(0.0).astype(dtype="float32"), np.array(-7.248798370361328).astype(dtype="float32")]), |
| 139 | + ("srow_x", [np.array([1., 0., 0., 0.]).astype(dtype="float32"), |
| 140 | + np.array([-2.00000000e+00, 6.71471565e-19, 9.08102451e-18, |
| 141 | + 1.17855103e+02]).astype(dtype="float32")]), |
| 142 | + ("srow_y", [np.array([0., 3., 0., 0.]).astype(dtype="float32"), |
| 143 | + np.array([-6.71471565e-19, 1.97371149e+00, -3.55528235e-01, -3.57229424e+01]).astype( |
| 144 | + dtype="float32")]), |
| 145 | + ("srow_z", [np.array([0., 0., 2., 0.]).astype(dtype="float32"), |
| 146 | + np.array([8.25548089e-18, 3.23207617e-01, 2.17108178e+00, |
| 147 | + -7.24879837e+00]).astype(dtype="float32")]), |
| 148 | + ('DATA(md5)', ['0a2576dd6badbb25bfb3b12076df986b', 'b0abbc492b4fd533b2c80d82570062cf'])]) |
| 149 | + |
| 150 | + np.testing.assert_equal(main(test_names), expected_difference) |
0 commit comments