diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2021-11-11 07:23:36 -0500 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2021-11-11 07:23:36 -0500 |
commit | 1b94835aac3268a32bfa4ce0df585dbb97457a06 (patch) | |
tree | adbc0aa1467460588e77aa6d574e1ae9abb74f0f /tests | |
parent | 79f9f4575321fafc2ef770e3255f874db3d4b037 (diff) | |
download | python-coveragepy-git-1b94835aac3268a32bfa4ce0df585dbb97457a06.tar.gz |
style: convert more string formatting to f-strings
Diffstat (limited to 'tests')
-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 |
15 files changed, 30 insertions, 32 deletions
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" |