5
5
import pytest
6
6
import numpy as np
7
7
from subprocess import check_call
8
+ import shutil
8
9
9
10
import nibabel as nb
10
11
from nibabel .eulerangles import euler2mat
30
31
}
31
32
32
33
34
+ @pytest .mark .xfail (reason = "Not fully implemented" )
33
35
@pytest .mark .parametrize ('image_orientation' , [
34
36
'RAS' , 'LAS' , 'LPS' , # 'oblique',
35
37
])
@@ -52,25 +54,26 @@ def test_linear_load(tmpdir, data_path, get_data, image_orientation, sw_tool):
52
54
53
55
fname = 'affine-%s.%s%s' % (image_orientation , sw_tool , ext )
54
56
xfm_fname = os .path .join (data_path , fname )
57
+ fmt = fname .split ('.' )[- 1 ]
55
58
56
59
if sw_tool == 'fsl' :
57
- with pytest .raises (" ValueError" ):
58
- loaded = nbl .load (xfm_fname , fmt = fname . split ( '.' )[ - 1 ] )
59
- with pytest .raises (" ValueError" ):
60
- loaded = nbl .load (xfm_fname , fmt = fname . split ( '.' )[ - 1 ],
61
- reference = 'img.nii.gz' )
62
- with pytest . raises ( "ValueError" ):
63
- loaded = nbl . load ( xfm_fname , fmt = fname . split ( '.' )[ - 1 ],
64
- moving = 'img.nii.gz' )
65
-
66
- loaded = nbl . load ( xfm_fname , fmt = fname . split ( '.' )[ - 1 ],
67
- moving = 'img.nii.gz' , reference = 'img.nii.gz' )
68
- if sw_tool == 'afni' :
69
- with pytest . raises ( "ValueError" ):
70
- loaded = nbl . load ( xfm_fname , fmt = fname . split ( '.' )[ - 1 ])
71
-
72
- loaded = nbl . load ( xfm_fname , fmt = fname . split ( '.' )[ - 1 ],
73
- reference = 'img.nii.gz' )
60
+ with pytest .raises (ValueError ):
61
+ loaded = nbl .load (xfm_fname , fmt = fmt )
62
+ with pytest .raises (ValueError ):
63
+ loaded = nbl .load (xfm_fname , fmt = fmt , reference = 'img.nii.gz' )
64
+ with pytest . raises ( ValueError ):
65
+ loaded = nbl . load ( xfm_fname , fmt = fmt , moving = 'img.nii.gz' )
66
+
67
+ loaded = nbl . load (
68
+ xfm_fname , fmt = fmt , moving = 'img.nii.gz' , reference = 'img.nii.gz'
69
+ )
70
+ elif sw_tool == 'afni' :
71
+ with pytest . raises ( ValueError ) :
72
+ loaded = nbl . load ( xfm_fname , fmt = fmt )
73
+
74
+ loaded = nbl . load ( xfm_fname , fmt = fmt , reference = 'img.nii.gz' )
75
+ elif sw_tool == 'itk' :
76
+ loaded = nbl . load ( xfm_fname , fmt = fmt )
74
77
75
78
assert loaded == xfm
76
79
@@ -132,6 +135,12 @@ def test_apply_linear_transform(
132
135
transform = os .path .abspath (xfm_fname ),
133
136
reference = os .path .abspath ('img.nii.gz' ),
134
137
moving = os .path .abspath ('img.nii.gz' ))
138
+
139
+ # skip test if command is not available on host
140
+ exe = cmd .split (" " , 1 )[0 ]
141
+ if not shutil .which (exe ):
142
+ pytest .skip ("Command {} not found on host" .format (exe ))
143
+
135
144
exit_code = check_call ([cmd ], shell = True )
136
145
assert exit_code == 0
137
146
sw_moved = nb .load ('resampled.nii.gz' )
0 commit comments