diff options
-rw-r--r-- | coverage/disposition.py | 2 | ||||
-rw-r--r-- | coverage/execfile.py | 2 | ||||
-rw-r--r-- | coverage/misc.py | 2 | ||||
-rw-r--r-- | coverage/results.py | 2 | ||||
-rw-r--r-- | coverage/version.py | 2 | ||||
-rw-r--r-- | coverage/xmlreport.py | 4 | ||||
-rw-r--r-- | igor.py | 6 | ||||
-rw-r--r-- | tests/coveragetest.py | 6 | ||||
-rw-r--r-- | tests/gold/annotate/anno_dir/d_b039179a8a4ce2c2_b.py,cover | 2 | ||||
-rw-r--r-- | tests/modules/process_test/try_execfile.py | 2 | ||||
-rw-r--r-- | tests/test_annotate.py | 2 | ||||
-rw-r--r-- | tests/test_arcs.py | 4 | ||||
-rw-r--r-- | tests/test_concurrency.py | 8 | ||||
-rw-r--r-- | tests/test_config.py | 4 | ||||
-rw-r--r-- | tests/test_debug.py | 8 | ||||
-rw-r--r-- | tests/test_execfile.py | 2 | ||||
-rw-r--r-- | tests/test_oddball.py | 2 | ||||
-rw-r--r-- | tests/test_parser.py | 2 | ||||
-rw-r--r-- | tests/test_phystokens.py | 4 | ||||
-rw-r--r-- | tests/test_plugins.py | 2 | ||||
-rw-r--r-- | tests/test_process.py | 12 | ||||
-rw-r--r-- | tests/test_summary.py | 2 |
22 files changed, 40 insertions, 42 deletions
diff --git a/coverage/disposition.py b/coverage/disposition.py index 1c39a9c1..30b31af6 100644 --- a/coverage/disposition.py +++ b/coverage/disposition.py @@ -33,7 +33,7 @@ def disposition_debug_msg(disp): if disp.original_filename != disp.source_filename: msg += f" as {disp.source_filename!r}" if disp.file_tracer: - msg += ": will be traced by %r" % disp.file_tracer + msg += f": will be traced by {disp.file_tracer!r}" else: msg = f"Not tracing {disp.original_filename!r}: {disp.reason}" return msg diff --git a/coverage/execfile.py b/coverage/execfile.py index 3da3ba1f..38dc1d07 100644 --- a/coverage/execfile.py +++ b/coverage/execfile.py @@ -144,7 +144,7 @@ class PyRunner: self.arg0 = try_filename break else: - raise NoSource("Can't find '__main__' module in '%s'" % self.arg0) + raise NoSource(f"Can't find '__main__' module in '{self.arg0}'") # Make a spec. I don't know if this is the right way to do it. try_filename = python_reported_file(try_filename) diff --git a/coverage/misc.py b/coverage/misc.py index 584efeaa..fa09f890 100644 --- a/coverage/misc.py +++ b/coverage/misc.py @@ -184,7 +184,7 @@ def bool_or_none(b): def join_regex(regexes): """Combine a list of regexes into one that matches any of them.""" - return "|".join("(?:%s)" % r for r in regexes) + return "|".join(f"(?:{r})" for r in regexes) def file_be_gone(path): diff --git a/coverage/results.py b/coverage/results.py index 11c4b09b..64e5130c 100644 --- a/coverage/results.py +++ b/coverage/results.py @@ -317,7 +317,7 @@ def format_lines(statements, lines, arcs=None): for ex in sorted(exits): if line not in lines and ex not in lines: dest = (ex if ex > 0 else "exit") - line_items.append((line, "%d->%s" % (line, dest))) + line_items.append((line, f"{line}->{dest}")) ret = ', '.join(t[-1] for t in sorted(line_items)) return ret diff --git a/coverage/version.py b/coverage/version.py index 41244144..394cd076 100644 --- a/coverage/version.py +++ b/coverage/version.py @@ -16,7 +16,7 @@ def _make_version(major, minor, micro, releaselevel, serial): version += ".%d" % (micro,) if releaselevel != 'final': short = {'alpha': 'a', 'beta': 'b', 'candidate': 'rc'}[releaselevel] - version += "%s%d" % (short, serial) + version += f"{short}{serial}" return version diff --git a/coverage/xmlreport.py b/coverage/xmlreport.py index 8c8409dc..ebc85de4 100644 --- a/coverage/xmlreport.py +++ b/coverage/xmlreport.py @@ -67,9 +67,9 @@ class XmlReporter: xcoverage.setAttribute("version", __version__) xcoverage.setAttribute("timestamp", str(int(time.time()*1000))) xcoverage.appendChild(self.xml_out.createComment( - " Generated by coverage.py: %s " % __url__ + f" Generated by coverage.py: {__url__} " )) - xcoverage.appendChild(self.xml_out.createComment(" Based on %s " % DTD_URL)) + xcoverage.appendChild(self.xml_out.createComment(f" Based on {DTD_URL} ")) # Call xml_file for each file in the data. for fr, analysis in get_analysis_to_report(self.coverage, morfs): @@ -282,14 +282,14 @@ def do_check_eol(): for n, line in enumerate(f, start=1): if crlf: if b"\r" in line: - print("%s@%d: CR found" % (fname, n)) + print(f"{fname}@{n}: CR found") return if trail_white: line = line[:-1] if not crlf: line = line.rstrip(b'\r') if line.rstrip() != line: - print("%s@%d: trailing whitespace found" % (fname, n)) + print(f"{fname}@{n}: trailing whitespace found") return if line is not None and not line.strip(): @@ -391,7 +391,7 @@ def main(args): verb = args.pop(0) handler = globals().get('do_'+verb) if handler is None: - print("*** No handler for %r" % verb) + print(f"*** No handler for {verb!r}") return 1 star, num_args = analyze_args(handler) if star: diff --git a/tests/coveragetest.py b/tests/coveragetest.py index 0960722b..52b0a6ab 100644 --- a/tests/coveragetest.py +++ b/tests/coveragetest.py @@ -275,13 +275,11 @@ class CoverageTest( def assert_exists(self, fname): """Assert that `fname` is a file that exists.""" - msg = "File %r should exist" % fname - assert os.path.exists(fname), msg + assert os.path.exists(fname), f"File {fname!r} should exist" def assert_doesnt_exist(self, fname): """Assert that `fname` is a file that doesn't exist.""" - msg = "File %r shouldn't exist" % fname - assert not os.path.exists(fname), msg + assert not os.path.exists(fname), f"File {fname!r} shouldn't exist" def assert_file_count(self, pattern, count): """Assert that there are `count` files matching `pattern`.""" diff --git a/tests/gold/annotate/anno_dir/d_b039179a8a4ce2c2_b.py,cover b/tests/gold/annotate/anno_dir/d_b039179a8a4ce2c2_b.py,cover index 90d076f1..382f1901 100644 --- a/tests/gold/annotate/anno_dir/d_b039179a8a4ce2c2_b.py,cover +++ b/tests/gold/annotate/anno_dir/d_b039179a8a4ce2c2_b.py,cover @@ -1,3 +1,3 @@ > def b(x): -> msg = "x is %s" % x +> msg = f"x is {x}" > print(msg) diff --git a/tests/modules/process_test/try_execfile.py b/tests/modules/process_test/try_execfile.py index 48f9d098..2c741662 100644 --- a/tests/modules/process_test/try_execfile.py +++ b/tests/modules/process_test/try_execfile.py @@ -61,7 +61,7 @@ import __main__ def my_function(a): """A function to force execution of module-level values.""" - return "my_fn(%r)" % a + return f"my_fn({a!r})" FN_VAL = my_function("fooey") diff --git a/tests/test_annotate.py b/tests/test_annotate.py index 97f2080b..09893143 100644 --- a/tests/test_annotate.py +++ b/tests/test_annotate.py @@ -32,7 +32,7 @@ class AnnotationGoldTest(CoverageTest): self.make_file("b/__init__.py") self.make_file("b/b.py", """\ def b(x): - msg = "x is %s" % x + msg = f"x is {x}" print(msg) """) diff --git a/tests/test_arcs.py b/tests/test_arcs.py index 349a560f..817943e9 100644 --- a/tests/test_arcs.py +++ b/tests/test_arcs.py @@ -1835,7 +1835,7 @@ class AsyncTest(CoverageTest): import asyncio async def compute(x, y): # 3 - print("Compute %s + %s ..." % (x, y)) + print(f"Compute {x} + {y} ...") await asyncio.sleep(0.001) return x + y # 6 @@ -1843,7 +1843,7 @@ class AsyncTest(CoverageTest): result = (0 + await compute(x, y) # A ) - print("%s + %s = %s" % (x, y, result)) + print(f"{x} + {y} = {result}") loop = asyncio.new_event_loop() # E loop.run_until_complete(print_sum(1, 2)) diff --git a/tests/test_concurrency.py b/tests/test_concurrency.py index c39b0163..6db75e69 100644 --- a/tests/test_concurrency.py +++ b/tests/test_concurrency.py @@ -215,7 +215,7 @@ class ConcurrencyTest(CoverageTest): self.make_file("try_it.py", code) - cmd = "coverage run --concurrency=%s try_it.py" % concurrency + cmd = f"coverage run --concurrency={concurrency} try_it.py" out = self.run_command(cmd) expected_cant_trace = cant_trace_msg(concurrency, the_module) @@ -366,11 +366,11 @@ class MultiprocessingTest(CoverageTest): ): """Run code using multiprocessing, it should produce `expected_out`.""" self.make_file("multi.py", code) - self.make_file(".coveragerc", """\ + self.make_file(".coveragerc", f"""\ [run] - concurrency = %s + concurrency = {concurrency} source = . - """ % concurrency) + """) for start_method in ["fork", "spawn"]: if start_method and start_method not in multiprocessing.get_all_start_methods(): diff --git a/tests/test_config.py b/tests/test_config.py index c2874188..ad3b446a 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -181,7 +181,7 @@ class ConfigTest(CoverageTest): ] for bad_config, msg in bad_configs_and_msgs: - print("Trying %r" % bad_config) + print(f"Trying {bad_config!r}") self.make_file(".coveragerc", bad_config) with pytest.raises(CoverageException, match=msg): coverage.Coverage() @@ -689,7 +689,7 @@ class ConfigFileTest(UsingModulesMixin, CoverageTest): ".", ] for bad_file in bad_files: - msg = "Couldn't read %r as a config file" % bad_file + msg = f"Couldn't read {bad_file!r} as a config file" with pytest.raises(CoverageException, match=msg): coverage.Coverage(config_file=bad_file) diff --git a/tests/test_debug.py b/tests/test_debug.py index 1ea72e82..42f41706 100644 --- a/tests/test_debug.py +++ b/tests/test_debug.py @@ -171,8 +171,8 @@ class DebugTraceTest(CoverageTest): report_include report_omit """.split() for label in labels: - label_pat = r"^\s*%s: " % label - msg = "Incorrect lines for %r" % label + label_pat = fr"^\s*{label}: " + msg = f"Incorrect lines for {label!r}" assert 1 == len(re_lines(label_pat, out_lines)), msg def test_debug_sys(self): @@ -185,8 +185,8 @@ class DebugTraceTest(CoverageTest): pid cwd path environment command_line cover_match pylib_match """.split() for label in labels: - label_pat = r"^\s*%s: " % label - msg = "Incorrect lines for %r" % label + label_pat = fr"^\s*{label}: " + msg = f"Incorrect lines for {label!r}" assert 1 == len(re_lines(label_pat, out_lines)), msg def test_debug_sys_ctracer(self): diff --git a/tests/test_execfile.py b/tests/test_execfile.py index b7a09902..d211eba9 100644 --- a/tests/test_execfile.py +++ b/tests/test_execfile.py @@ -83,7 +83,7 @@ class RunFileTest(CoverageTest): self.make_file("abrupt.py", """\ if 1: a = 1 - print("a is %r" % a) + print(f"a is {a!r}") #""") with open("abrupt.py") as f: abrupt = f.read() diff --git a/tests/test_oddball.py b/tests/test_oddball.py index 19c93be5..2eb0fc1d 100644 --- a/tests/test_oddball.py +++ b/tests/test_oddball.py @@ -475,7 +475,7 @@ class GettraceTest(CoverageTest): def tracer(frame, event, arg): filename = os.path.basename(frame.f_code.co_filename) - print("%s: %s @ %d" % (event, filename, frame.f_lineno)) + print(f"{event}: {filename} @ {frame.f_lineno}") return tracer def begin(): diff --git a/tests/test_parser.py b/tests/test_parser.py index 538e2500..6dcfc00a 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -463,7 +463,7 @@ class ParserFileTest(CoverageTest): fname = fname + ".py" self.make_file(fname, text, newline=newline) parser = self.parse_file(fname) - assert parser.exit_counts() == counts, "Wrong for %r" % fname + assert parser.exit_counts() == counts, f"Wrong for {fname!r}" def test_encoding(self): self.make_file("encoded.py", """\ diff --git a/tests/test_phystokens.py b/tests/test_phystokens.py index 9950e655..91a9d3d9 100644 --- a/tests/test_phystokens.py +++ b/tests/test_phystokens.py @@ -171,7 +171,7 @@ class SourceEncodingTest(CoverageTest): def test_detect_source_encoding(self): for _, source, expected in ENCODING_DECLARATION_SOURCES: - assert source_encoding(source) == expected, "Wrong encoding in %r" % source + assert source_encoding(source) == expected, f"Wrong encoding in {source!r}" # PyPy3 gets this case wrong. Not sure what I can do about it, so skip the test. @pytest.mark.skipif(env.PYPY, reason="PyPy3 is wrong about non-comment encoding. Skip it.") @@ -233,7 +233,7 @@ class NeuterEncodingDeclarationTest(CoverageTest): # The neutered source will be detected as having no encoding # declaration. - assert source_encoding(neutered) == DEF_ENCODING, "Wrong encoding in %r" % neutered + assert source_encoding(neutered) == DEF_ENCODING, f"Wrong encoding in {neutered!r}" def test_two_encoding_declarations(self): input_src = textwrap.dedent("""\ diff --git a/tests/test_plugins.py b/tests/test_plugins.py index 17c7ba44..5d3b5322 100644 --- a/tests/test_plugins.py +++ b/tests/test_plugins.py @@ -988,7 +988,7 @@ class DynamicContextPluginTest(CoverageTest): """Make some files to use while testing dynamic context plugins.""" self.make_file("rendering.py", """\ def html_tag(tag, content): - return '<%s>%s</%s>' % (tag, content, tag) + return f'<{tag}>{content}</{tag}>' def render_paragraph(text): return html_tag('p', text) diff --git a/tests/test_process.py b/tests/test_process.py index 83ca1feb..58f32707 100644 --- a/tests/test_process.py +++ b/tests/test_process.py @@ -382,7 +382,7 @@ class ProcessTest(CoverageTest): self.make_file("d1/x.py", """\ a = 1 b = 2 - print("%s %s" % (a, b)) + print(f"{a} {b}") """) self.make_file("d2/x.py", """\ @@ -391,7 +391,7 @@ class ProcessTest(CoverageTest): # 3 c = 4 d = 5 - print("%s %s" % (c, d)) + print(f"{c} {d}") """) self.make_file(".coveragerc", """\ @@ -823,7 +823,7 @@ class ProcessTest(CoverageTest): import coverage for i in [1, 2]: - sys.stderr.write("Run %s\\n" % i) + sys.stderr.write(f"Run {i}\\n") inst = coverage.Coverage(source=['foo']) inst.load() inst.start() @@ -1206,9 +1206,9 @@ class AliasedCommandTest(CoverageTest): "coverage-%d.%d" % sys.version_info[:2], ] for cmd in cmds: - out = self.run_command("%s foobar" % cmd) + out = self.run_command(f"{cmd} foobar") assert "Unknown command: 'foobar'" in out - assert "Use '%s help' for help" % cmd in out + assert f"Use '{cmd} help' for help" in out class PydocTest(CoverageTest): @@ -1557,7 +1557,7 @@ class ProcessStartupTest(ProcessCoverageMixin, CoverageTest): data_files = glob.glob(os.getcwd() + '/.coverage*') msg = ( "Expected only .coverage after combine, looks like there are " + - "extra data files that were not cleaned up: %r" % data_files + f"extra data files that were not cleaned up: {data_files!r}" ) assert len(data_files) == 1, msg diff --git a/tests/test_summary.py b/tests/test_summary.py index 03660542..6fbb034d 100644 --- a/tests/test_summary.py +++ b/tests/test_summary.py @@ -631,7 +631,7 @@ class SummaryTest(UsingModulesMixin, CoverageTest): if not b: c = 6 d = 7 - print("xxx: %r %r %r %r" % (a, b, c, d)) + print(f"xxx: {a} {b} {c} {d}") """) out = self.run_command("coverage run --source=. xxx") assert out == "xxx: 3 4 0 7\n" |