@@ -75,61 +75,35 @@ def test_ApplyMask(tmp_path):
75
75
ApplyMask (in_file = str (in_file4d ), in_mask = str (in_mask ), threshold = 0.4 ).run ()
76
76
77
77
78
- def test_SplitSeries (tmp_path ):
78
+ @pytest .mark .parametrize ("shape,exp_n" , [
79
+ ((20 , 20 , 20 , 15 ), 15 ),
80
+ ((20 , 20 , 20 ), 1 ),
81
+ ((20 , 20 , 20 , 1 ), 1 ),
82
+ ((20 , 20 , 20 , 1 , 3 ), 3 ),
83
+ ((20 , 20 , 20 , 3 , 1 ), 3 ),
84
+ ((20 , 20 , 20 , 1 , 3 , 3 ), - 1 ),
85
+ ((20 , 1 , 20 , 15 ), 15 ),
86
+ ((20 , 1 , 20 ), 1 ),
87
+ ((20 , 1 , 20 , 1 ), 1 ),
88
+ ((20 , 1 , 20 , 1 , 3 ), 3 ),
89
+ ((20 , 1 , 20 , 3 , 1 ), 3 ),
90
+ ((20 , 1 , 20 , 1 , 3 , 3 ), - 1 ),
91
+ ])
92
+ def test_SplitSeries (tmp_path , shape , exp_n ):
79
93
"""Test 4-to-3 NIfTI split interface."""
80
94
os .chdir (tmp_path )
81
95
82
- # Test the 4D
83
- data = np .ones ((20 , 20 , 20 , 15 ), dtype = float )
84
- in_file = tmp_path / "input4D.nii.gz"
85
- nb .Nifti1Image (data , np .eye (4 ), None ).to_filename (str (in_file ))
86
-
87
- split = SplitSeries (in_file = str (in_file )).run ()
88
- assert len (split .outputs .out_files ) == 15
89
-
90
- # Test the 3D
91
- in_file = tmp_path / "input3D.nii.gz"
92
- nb .Nifti1Image (np .ones ((20 , 20 , 20 ), dtype = float ), np .eye (4 ), None ).to_filename (
93
- str (in_file )
94
- )
95
-
96
- with pytest .raises (RuntimeError ):
97
- SplitSeries (in_file = str (in_file )).run ()
98
-
99
- split = SplitSeries (in_file = str (in_file ), allow_3D = True ).run ()
100
- assert isinstance (split .outputs .out_files , str )
101
-
102
- # Test the 3D
103
- in_file = tmp_path / "input3D.nii.gz"
104
- nb .Nifti1Image (np .ones ((20 , 20 , 20 , 1 ), dtype = float ), np .eye (4 ), None ).to_filename (
105
- str (in_file )
106
- )
107
-
108
- with pytest .raises (RuntimeError ):
109
- SplitSeries (in_file = str (in_file )).run ()
110
-
111
- split = SplitSeries (in_file = str (in_file ), allow_3D = True ).run ()
112
- assert isinstance (split .outputs .out_files , str )
113
-
114
- # Test the 5D
115
- in_file = tmp_path / "input5D.nii.gz"
116
- nb .Nifti1Image (
117
- np .ones ((20 , 20 , 20 , 2 , 2 ), dtype = float ), np .eye (4 ), None
118
- ).to_filename (str (in_file ))
119
-
120
- with pytest .raises (RuntimeError ):
121
- SplitSeries (in_file = str (in_file )).run ()
122
-
123
- with pytest .raises (RuntimeError ):
124
- SplitSeries (in_file = str (in_file ), allow_3D = True ).run ()
125
-
126
- # Test splitting ANTs warpfields
127
- data = np .ones ((20 , 20 , 20 , 1 , 3 ), dtype = float )
128
- in_file = tmp_path / "warpfield.nii.gz"
129
- nb .Nifti1Image (data , np .eye (4 ), None ).to_filename (str (in_file ))
130
-
131
- split = SplitSeries (in_file = str (in_file )).run ()
132
- assert len (split .outputs .out_files ) == 3
96
+ in_file = str (tmp_path / "input.nii.gz" )
97
+ nb .Nifti1Image (np .ones (shape , dtype = float ), np .eye (4 ), None ).to_filename (in_file )
98
+
99
+ _interface = SplitSeries (in_file = in_file )
100
+ if exp_n > 0 :
101
+ split = _interface .run ()
102
+ n = int (isinstance (split .outputs .out_files , str )) or len (split .outputs .out_files )
103
+ assert n == exp_n
104
+ else :
105
+ with pytest .raises (ValueError ):
106
+ _interface .run ()
133
107
134
108
135
109
def test_MergeSeries (tmp_path ):
0 commit comments