Skip to content

Commit 7d529e0

Browse files
committed
changing %s to format in test_maths (in all places that the strings are used only locally in test functions)
1 parent a3cf60d commit 7d529e0

File tree

1 file changed

+45
-45
lines changed

1 file changed

+45
-45
lines changed

nipype/interfaces/fsl/tests/test_maths.py

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -77,23 +77,23 @@ def test_maths_base(create_files_in_directory):
7777

7878
# Set an in file
7979
maths.inputs.in_file = "a.nii"
80-
out_file = "a_maths%s" % out_ext
80+
out_file = "a_maths{}".format(out_ext)
8181

8282
# 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))
8484

8585
# Now test that we can set the various data types
8686
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 {}"
9090
for dtype in dtypes:
9191
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)
9393
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)
9595
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)
9797

9898
# Test that we can ask for an outfile name
9999
maths.inputs.out_file = "b.nii"
@@ -124,10 +124,10 @@ def test_changedt(create_files_in_directory):
124124

125125
# Now test that we can set the various data types
126126
dtypes = ["float", "char", "int", "short", "double", "input"]
127-
cmdline = "fslmaths a.nii b.nii -odt %s"
127+
cmdline = "fslmaths a.nii b.nii -odt {}"
128128
for dtype in dtypes:
129129
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)
131131

132132

133133
@pytest.mark.skipif(no_fsl(), reason="fsl is not installed")
@@ -145,22 +145,22 @@ def test_threshold(create_files_in_directory):
145145
thresh.run()
146146

147147
# Test the various opstrings
148-
cmdline = "fslmaths a.nii %s b.nii"
148+
cmdline = "fslmaths a.nii {} b.nii"
149149
for val in [0, 0., -1, -1.5, -0.5, 0.5, 3, 400, 400.5]:
150150
thresh.inputs.thresh = val
151-
assert thresh.cmdline == cmdline % "-thr %.10f" % val
151+
assert thresh.cmdline == cmdline.format("-thr {:.10f}".format(val))
152152

153-
val = "%.10f" % 42
153+
val = "{:.10f}".format(42)
154154
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)
156156
thresh.inputs.use_nonzero_voxels = True
157-
assert thresh.cmdline == cmdline % ("-thrP " + val)
157+
assert thresh.cmdline == cmdline.format("-thrP " + val)
158158
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)
160160
thresh.inputs.use_robust_range = True
161-
assert thresh.cmdline == cmdline % ("-uthrp " + val)
161+
assert thresh.cmdline == cmdline.format("-uthrp " + val)
162162
thresh.inputs.use_nonzero_voxels = True
163-
assert thresh.cmdline == cmdline % ("-uthrP " + val)
163+
assert thresh.cmdline == cmdline.format("-uthrP " + val)
164164

165165

166166
@pytest.mark.skipif(no_fsl(), reason="fsl is not installed")
@@ -177,14 +177,14 @@ def test_meanimage(create_files_in_directory):
177177
assert meaner.cmdline == "fslmaths a.nii -Tmean b.nii"
178178

179179
# Test the other dimensions
180-
cmdline = "fslmaths a.nii -%smean b.nii"
180+
cmdline = "fslmaths a.nii -{}mean b.nii"
181181
for dim in ["X", "Y", "Z", "T"]:
182182
meaner.inputs.dimension = dim
183-
assert meaner.cmdline == cmdline % dim
183+
assert meaner.cmdline == cmdline.format(dim)
184184

185185
# Test the auto naming
186186
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)))
188188

189189

190190
@pytest.mark.skipif(no_fsl(), reason="fsl is not installed")
@@ -201,14 +201,14 @@ def test_stdimage(create_files_in_directory):
201201
assert stder.cmdline == "fslmaths a.nii -Tstd b.nii"
202202

203203
# Test the other dimensions
204-
cmdline = "fslmaths a.nii -%sstd b.nii"
204+
cmdline = "fslmaths a.nii -{}std b.nii"
205205
for dim in ["X","Y","Z","T"]:
206206
stder.inputs.dimension=dim
207-
assert stder.cmdline == cmdline%dim
207+
assert stder.cmdline == cmdline.format(dim)
208208

209209
# Test the auto naming
210210
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"))
212212

213213

214214
@pytest.mark.skipif(no_fsl(), reason="fsl is not installed")
@@ -225,14 +225,14 @@ def test_maximage(create_files_in_directory):
225225
assert maxer.cmdline == "fslmaths a.nii -Tmax b.nii"
226226

227227
# Test the other dimensions
228-
cmdline = "fslmaths a.nii -%smax b.nii"
228+
cmdline = "fslmaths a.nii -{}max b.nii"
229229
for dim in ["X", "Y", "Z", "T"]:
230230
maxer.inputs.dimension = dim
231-
assert maxer.cmdline == cmdline % dim
231+
assert maxer.cmdline == cmdline.format(dim)
232232

233233
# Test the auto naming
234234
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)))
236236

237237

238238
@pytest.mark.skipif(no_fsl(), reason="fsl is not installed")
@@ -250,17 +250,17 @@ def test_smooth(create_files_in_directory):
250250
smoother.run()
251251

252252
# Test smoothing kernels
253-
cmdline = "fslmaths a.nii -s %.5f b.nii"
253+
cmdline = "fslmaths a.nii -s {:.5f} b.nii"
254254
for val in [0, 1., 1, 25, 0.5, 8 / 3.]:
255255
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)
257257
smoother = fsl.IsotropicSmooth(in_file="a.nii", out_file="b.nii", fwhm=val)
258258
val = float(val) / np.sqrt(8 * np.log(2))
259-
assert smoother.cmdline == cmdline % val
259+
assert smoother.cmdline == cmdline.format(val)
260260

261261
# Test automatic naming
262262
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)))
264264

265265

266266
@pytest.mark.skipif(no_fsl(), reason="fsl is not installed")
@@ -283,7 +283,7 @@ def test_mask(create_files_in_directory):
283283

284284
# Test auto name generation
285285
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))
287287

288288

289289
@pytest.mark.skipif(no_fsl(), reason="fsl is not installed")
@@ -304,14 +304,14 @@ def test_dilation(create_files_in_directory):
304304
for op in ["mean", "modal", "max"]:
305305
cv = dict(mean="M", modal="D", max="F")
306306
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])
308308

309309
# Now test the different kernel options
310310
for k in ["3D", "2D", "box", "boxv", "gauss", "sphere"]:
311311
for size in [1, 1.5, 5]:
312312
diller.inputs.kernel_shape = k
313313
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)
315315

316316
# Test that we can use a file kernel
317317
f = open("kernel.txt", "w").close()
@@ -323,7 +323,7 @@ def test_dilation(create_files_in_directory):
323323

324324
# Test that we don't need to request an out name
325325
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)))
327327

328328

329329
@pytest.mark.skipif(no_fsl(), reason="fsl is not installed")
@@ -345,7 +345,7 @@ def test_erosion(create_files_in_directory):
345345

346346
# Test that we don't need to request an out name
347347
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)))
349349

350350

351351
@pytest.mark.skipif(no_fsl(), reason="fsl is not installed")
@@ -365,11 +365,11 @@ def test_spatial_filter(create_files_in_directory):
365365
# Test the different operations
366366
for op in ["mean", "meanu", "median"]:
367367
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)
369369

370370
# Test that we don't need to ask for an out name
371371
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)))
373373

374374

375375
@pytest.mark.skipif(no_fsl(), reason="fsl is not installed")
@@ -390,12 +390,12 @@ def test_unarymaths(create_files_in_directory):
390390
ops = ["exp", "log", "sin", "cos", "sqr", "sqrt", "recip", "abs", "bin", "index"]
391391
for op in ops:
392392
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)
394394

395395
# Test that we don't need to ask for an out file
396396
for op in ops:
397397
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)))
399399

400400

401401
@pytest.mark.skipif(no_fsl(), reason="fsl is not installed")
@@ -420,15 +420,15 @@ def test_binarymaths(create_files_in_directory):
420420
maths = fsl.BinaryMaths(in_file="a.nii", out_file="c.nii", operation=op)
421421
if ent == "b.nii":
422422
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)
424424
else:
425425
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)
427427

428428
# Test that we don't need to ask for an out file
429429
for op in ops:
430430
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)))
432432

433433

434434
@pytest.mark.skipif(no_fsl(), reason="fsl is not installed")
@@ -478,12 +478,12 @@ def test_tempfilt(create_files_in_directory):
478478
for win in windows:
479479
filt.inputs.highpass_sigma = win[0]
480480
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])
482482

483483
# Test that we don't need to ask for an out file
484484
filt = fsl.TemporalFilter(in_file="a.nii", highpass_sigma=64)
485485
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)))
487487

488488

489489

0 commit comments

Comments
 (0)