|
25 | 25 |
|
26 | 26 | from .scriptrunner import ScriptRunner
|
27 | 27 | from .nibabel_data import needs_nibabel_data
|
28 |
| -from ..testing import assert_dt_equal |
| 28 | +from ..testing import assert_dt_equal, assert_re_in |
29 | 29 | from .test_parrec import (DTI_PAR_BVECS, DTI_PAR_BVALS,
|
30 | 30 | EXAMPLE_IMAGES as PARREC_EXAMPLES)
|
31 | 31 | from .test_parrec_data import BALLS, AFF_OFF
|
@@ -54,15 +54,60 @@ def script_test(func):
|
54 | 54 |
|
55 | 55 |
|
56 | 56 | @script_test
|
57 |
| -def test_nib_ls(): |
| 57 | +def _test_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 _test_nib_ls_example4d |
| 71 | + yield _test_nib_ls_example4d, ['-H', 'dim,bitpix'], " \[ 4 128 96 24 2 1 1 1\] 16" |
| 72 | + |
| 73 | +@script_test |
| 74 | +def test_nib_ls_multiple(): |
| 75 | + # verify that correctly lists/formats for multiple files |
| 76 | + fnames = [ |
| 77 | + pjoin(DATA_PATH, f) |
| 78 | + for f in ('example4d.nii.gz', 'example_nifti2.nii.gz', 'small.mnc', 'nifti2.hdr') |
| 79 | + ] |
| 80 | + code, stdout, stderr = run_command(['nib-ls'] + fnames) |
| 81 | + stdout_lines = stdout.split('\n') |
| 82 | + assert_equal(len(stdout_lines), 4) |
| 83 | + # they should be indented correctly. Since all files are int type - |
| 84 | + ln = max(len(f) for f in fnames) |
| 85 | + assert_equal([l[ln:ln+2] for l in stdout_lines], [' i']*4) |
| 86 | + # and if disregard type indicator which might vary |
| 87 | + assert_equal( |
| 88 | + [l[l.index('['):] for l in stdout_lines], |
| 89 | + [ |
| 90 | + '[128, 96, 24, 2] 2.00x2.00x2.20x2000.00 #exts: 2 sform', |
| 91 | + '[ 32, 20, 12, 2] 2.00x2.00x2.20x2000.00 #exts: 2 sform', |
| 92 | + '[ 18, 28, 29] 9.00x8.00x7.00', |
| 93 | + '[ 91, 109, 91] 2.00x2.00x2.00' |
| 94 | + ] |
| 95 | + ) |
| 96 | + |
| 97 | + # Now run with -s for stats |
| 98 | + code, stdout, stderr = run_command(['nib-ls', '-s'] + fnames) |
| 99 | + stdout_lines = stdout.split('\n') |
| 100 | + assert_equal(len(stdout_lines), 4) |
| 101 | + assert_equal( |
| 102 | + [l[l.index('['):] for l in stdout_lines], |
| 103 | + [ |
| 104 | + '[128, 96, 24, 2] 2.00x2.00x2.20x2000.00 #exts: 2 sform [229725] 2:1.2e+03', |
| 105 | + '[ 32, 20, 12, 2] 2.00x2.00x2.20x2000.00 #exts: 2 sform [15360] 46:7.6e+02', |
| 106 | + '[ 18, 28, 29] 9.00x8.00x7.00 [14616] 0.12:93', |
| 107 | + '[ 91, 109, 91] 2.00x2.00x2.00 error' |
| 108 | + ] |
| 109 | + ) |
| 110 | + |
66 | 111 |
|
67 | 112 |
|
68 | 113 | @script_test
|
|
0 commit comments