Skip to content

Commit 42079be

Browse files
committed
Use f-strings
1 parent bb591b6 commit 42079be

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

Lib/doctest.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -1050,7 +1050,7 @@ def _find(self, tests, obj, name, module, source_lines, globs, seen):
10501050
# Look for tests in a module's contained objects.
10511051
if inspect.ismodule(obj) and self._recurse:
10521052
for valname, val in obj.__dict__.items():
1053-
valname = '%s.%s' % (name, valname)
1053+
valname = f'{name}.{valname}'
10541054

10551055
# Recurse to functions & classes.
10561056
if ((self._is_routine(val) or inspect.isclass(val)) and
@@ -1071,7 +1071,7 @@ def _find(self, tests, obj, name, module, source_lines, globs, seen):
10711071
"must be strings, functions, methods, "
10721072
"classes, or modules: %r" %
10731073
(type(val),))
1074-
valname = '%s.__test__.%s' % (name, valname)
1074+
valname = f'{name}.__test__.{valname}'
10751075
self._find(tests, val, valname, module, source_lines,
10761076
globs, seen)
10771077

@@ -1086,7 +1086,7 @@ def _find(self, tests, obj, name, module, source_lines, globs, seen):
10861086
if ((inspect.isroutine(val) or inspect.isclass(val) or
10871087
isinstance(val, property)) and
10881088
self._from_module(module, val)):
1089-
valname = '%s.%s' % (name, valname)
1089+
valname = f'{name}.{valname}'
10901090
self._find(tests, val, valname, module, source_lines,
10911091
globs, seen)
10921092

@@ -1335,7 +1335,7 @@ def _failure_header(self, test, example):
13351335
out.append('File "%s", line %s, in %s' %
13361336
(test.filename, lineno, test.name))
13371337
else:
1338-
out.append('Line %s, in %s' % (example.lineno+1, test.name))
1338+
out.append(f'Line {example.lineno+1}, in {test.name}')
13391339
out.append('Failed example:')
13401340
source = example.source
13411341
out.append(_indent(source))
@@ -1831,7 +1831,7 @@ def output_difference(self, example, got, optionflags):
18311831
# If we're not using diff, then simply list the expected
18321832
# output followed by the actual output.
18331833
if want and got:
1834-
return 'Expected:\n%sGot:\n%s' % (_indent(want), _indent(got))
1834+
return f'Expected:\n{_indent(want)}Got:\n{_indent(got)}'
18351835
elif want:
18361836
return 'Expected:\n%sGot nothing\n' % _indent(want)
18371837
elif got:
@@ -2071,7 +2071,7 @@ class doctest.Tester, then merges the results into (or creates)
20712071

20722072
# Check that we were actually given a module.
20732073
if not inspect.ismodule(m):
2074-
raise TypeError("testmod: module required; %r" % (m,))
2074+
raise TypeError(f"testmod: module required; {m!r}")
20752075

20762076
# If no name was given, then use the module's name.
20772077
if name is None:
@@ -2447,7 +2447,7 @@ def __hash__(self):
24472447

24482448
def __repr__(self):
24492449
name = self._dt_test.name.split('.')
2450-
return "%s (%s)" % (name[-1], '.'.join(name[:-1]))
2450+
return f"{name[-1]} ({'.'.join(name[:-1])})"
24512451

24522452
__str__ = object.__str__
24532453

Lib/test/test_doctest/test_doctest2.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,14 @@ def tearDown(self):
122122
_colorize._COLORIZE = self.colorize
123123

124124
def test_testmod(self):
125-
import doctest, sys
125+
import doctest
126+
import sys
126127
EXPECTED = 19
127128
f, t = doctest.testmod(sys.modules[__name__])
128129
if f:
129-
self.fail("%d of %d doctests failed" % (f, t))
130+
self.fail(f"{f} of {t} doctests failed")
130131
if t != EXPECTED:
131-
self.fail("expected %d tests to run, not %d" % (EXPECTED, t))
132+
self.fail(f"expected {EXPECTED} tests to run, not {t}")
132133

133134

134135
# Pollute the namespace with a bunch of imported functions and classes,

0 commit comments

Comments
 (0)