@@ -77,23 +77,23 @@ def test_maths_base(create_files_in_directory):
77
77
78
78
# Set an in file
79
79
maths .inputs .in_file = "a.nii"
80
- out_file = "a_maths%s" % out_ext
80
+ out_file = "a_maths{}" . format ( out_ext )
81
81
82
82
# Now test the most basic command line
83
- assert maths .cmdline == "fslmaths a.nii %s" % os .path .join (testdir , out_file )
83
+ assert maths .cmdline == "fslmaths a.nii {}" . format ( os .path .join (testdir , out_file ) )
84
84
85
85
# Now test that we can set the various data types
86
86
dtypes = ["float" , "char" , "int" , "short" , "double" , "input" ]
87
- int_cmdline = "fslmaths -dt %s a.nii " + os .path .join (testdir , out_file )
88
- out_cmdline = "fslmaths a.nii " + os .path .join (testdir , out_file ) + " -odt %s "
89
- duo_cmdline = "fslmaths -dt %s a.nii " + os .path .join (testdir , out_file ) + " -odt %s "
87
+ int_cmdline = "fslmaths -dt {} a.nii " + os .path .join (testdir , out_file )
88
+ out_cmdline = "fslmaths a.nii " + os .path .join (testdir , out_file ) + " -odt {} "
89
+ duo_cmdline = "fslmaths -dt {} a.nii " + os .path .join (testdir , out_file ) + " -odt {} "
90
90
for dtype in dtypes :
91
91
foo = fsl .MathsCommand (in_file = "a.nii" , internal_datatype = dtype )
92
- assert foo .cmdline == int_cmdline % dtype
92
+ assert foo .cmdline == int_cmdline . format ( dtype )
93
93
bar = fsl .MathsCommand (in_file = "a.nii" , output_datatype = dtype )
94
- assert bar .cmdline == out_cmdline % dtype
94
+ assert bar .cmdline == out_cmdline . format ( dtype )
95
95
foobar = fsl .MathsCommand (in_file = "a.nii" , internal_datatype = dtype , output_datatype = dtype )
96
- assert foobar .cmdline == duo_cmdline % (dtype , dtype )
96
+ assert foobar .cmdline == duo_cmdline . format (dtype , dtype )
97
97
98
98
# Test that we can ask for an outfile name
99
99
maths .inputs .out_file = "b.nii"
@@ -124,10 +124,10 @@ def test_changedt(create_files_in_directory):
124
124
125
125
# Now test that we can set the various data types
126
126
dtypes = ["float" , "char" , "int" , "short" , "double" , "input" ]
127
- cmdline = "fslmaths a.nii b.nii -odt %s "
127
+ cmdline = "fslmaths a.nii b.nii -odt {} "
128
128
for dtype in dtypes :
129
129
foo = fsl .MathsCommand (in_file = "a.nii" , out_file = "b.nii" , output_datatype = dtype )
130
- assert foo .cmdline == cmdline % dtype
130
+ assert foo .cmdline == cmdline . format ( dtype )
131
131
132
132
133
133
@pytest .mark .skipif (no_fsl (), reason = "fsl is not installed" )
@@ -145,22 +145,22 @@ def test_threshold(create_files_in_directory):
145
145
thresh .run ()
146
146
147
147
# Test the various opstrings
148
- cmdline = "fslmaths a.nii %s b.nii"
148
+ cmdline = "fslmaths a.nii {} b.nii"
149
149
for val in [0 , 0. , - 1 , - 1.5 , - 0.5 , 0.5 , 3 , 400 , 400.5 ]:
150
150
thresh .inputs .thresh = val
151
- assert thresh .cmdline == cmdline % "-thr % .10f" % val
151
+ assert thresh .cmdline == cmdline . format ( "-thr {: .10f}" . format ( val ))
152
152
153
- val = "% .10f" % 42
153
+ val = "{: .10f}" . format ( 42 )
154
154
thresh = fsl .Threshold (in_file = "a.nii" , out_file = "b.nii" , thresh = 42 , use_robust_range = True )
155
- assert thresh .cmdline == cmdline % ("-thrp " + val )
155
+ assert thresh .cmdline == cmdline . format ("-thrp " + val )
156
156
thresh .inputs .use_nonzero_voxels = True
157
- assert thresh .cmdline == cmdline % ("-thrP " + val )
157
+ assert thresh .cmdline == cmdline . format ("-thrP " + val )
158
158
thresh = fsl .Threshold (in_file = "a.nii" , out_file = "b.nii" , thresh = 42 , direction = "above" )
159
- assert thresh .cmdline == cmdline % ("-uthr " + val )
159
+ assert thresh .cmdline == cmdline . format ("-uthr " + val )
160
160
thresh .inputs .use_robust_range = True
161
- assert thresh .cmdline == cmdline % ("-uthrp " + val )
161
+ assert thresh .cmdline == cmdline . format ("-uthrp " + val )
162
162
thresh .inputs .use_nonzero_voxels = True
163
- assert thresh .cmdline == cmdline % ("-uthrP " + val )
163
+ assert thresh .cmdline == cmdline . format ("-uthrP " + val )
164
164
165
165
166
166
@pytest .mark .skipif (no_fsl (), reason = "fsl is not installed" )
@@ -177,14 +177,14 @@ def test_meanimage(create_files_in_directory):
177
177
assert meaner .cmdline == "fslmaths a.nii -Tmean b.nii"
178
178
179
179
# Test the other dimensions
180
- cmdline = "fslmaths a.nii -%smean b.nii"
180
+ cmdline = "fslmaths a.nii -{}mean b.nii"
181
181
for dim in ["X" , "Y" , "Z" , "T" ]:
182
182
meaner .inputs .dimension = dim
183
- assert meaner .cmdline == cmdline % dim
183
+ assert meaner .cmdline == cmdline . format ( dim )
184
184
185
185
# Test the auto naming
186
186
meaner = fsl .MeanImage (in_file = "a.nii" )
187
- assert meaner .cmdline == "fslmaths a.nii -Tmean %s" % os .path .join (testdir , "a_mean%s" % out_ext )
187
+ assert meaner .cmdline == "fslmaths a.nii -Tmean {}" . format ( os .path .join (testdir , "a_mean{}" . format ( out_ext )) )
188
188
189
189
190
190
@pytest .mark .skipif (no_fsl (), reason = "fsl is not installed" )
@@ -201,14 +201,14 @@ def test_stdimage(create_files_in_directory):
201
201
assert stder .cmdline == "fslmaths a.nii -Tstd b.nii"
202
202
203
203
# Test the other dimensions
204
- cmdline = "fslmaths a.nii -%sstd b.nii"
204
+ cmdline = "fslmaths a.nii -{}std b.nii"
205
205
for dim in ["X" ,"Y" ,"Z" ,"T" ]:
206
206
stder .inputs .dimension = dim
207
- assert stder .cmdline == cmdline % dim
207
+ assert stder .cmdline == cmdline . format ( dim )
208
208
209
209
# Test the auto naming
210
210
stder = fsl .StdImage (in_file = "a.nii" , output_type = 'NIFTI' )
211
- assert stder .cmdline == "fslmaths a.nii -Tstd %s" % os .path .join (testdir , "a_std.nii" )
211
+ assert stder .cmdline == "fslmaths a.nii -Tstd {}" . format ( os .path .join (testdir , "a_std.nii" ) )
212
212
213
213
214
214
@pytest .mark .skipif (no_fsl (), reason = "fsl is not installed" )
@@ -225,14 +225,14 @@ def test_maximage(create_files_in_directory):
225
225
assert maxer .cmdline == "fslmaths a.nii -Tmax b.nii"
226
226
227
227
# Test the other dimensions
228
- cmdline = "fslmaths a.nii -%smax b.nii"
228
+ cmdline = "fslmaths a.nii -{}max b.nii"
229
229
for dim in ["X" , "Y" , "Z" , "T" ]:
230
230
maxer .inputs .dimension = dim
231
- assert maxer .cmdline == cmdline % dim
231
+ assert maxer .cmdline == cmdline . format ( dim )
232
232
233
233
# Test the auto naming
234
234
maxer = fsl .MaxImage (in_file = "a.nii" )
235
- assert maxer .cmdline == "fslmaths a.nii -Tmax %s" % os .path .join (testdir , "a_max%s" % out_ext )
235
+ assert maxer .cmdline == "fslmaths a.nii -Tmax {}" . format ( os .path .join (testdir , "a_max{}" . format ( out_ext )) )
236
236
237
237
238
238
@pytest .mark .skipif (no_fsl (), reason = "fsl is not installed" )
@@ -250,17 +250,17 @@ def test_smooth(create_files_in_directory):
250
250
smoother .run ()
251
251
252
252
# Test smoothing kernels
253
- cmdline = "fslmaths a.nii -s % .5f b.nii"
253
+ cmdline = "fslmaths a.nii -s {: .5f} b.nii"
254
254
for val in [0 , 1. , 1 , 25 , 0.5 , 8 / 3. ]:
255
255
smoother = fsl .IsotropicSmooth (in_file = "a.nii" , out_file = "b.nii" , sigma = val )
256
- assert smoother .cmdline == cmdline % val
256
+ assert smoother .cmdline == cmdline . format ( val )
257
257
smoother = fsl .IsotropicSmooth (in_file = "a.nii" , out_file = "b.nii" , fwhm = val )
258
258
val = float (val ) / np .sqrt (8 * np .log (2 ))
259
- assert smoother .cmdline == cmdline % val
259
+ assert smoother .cmdline == cmdline . format ( val )
260
260
261
261
# Test automatic naming
262
262
smoother = fsl .IsotropicSmooth (in_file = "a.nii" , sigma = 5 )
263
- assert smoother .cmdline == "fslmaths a.nii -s % .5f %s" % (5 , os .path .join (testdir , "a_smooth%s" % out_ext ))
263
+ assert smoother .cmdline == "fslmaths a.nii -s {: .5f} {}" . format (5 , os .path .join (testdir , "a_smooth{}" . format ( out_ext ) ))
264
264
265
265
266
266
@pytest .mark .skipif (no_fsl (), reason = "fsl is not installed" )
@@ -283,7 +283,7 @@ def test_mask(create_files_in_directory):
283
283
284
284
# Test auto name generation
285
285
masker = fsl .ApplyMask (in_file = "a.nii" , mask_file = "b.nii" )
286
- assert masker .cmdline == "fslmaths a.nii -mas b.nii " + os .path .join (testdir , "a_masked%s" % out_ext )
286
+ assert masker .cmdline == "fslmaths a.nii -mas b.nii " + os .path .join (testdir , "a_masked{}" . format ( out_ext ) )
287
287
288
288
289
289
@pytest .mark .skipif (no_fsl (), reason = "fsl is not installed" )
@@ -304,14 +304,14 @@ def test_dilation(create_files_in_directory):
304
304
for op in ["mean" , "modal" , "max" ]:
305
305
cv = dict (mean = "M" , modal = "D" , max = "F" )
306
306
diller .inputs .operation = op
307
- assert diller .cmdline == "fslmaths a.nii -dil%s b.nii" % cv [op ]
307
+ assert diller .cmdline == "fslmaths a.nii -dil{} b.nii" . format ( cv [op ])
308
308
309
309
# Now test the different kernel options
310
310
for k in ["3D" , "2D" , "box" , "boxv" , "gauss" , "sphere" ]:
311
311
for size in [1 , 1.5 , 5 ]:
312
312
diller .inputs .kernel_shape = k
313
313
diller .inputs .kernel_size = size
314
- assert diller .cmdline == "fslmaths a.nii -kernel %s % .4f -dilF b.nii" % (k , size )
314
+ assert diller .cmdline == "fslmaths a.nii -kernel {} {: .4f} -dilF b.nii" . format (k , size )
315
315
316
316
# Test that we can use a file kernel
317
317
f = open ("kernel.txt" , "w" ).close ()
@@ -323,7 +323,7 @@ def test_dilation(create_files_in_directory):
323
323
324
324
# Test that we don't need to request an out name
325
325
dil = fsl .DilateImage (in_file = "a.nii" , operation = "max" )
326
- assert dil .cmdline == "fslmaths a.nii -dilF %s" % os .path .join (testdir , "a_dil%s" % out_ext )
326
+ assert dil .cmdline == "fslmaths a.nii -dilF {}" . format ( os .path .join (testdir , "a_dil{}" . format ( out_ext )) )
327
327
328
328
329
329
@pytest .mark .skipif (no_fsl (), reason = "fsl is not installed" )
@@ -345,7 +345,7 @@ def test_erosion(create_files_in_directory):
345
345
346
346
# Test that we don't need to request an out name
347
347
erode = fsl .ErodeImage (in_file = "a.nii" )
348
- assert erode .cmdline == "fslmaths a.nii -ero %s" % os .path .join (testdir , "a_ero%s" % out_ext )
348
+ assert erode .cmdline == "fslmaths a.nii -ero {}" . format ( os .path .join (testdir , "a_ero{}" . format ( out_ext )) )
349
349
350
350
351
351
@pytest .mark .skipif (no_fsl (), reason = "fsl is not installed" )
@@ -365,11 +365,11 @@ def test_spatial_filter(create_files_in_directory):
365
365
# Test the different operations
366
366
for op in ["mean" , "meanu" , "median" ]:
367
367
filter .inputs .operation = op
368
- assert filter .cmdline == "fslmaths a.nii -f%s b.nii" % op
368
+ assert filter .cmdline == "fslmaths a.nii -f{} b.nii" . format ( op )
369
369
370
370
# Test that we don't need to ask for an out name
371
371
filter = fsl .SpatialFilter (in_file = "a.nii" , operation = "mean" )
372
- assert filter .cmdline == "fslmaths a.nii -fmean %s" % os .path .join (testdir , "a_filt%s" % out_ext )
372
+ assert filter .cmdline == "fslmaths a.nii -fmean {}" . format ( os .path .join (testdir , "a_filt{}" . format ( out_ext )) )
373
373
374
374
375
375
@pytest .mark .skipif (no_fsl (), reason = "fsl is not installed" )
@@ -390,12 +390,12 @@ def test_unarymaths(create_files_in_directory):
390
390
ops = ["exp" , "log" , "sin" , "cos" , "sqr" , "sqrt" , "recip" , "abs" , "bin" , "index" ]
391
391
for op in ops :
392
392
maths .inputs .operation = op
393
- assert maths .cmdline == "fslmaths a.nii -%s b.nii" % op
393
+ assert maths .cmdline == "fslmaths a.nii -{} b.nii" . format ( op )
394
394
395
395
# Test that we don't need to ask for an out file
396
396
for op in ops :
397
397
maths = fsl .UnaryMaths (in_file = "a.nii" , operation = op )
398
- assert maths .cmdline == "fslmaths a.nii -%s %s" % (op , os .path .join (testdir , "a_%s%s" % (op , out_ext )))
398
+ assert maths .cmdline == "fslmaths a.nii -{} {}" . format (op , os .path .join (testdir , "a_{}{}" . format (op , out_ext )))
399
399
400
400
401
401
@pytest .mark .skipif (no_fsl (), reason = "fsl is not installed" )
@@ -420,15 +420,15 @@ def test_binarymaths(create_files_in_directory):
420
420
maths = fsl .BinaryMaths (in_file = "a.nii" , out_file = "c.nii" , operation = op )
421
421
if ent == "b.nii" :
422
422
maths .inputs .operand_file = ent
423
- assert maths .cmdline == "fslmaths a.nii -%s b.nii c.nii" % op
423
+ assert maths .cmdline == "fslmaths a.nii -{} b.nii c.nii" . format ( op )
424
424
else :
425
425
maths .inputs .operand_value = ent
426
- assert maths .cmdline == "fslmaths a.nii -%s % .8f c.nii" % (op , ent )
426
+ assert maths .cmdline == "fslmaths a.nii -{} {: .8f} c.nii" . format (op , ent )
427
427
428
428
# Test that we don't need to ask for an out file
429
429
for op in ops :
430
430
maths = fsl .BinaryMaths (in_file = "a.nii" , operation = op , operand_file = "b.nii" )
431
- assert maths .cmdline == "fslmaths a.nii -%s b.nii %s" % (op , os .path .join (testdir , "a_maths%s" % out_ext ))
431
+ assert maths .cmdline == "fslmaths a.nii -{} b.nii {}" . format (op , os .path .join (testdir , "a_maths{}" . format ( out_ext ) ))
432
432
433
433
434
434
@pytest .mark .skipif (no_fsl (), reason = "fsl is not installed" )
@@ -478,12 +478,12 @@ def test_tempfilt(create_files_in_directory):
478
478
for win in windows :
479
479
filt .inputs .highpass_sigma = win [0 ]
480
480
filt .inputs .lowpass_sigma = win [1 ]
481
- assert filt .cmdline == "fslmaths a.nii -bptf % .6f % .6f b.nii" % win
481
+ assert filt .cmdline == "fslmaths a.nii -bptf {: .6f} {: .6f} b.nii" . format ( win [ 0 ], win [ 1 ])
482
482
483
483
# Test that we don't need to ask for an out file
484
484
filt = fsl .TemporalFilter (in_file = "a.nii" , highpass_sigma = 64 )
485
485
assert filt .cmdline == \
486
- "fslmaths a.nii -bptf 64.000000 -1.000000 %s" % os .path .join (testdir , "a_filt%s" % out_ext )
486
+ "fslmaths a.nii -bptf 64.000000 -1.000000 {}" . format ( os .path .join (testdir , "a_filt{}" . format ( out_ext )) )
487
487
488
488
489
489
0 commit comments