Skip to content

Commit cbf4bcc

Browse files
author
CindeeM
committed
TEST: added tests for spm utils reslice
1 parent 1a2f11f commit cbf4bcc

File tree

1 file changed

+27
-9
lines changed

1 file changed

+27
-9
lines changed

nipype/interfaces/spm/tests/test_utils.py

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,37 +7,55 @@
77
import nipype.interfaces.spm.utils as spmu
88
from nipype.interfaces.base import isdefined
99
from nipype.utils.filemanip import split_filename, fname_presuffix
10-
10+
from nipype.interfaces.base import TraitError
1111

1212
def test_coreg():
1313
moving = example_data(infile = 'functional.nii')
1414
target = example_data(infile = 'T1.nii')
1515
mat = example_data(infile = 'trans.mat')
1616
coreg = spmu.CalcCoregAffine(matlab_cmd = 'mymatlab')
1717
coreg.inputs.target = target
18-
yield assert_equal, coreg.inputs.matlab_cmd, 'mymatlab'
18+
assert_equal(coreg.inputs.matlab_cmd, 'mymatlab')
1919
coreg.inputs.moving = moving
20-
yield assert_equal, isdefined(coreg.inputs.mat),False
20+
assert_equal( isdefined(coreg.inputs.mat),False)
2121
pth, mov, _ = split_filename(moving)
2222
_, tgt, _ = split_filename(target)
2323
mat = os.path.join(pth, '%s_to_%s.mat'%(mov,tgt))
2424
invmat = fname_presuffix(mat, prefix = 'inverse_')
2525
scrpt = coreg._make_matlab_command(None)
26-
yield assert_equal, coreg.inputs.mat, mat
27-
yield assert_equal, coreg.inputs.invmat, invmat
26+
assert_equal(coreg.inputs.mat, mat)
27+
assert_equal( coreg.inputs.invmat, invmat)
2828

2929

3030
def test_apply_transform():
3131
moving = example_data(infile = 'functional.nii')
3232
mat = example_data(infile = 'trans.mat')
3333
applymat = spmu.ApplyTransform(matlab_cmd = 'mymatlab')
34-
yield assert_equal, applymat.inputs.matlab_cmd, 'mymatlab'
34+
assert_equal( applymat.inputs.matlab_cmd, 'mymatlab' )
3535
applymat.inputs.in_file = moving
3636
applymat.inputs.mat = mat
3737
scrpt = applymat._make_matlab_command(None)
3838
expected = 'img_space = spm_get_space(infile);'
39-
yield assert_equal, expected in scrpt, True
39+
assert_equal( expected in scrpt, True)
4040
expected = 'spm_get_space(infile, transform.M * img_space);'
41-
yield assert_equal, expected in scrpt, True
41+
assert_equal(expected in scrpt, True)
4242

43-
43+
def test_reslice():
44+
moving = example_data(infile = 'functional.nii')
45+
space_defining = example_data(infile = 'T1.nii')
46+
reslice = spmu.Reslice(matlab_cmd = 'mymatlab_version')
47+
assert_equal( reslice.inputs.matlab_cmd, 'mymatlab_version')
48+
reslice.inputs.in_file = moving
49+
reslice.inputs.space_defining = space_defining
50+
assert_equal( reslice.inputs.interp, 0)
51+
assert_raises(TraitError,reslice.inputs.trait_set,interp = 'nearest')
52+
assert_raises(TraitError, reslice.inputs.trait_set, interp = 10)
53+
reslice.inputs.interp = 1
54+
script = reslice._make_matlab_command(None)
55+
outfile = fname_presuffix(moving, prefix='r')
56+
assert_equal(reslice.inputs.out_file, outfile)
57+
expected = '\nflags.mean=0;\nflags.which=1;\nflags.mask=0;'
58+
assert_equal(expected in script.replace(' ',''), True)
59+
expected_interp = 'flags.interp = 1;\n'
60+
assert_equal(expected_interp in script, True)
61+
assert_equal('spm_reslice(invols, flags);' in script, True)

0 commit comments

Comments
 (0)