|
7 | 7 | import nipype.interfaces.spm.utils as spmu
|
8 | 8 | from nipype.interfaces.base import isdefined
|
9 | 9 | from nipype.utils.filemanip import split_filename, fname_presuffix
|
10 |
| - |
| 10 | +from nipype.interfaces.base import TraitError |
11 | 11 |
|
12 | 12 | def test_coreg():
|
13 | 13 | moving = example_data(infile = 'functional.nii')
|
14 | 14 | target = example_data(infile = 'T1.nii')
|
15 | 15 | mat = example_data(infile = 'trans.mat')
|
16 | 16 | coreg = spmu.CalcCoregAffine(matlab_cmd = 'mymatlab')
|
17 | 17 | coreg.inputs.target = target
|
18 |
| - yield assert_equal, coreg.inputs.matlab_cmd, 'mymatlab' |
| 18 | + assert_equal(coreg.inputs.matlab_cmd, 'mymatlab') |
19 | 19 | coreg.inputs.moving = moving
|
20 |
| - yield assert_equal, isdefined(coreg.inputs.mat),False |
| 20 | + assert_equal( isdefined(coreg.inputs.mat),False) |
21 | 21 | pth, mov, _ = split_filename(moving)
|
22 | 22 | _, tgt, _ = split_filename(target)
|
23 | 23 | mat = os.path.join(pth, '%s_to_%s.mat'%(mov,tgt))
|
24 | 24 | invmat = fname_presuffix(mat, prefix = 'inverse_')
|
25 | 25 | 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) |
28 | 28 |
|
29 | 29 |
|
30 | 30 | def test_apply_transform():
|
31 | 31 | moving = example_data(infile = 'functional.nii')
|
32 | 32 | mat = example_data(infile = 'trans.mat')
|
33 | 33 | applymat = spmu.ApplyTransform(matlab_cmd = 'mymatlab')
|
34 |
| - yield assert_equal, applymat.inputs.matlab_cmd, 'mymatlab' |
| 34 | + assert_equal( applymat.inputs.matlab_cmd, 'mymatlab' ) |
35 | 35 | applymat.inputs.in_file = moving
|
36 | 36 | applymat.inputs.mat = mat
|
37 | 37 | scrpt = applymat._make_matlab_command(None)
|
38 | 38 | expected = 'img_space = spm_get_space(infile);'
|
39 |
| - yield assert_equal, expected in scrpt, True |
| 39 | + assert_equal( expected in scrpt, True) |
40 | 40 | expected = 'spm_get_space(infile, transform.M * img_space);'
|
41 |
| - yield assert_equal, expected in scrpt, True |
| 41 | + assert_equal(expected in scrpt, True) |
42 | 42 |
|
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