|
20 | 20 |
|
21 | 21 | from nose.tools import (assert_true, assert_false, assert_not_equal,
|
22 | 22 | assert_equal)
|
| 23 | +from nose import SkipTest |
23 | 24 |
|
24 | 25 | from numpy.testing import assert_almost_equal
|
25 | 26 |
|
26 | 27 | from .scriptrunner import ScriptRunner
|
27 | 28 | from .nibabel_data import needs_nibabel_data
|
28 |
| -from ..testing import assert_dt_equal |
| 29 | +from ..testing import assert_dt_equal, assert_re_in |
29 | 30 | from .test_parrec import (DTI_PAR_BVECS, DTI_PAR_BVALS,
|
30 | 31 | EXAMPLE_IMAGES as PARREC_EXAMPLES)
|
31 | 32 | from .test_parrec_data import BALLS, AFF_OFF
|
@@ -53,16 +54,69 @@ def script_test(func):
|
53 | 54 | DATA_PATH = abspath(pjoin(dirname(__file__), 'data'))
|
54 | 55 |
|
55 | 56 |
|
56 |
| -@script_test |
57 |
| -def test_nib_ls(): |
| 57 | +def check_nib_ls_example4d(opts=[], hdrs_str=""): |
58 | 58 | # test nib-ls script
|
59 | 59 | fname = pjoin(DATA_PATH, 'example4d.nii.gz')
|
60 | 60 | expected_re = (" (int16|[<>]i2) \[128, 96, 24, 2\] "
|
61 |
| - "2.00x2.00x2.20x2000.00 #exts: 2 sform$") |
62 |
| - cmd = ['nib-ls', fname] |
| 61 | + "2.00x2.00x2.20x2000.00 #exts: 2%s sform$" |
| 62 | + % hdrs_str) |
| 63 | + cmd = ['nib-ls'] + opts + [fname] |
63 | 64 | code, stdout, stderr = run_command(cmd)
|
64 | 65 | assert_equal(fname, stdout[:len(fname)])
|
65 |
| - assert_not_equal(re.match(expected_re, stdout[len(fname):]), None) |
| 66 | + assert_re_in(expected_re, stdout[len(fname):]) |
| 67 | + |
| 68 | +@script_test |
| 69 | +def test_nib_ls(): |
| 70 | + yield check_nib_ls_example4d |
| 71 | + yield check_nib_ls_example4d, \ |
| 72 | + ['-H', 'dim,bitpix'], " \[ 4 128 96 24 2 1 1 1\] 16" |
| 73 | + |
| 74 | +@script_test |
| 75 | +def test_nib_ls_multiple(): |
| 76 | + # verify that correctly lists/formats for multiple files |
| 77 | + fnames = [ |
| 78 | + pjoin(DATA_PATH, f) |
| 79 | + for f in ('example4d.nii.gz', 'example_nifti2.nii.gz', |
| 80 | + 'small.mnc', 'nifti2.hdr') |
| 81 | + ] |
| 82 | + code, stdout, stderr = run_command(['nib-ls'] + fnames) |
| 83 | + stdout_lines = stdout.split('\n') |
| 84 | + assert_equal(len(stdout_lines), 4) |
| 85 | + try: |
| 86 | + load(pjoin(DATA_PATH, 'small.mnc')) |
| 87 | + except: |
| 88 | + raise SkipTest("For the other tests should be able to load MINC files") |
| 89 | + |
| 90 | + # they should be indented correctly. Since all files are int type - |
| 91 | + ln = max(len(f) for f in fnames) |
| 92 | + assert_equal([l[ln:ln+2] for l in stdout_lines], [' i']*4, |
| 93 | + msg="Type sub-string didn't start with 'i'. " |
| 94 | + "Full output was: %s" % stdout_lines) |
| 95 | + # and if disregard type indicator which might vary |
| 96 | + assert_equal( |
| 97 | + [l[l.index('['):] for l in stdout_lines], |
| 98 | + [ |
| 99 | + '[128, 96, 24, 2] 2.00x2.00x2.20x2000.00 #exts: 2 sform', |
| 100 | + '[ 32, 20, 12, 2] 2.00x2.00x2.20x2000.00 #exts: 2 sform', |
| 101 | + '[ 18, 28, 29] 9.00x8.00x7.00', |
| 102 | + '[ 91, 109, 91] 2.00x2.00x2.00' |
| 103 | + ] |
| 104 | + ) |
| 105 | + |
| 106 | + # Now run with -s for stats |
| 107 | + code, stdout, stderr = run_command(['nib-ls', '-s'] + fnames) |
| 108 | + stdout_lines = stdout.split('\n') |
| 109 | + assert_equal(len(stdout_lines), 4) |
| 110 | + assert_equal( |
| 111 | + [l[l.index('['):] for l in stdout_lines], |
| 112 | + [ |
| 113 | + '[128, 96, 24, 2] 2.00x2.00x2.20x2000.00 #exts: 2 sform [229725] 2:1.2e+03', |
| 114 | + '[ 32, 20, 12, 2] 2.00x2.00x2.20x2000.00 #exts: 2 sform [15360] 46:7.6e+02', |
| 115 | + '[ 18, 28, 29] 9.00x8.00x7.00 [14616] 0.12:93', |
| 116 | + '[ 91, 109, 91] 2.00x2.00x2.00 error' |
| 117 | + ] |
| 118 | + ) |
| 119 | + |
66 | 120 |
|
67 | 121 |
|
68 | 122 | @script_test
|
|
0 commit comments