Skip to content

Commit 59f2f14

Browse files
committed
Use f-strings
1 parent 902f9a2 commit 59f2f14

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

Tools/iobench/iobench.py

+10-11
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def get_binary_files():
3131

3232

3333
def get_text_files():
34-
return (("%s-%s-%s.txt" % (name, TEXT_ENCODING, NEWLINES), size)
34+
return ((f"{name}-{TEXT_ENCODING}-{NEWLINES}.txt", size)
3535
for name, size in get_file_sizes())
3636

3737

@@ -280,18 +280,17 @@ def run_all_tests(options):
280280
def print_label(filename, func):
281281
name = re.split(r'[-.]', filename)[0]
282282
out.write(
283-
("[%s] %s... "
284-
% (name.center(7), func.__doc__.strip())
285-
).ljust(52))
283+
f"[{name.center(7)}] {func.__doc__.strip()}... ".ljust(52))
286284
out.flush()
287285

288286
def print_results(size, n, real, cpu):
289287
bw = n * float(size) / 1024 ** 2 / real
290288
bw = ("%4d MiB/s" if bw > 100 else "%.3g MiB/s") % bw
291289
out.write(bw.rjust(12) + "\n")
292290
if cpu < 0.90 * real:
293-
out.write(" warning: test above used only %d%% CPU, "
294-
"result may be flawed!\n" % (100.0 * cpu / real))
291+
out.write(" warning: test above used only "
292+
f"{100.0 * cpu / real}% CPU, "
293+
"result may be flawed!\n")
295294

296295
def run_one_test(name, size, open_func, test_func, *args):
297296
mode = test_func.file_open_mode
@@ -322,15 +321,15 @@ def run_test_family(tests, mode_filter, files, open_func, *make_args):
322321
"large": 2,
323322
}
324323

325-
print("Python %s" % sys.version)
324+
print(f"Python {sys.version}")
326325
print("Unicode: PEP 393")
327326
print(platform.platform())
328327
binary_files = list(get_binary_files())
329328
text_files = list(get_text_files())
330329
if "b" in options:
331330
print("Binary unit = one byte")
332331
if "t" in options:
333-
print("Text unit = one character (%s-decoded)" % TEXT_ENCODING)
332+
print(f"Text unit = one character ({TEXT_ENCODING}-decoded)")
334333

335334
# Binary reads
336335
if "b" in options and "r" in options:
@@ -399,7 +398,7 @@ def prepare_files():
399398
break
400399
else:
401400
raise RuntimeError(
402-
"Couldn't find chunk marker in %s !" % __file__)
401+
f"Couldn't find chunk marker in {__file__} !")
403402
if NEWLINES == "all":
404403
it = itertools.cycle(["\n", "\r", "\r\n"])
405404
else:
@@ -445,7 +444,7 @@ def main():
445444
help="run write & modify tests")
446445
parser.add_option("-E", "--encoding",
447446
action="store", dest="encoding", default=None,
448-
help="encoding for text tests (default: %s)" % TEXT_ENCODING)
447+
help=f"encoding for text tests (default: {TEXT_ENCODING})")
449448
parser.add_option("-N", "--newlines",
450449
action="store", dest="newlines", default='lf',
451450
help="line endings for text tests "
@@ -458,7 +457,7 @@ def main():
458457
parser.error("unexpected arguments")
459458
NEWLINES = options.newlines.lower()
460459
if NEWLINES not in ('lf', 'cr', 'crlf', 'all'):
461-
parser.error("invalid 'newlines' option: %r" % NEWLINES)
460+
parser.error(f"invalid 'newlines' option: {NEWLINES!r}")
462461

463462
test_options = ""
464463
if options.read:

0 commit comments

Comments
 (0)