From d02be78c3a0ee3022be56c623bb9bdcad1e9acd4 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Sun, 31 Jan 2021 10:10:47 -0500 Subject: style: fix long lines and avoid backslashes --- tests/coveragetest.py | 3 +- tests/test_api.py | 14 ++--- tests/test_arcs.py | 8 +-- tests/test_cmdline.py | 7 +-- tests/test_config.py | 9 +-- tests/test_data.py | 16 +++--- tests/test_debug.py | 10 ++-- tests/test_execfile.py | 3 +- tests/test_files.py | 14 ++--- tests/test_html.py | 30 +++++----- tests/test_numbits.py | 8 ++- tests/test_oddball.py | 22 ++++---- tests/test_parser.py | 142 ++++++++++++++++++++++++++++------------------- tests/test_phystokens.py | 8 +-- tests/test_plugins.py | 4 +- tests/test_process.py | 28 ++++++---- tests/test_summary.py | 7 +-- tests/test_templite.py | 3 +- tests/test_version.py | 7 +-- tests/test_xml.py | 3 +- 20 files changed, 179 insertions(+), 167 deletions(-) diff --git a/tests/coveragetest.py b/tests/coveragetest.py index b0c99d2e..f7a5f6f8 100644 --- a/tests/coveragetest.py +++ b/tests/coveragetest.py @@ -210,7 +210,8 @@ class CoverageTest( missing_formatted = analysis.missing_formatted() if isinstance(missing, string_class): - assert missing_formatted == missing, "{!r} != {!r}".format(missing_formatted, missing) + msg = "{!r} != {!r}".format(missing_formatted, missing) + assert missing_formatted == missing, msg else: for missing_list in missing: if missing_formatted == missing_list: diff --git a/tests/test_api.py b/tests/test_api.py index 7d75022e..bce431f3 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -548,8 +548,7 @@ class ApiTest(CoverageTest): assert "Hello\n" in out err = self.stderr() - assert "Coverage.py warning: Module sys has no Python source. (module-not-python)" in \ - err + assert "Coverage.py warning: Module sys has no Python source. (module-not-python)" in err assert "module-not-imported" not in err assert "no-data-collected" not in err @@ -634,8 +633,7 @@ class ApiTest(CoverageTest): # Labeled data is collected data = cov.get_data() - assert [u'', u'multiply_six', u'multiply_zero'] == \ - sorted(data.measured_contexts()) + assert [u'', u'multiply_six', u'multiply_zero'] == sorted(data.measured_contexts()) filenames = self.get_measured_filenames(data) suite_filename = filenames['testsuite.py'] @@ -673,8 +671,8 @@ class ApiTest(CoverageTest): # Labeled data is collected data = cov.get_data() - assert [u'mysuite', u'mysuite|multiply_six', u'mysuite|multiply_zero'] == \ - sorted(data.measured_contexts()) + expected = [u'mysuite', u'mysuite|multiply_six', u'mysuite|multiply_zero'] + assert expected == sorted(data.measured_contexts()) filenames = self.get_measured_filenames(data) suite_filename = filenames['testsuite.py'] @@ -691,8 +689,8 @@ class ApiTest(CoverageTest): # Switch twice, but only get one warning. cov.switch_context("test1") # pragma: nested cov.switch_context("test2") # pragma: nested - assert self.stderr() == \ - "Coverage.py warning: Conflicting dynamic contexts (dynamic-conflict)\n" + expected = "Coverage.py warning: Conflicting dynamic contexts (dynamic-conflict)\n" + assert expected == self.stderr() cov.stop() # pragma: nested def test_switch_context_unstarted(self): diff --git a/tests/test_arcs.py b/tests/test_arcs.py index c4d34d30..2f49ecfb 100644 --- a/tests/test_arcs.py +++ b/tests/test_arcs.py @@ -1410,10 +1410,10 @@ class MiscArcTest(CoverageTest): filename = self.last_module_name + ".py" fr = cov._get_file_reporter(filename) arcs_executed = cov._analyze(filename).arcs_executed() - assert fr.missing_arc_description(3, -3, arcs_executed) == \ - "line 3 didn't finish the generator expression on line 3" - assert fr.missing_arc_description(4, -4, arcs_executed) == \ - "line 4 didn't run the generator expression on line 4" + expected = "line 3 didn't finish the generator expression on line 3" + assert expected == fr.missing_arc_description(3, -3, arcs_executed) + expected = "line 4 didn't run the generator expression on line 4" + assert expected == fr.missing_arc_description(4, -4, arcs_executed) class DecoratorArcTest(CoverageTest): diff --git a/tests/test_cmdline.py b/tests/test_cmdline.py index 2c24c598..a0744452 100644 --- a/tests/test_cmdline.py +++ b/tests/test_cmdline.py @@ -544,10 +544,9 @@ class CmdLineTest(BaseCmdLineTest): # runs, since they won't make it to the subprocesses. You need to use a # config file. self.command_line("run --concurrency=multiprocessing --branch foo.py", ret=ERR) - assert "Options affecting multiprocessing must only be specified in a configuration file." in \ - self.stderr() - assert "Remove --branch from the command line." in \ - self.stderr() + msg = "Options affecting multiprocessing must only be specified in a configuration file." + assert msg in self.stderr() + assert "Remove --branch from the command line." in self.stderr() def test_run_debug(self): self.cmd_executes("run --debug=opt1 foo.py", """\ diff --git a/tests/test_config.py b/tests/test_config.py index 3d090668..04503f30 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -88,8 +88,7 @@ class ConfigTest(CoverageTest): assert cov.config.precision == 3 assert cov.config.html_title == u"tabblo & «ταБЬℓσ»" assert round(abs(cov.config.fail_under-90.5), 7) == 0 - assert cov.config.get_plugin_options("plugins.a_plugin") == \ - {u"hello": u"world"} + assert cov.config.get_plugin_options("plugins.a_plugin") == {u"hello": u"world"} # Test that our class doesn't reject integers when loading floats self.make_file("pyproject.toml", """\ @@ -233,8 +232,7 @@ class ConfigTest(CoverageTest): cov = coverage.Coverage() assert cov.config.data_file == "hello-world.fooey" assert cov.config.branch is True - assert cov.config.exclude_list == \ - ["the_$one", "anotherZZZ", "xZZZy", "xy", "huh${X}what"] + assert cov.config.exclude_list == ["the_$one", "anotherZZZ", "xZZZy", "xy", "huh${X}what"] def test_environment_vars_in_toml_config(self): # Config files can have $envvars in them. @@ -257,8 +255,7 @@ class ConfigTest(CoverageTest): cov = coverage.Coverage() assert cov.config.data_file == "hello-world.fooey" assert cov.config.branch is True - assert cov.config.exclude_list == \ - ["the_$one", "anotherZZZ", "xZZZy", "xy", "huh${X}what"] + assert cov.config.exclude_list == ["the_$one", "anotherZZZ", "xZZZy", "xy", "huh${X}what"] def test_tilde_in_config(self): # Config entries that are file paths can be tilde-expanded. diff --git a/tests/test_data.py b/tests/test_data.py index 4eda1873..789bdd5a 100644 --- a/tests/test_data.py +++ b/tests/test_data.py @@ -209,8 +209,7 @@ class CoverageDataTest(DataTestHelpers, CoverageTest): covdata = CoverageData() covdata.set_context('test_a') covdata.add_lines(LINES_1) - assert covdata.contexts_by_lineno('a.py') == \ - {1: ['test_a'], 2: ['test_a']} + assert covdata.contexts_by_lineno('a.py') == {1: ['test_a'], 2: ['test_a']} def test_no_duplicate_lines(self): covdata = CoverageData() @@ -251,8 +250,8 @@ class CoverageDataTest(DataTestHelpers, CoverageTest): covdata = CoverageData() covdata.set_context('test_x') covdata.add_arcs(ARCS_3) - assert covdata.contexts_by_lineno('x.py') == \ - {-1: ['test_x'], 1: ['test_x'], 2: ['test_x'], 3: ['test_x']} + expected = {-1: ['test_x'], 1: ['test_x'], 2: ['test_x'], 3: ['test_x']} + assert expected == covdata.contexts_by_lineno('x.py') def test_contexts_by_lineno_with_unknown_file(self): covdata = CoverageData() @@ -587,9 +586,12 @@ class CoverageDataFilesTest(DataTestHelpers, CoverageTest): covdata2.read() self.assert_line_counts(covdata2, SUMMARY_1) - assert re.search(r"^Erasing data file '.*\.coverage'\n" \ - r"Creating data file '.*\.coverage'\n" \ - r"Opening data file '.*\.coverage'\n$", debug.get_output()) + assert re.search( + r"^Erasing data file '.*\.coverage'\n" + r"Creating data file '.*\.coverage'\n" + r"Opening data file '.*\.coverage'\n$", + debug.get_output() + ) def test_debug_output_without_debug_option(self): # With a debug object, but not the dataio option, we don't get debug diff --git a/tests/test_debug.py b/tests/test_debug.py index 42d7945e..16669407 100644 --- a/tests/test_debug.py +++ b/tests/test_debug.py @@ -176,9 +176,8 @@ class DebugTraceTest(CoverageTest): """.split() for label in labels: label_pat = r"^\s*%s: " % label - assert len(re_lines(out_lines, label_pat).splitlines()) == \ - 1, \ - "Incorrect lines for %r" % label + msg = "Incorrect lines for %r" % label + assert 1 == len(re_lines(out_lines, label_pat).splitlines()), msg def test_debug_sys(self): out_lines = self.f1_debug_output(["sys"]) @@ -190,9 +189,8 @@ class DebugTraceTest(CoverageTest): """.split() for label in labels: label_pat = r"^\s*%s: " % label - assert len(re_lines(out_lines, label_pat).splitlines()) == \ - 1, \ - "Incorrect lines for %r" % label + msg = "Incorrect lines for %r" % label + assert 1 == len(re_lines(out_lines, label_pat).splitlines()), msg def test_debug_sys_ctracer(self): out_lines = self.f1_debug_output(["sys"]) diff --git a/tests/test_execfile.py b/tests/test_execfile.py index 77527478..db78d0f6 100644 --- a/tests/test_execfile.py +++ b/tests/test_execfile.py @@ -39,8 +39,7 @@ class RunFileTest(CoverageTest): assert dunder_file == "try_execfile.py" # It should have its correct module data. - assert mod_globs['__doc__'].splitlines()[0] == \ - "Test file for run_python_file." + assert mod_globs['__doc__'].splitlines()[0] == "Test file for run_python_file." assert mod_globs['DATA'] == "xyzzy" assert mod_globs['FN_VAL'] == "my_fn('fooey')" diff --git a/tests/test_files.py b/tests/test_files.py index 1e0ddcfb..6a9556ec 100644 --- a/tests/test_files.py +++ b/tests/test_files.py @@ -66,8 +66,7 @@ class FilesTest(CoverageTest): assert canonical_path == self.abs_path('file1.py') # After the filename has been converted, it should be in the cache. assert 'sub/proj1/file1.py' in files.CANONICAL_FILENAME_CACHE - assert files.canonical_filename('sub/proj1/file1.py') == \ - self.abs_path('file1.py') + assert files.canonical_filename('sub/proj1/file1.py') == self.abs_path('file1.py') @pytest.mark.parametrize("original, flat", [ @@ -148,8 +147,8 @@ class MatcherTest(CoverageTest): def assertMatches(self, matcher, filepath, matches): """The `matcher` should agree with `matches` about `filepath`.""" canonical = files.canonical_filename(filepath) - assert matcher.match(canonical) == matches, \ - "File %s should have matched as %s" % (filepath, matches) + msg = "File %s should have matched as %s" % (filepath, matches) + assert matches == matcher.match(canonical), msg def test_tree_matcher(self): matches_to_try = [ @@ -187,12 +186,9 @@ class MatcherTest(CoverageTest): ] modules = ['test', 'py.test', 'mymain'] mm = ModuleMatcher(modules) - assert mm.info() == \ - modules + assert mm.info() == modules for modulename, matches in matches_to_try: - assert mm.match(modulename) == \ - matches, \ - modulename + assert mm.match(modulename) == matches, modulename def test_fnmatch_matcher(self): matches_to_try = [ diff --git a/tests/test_html.py b/tests/test_html.py index 59cda0d4..ee2eb575 100644 --- a/tests/test_html.py +++ b/tests/test_html.py @@ -309,20 +309,20 @@ class HtmlTitleTest(HtmlTestHelpers, CoverageTest): self.make_file(".coveragerc", "[html]\ntitle = «ταБЬℓσ» numbers") self.run_coverage() index = self.get_html_index_content() - assert "«ταБЬℓσ»" \ - " numbers" in index - assert "<h1>«ταБЬℓσ»" \ - " numbers" in index + assert "<title>«ταБЬℓσ» numbers" in index + assert "<h1>«ταБЬℓσ» numbers" in index def test_title_set_in_args(self): self.create_initial_files() self.make_file(".coveragerc", "[html]\ntitle = Good title\n") self.run_coverage(htmlargs=dict(title="«ταБЬℓσ» & stüff!")) index = self.get_html_index_content() - assert "<title>«ταБЬℓσ»" \ - " & stüff!" in index - assert "

«ταБЬℓσ»" \ - " & stüff!:" in index + expected = ( + "«ταБЬℓσ» " + + "& stüff!" + ) + assert expected in index + assert "

«ταБЬℓσ» & stüff!:" in index class HtmlWithUnparsableFilesTest(HtmlTestHelpers, CoverageTest): @@ -345,15 +345,11 @@ class HtmlWithUnparsableFilesTest(HtmlTestHelpers, CoverageTest): self.start_import_stop(cov, "main") self.make_file("innocuous.py", "

This isn't python!

") cov.html_report(ignore_errors=True) - assert len(cov._warnings) == \ - 1, \ - "Expected a warning to be thrown when an invalid python file is parsed" - assert "Couldn't parse Python file" in \ - cov._warnings[0], \ - "Warning message should be in 'invalid file' warning" - assert "innocuous.py" in \ - cov._warnings[0], \ - "Filename should be in 'invalid file' warning" + msg = "Expected a warning to be thrown when an invalid python file is parsed" + assert 1 == len(cov._warnings), msg + msg = "Warning message should be in 'invalid file' warning" + assert "Couldn't parse Python file" in cov._warnings[0], msg + assert "innocuous.py" in cov._warnings[0], "Filename should be in 'invalid file' warning" self.assert_exists("htmlcov/index.html") # This would be better as a glob, if the HTML layout changes: self.assert_doesnt_exist("htmlcov/innocuous.html") diff --git a/tests/test_numbits.py b/tests/test_numbits.py index 8216b628..fc27a093 100644 --- a/tests/test_numbits.py +++ b/tests/test_numbits.py @@ -121,10 +121,12 @@ class NumbitsSqliteFunctionTest(CoverageTest): "(select numbits from data where id = 9)" ")" ) + expected = [ + 7, 9, 14, 18, 21, 27, 28, 35, 36, 42, 45, 49, + 54, 56, 63, 70, 72, 77, 81, 84, 90, 91, 98, 99, + ] answer = numbits_to_nums(list(res)[0][0]) - assert [7, 9, 14, 18, 21, 27, 28, 35, 36, 42, 45, 49, - 54, 56, 63, 70, 72, 77, 81, 84, 90, 91, 98, 99] == \ - answer + assert expected == answer def test_numbits_intersection(self): res = self.cursor.execute( diff --git a/tests/test_oddball.py b/tests/test_oddball.py index 46c22f9c..afbf232a 100644 --- a/tests/test_oddball.py +++ b/tests/test_oddball.py @@ -130,8 +130,7 @@ class RecursionTest(CoverageTest): # Get a warning about the stackoverflow effect on the tracing function. if pytrace: # pragma: no metacov - assert cov._warnings == \ - ["Trace function changed, measurement is likely wrong: None"] + assert cov._warnings == ["Trace function changed, measurement is likely wrong: None"] else: assert cov._warnings == [] @@ -277,8 +276,8 @@ class PyexpatTest(CoverageTest): # Make sure pyexpat isn't recorded as a source file. # https://github.com/nedbat/coveragepy/issues/419 files = cov.get_data().measured_files() - assert not any(f.endswith("pyexpat.c") for f in files), \ - "Pyexpat.c is in the measured files!: %r:" % (files,) + msg = "Pyexpat.c is in the measured files!: %r:" % (files,) + assert not any(f.endswith("pyexpat.c") for f in files), msg class ExceptionTest(CoverageTest): @@ -485,14 +484,13 @@ class GettraceTest(CoverageTest): ) out = self.stdout().replace(self.last_module_name, "coverage_test") - - assert out == \ - ( - "call: coverage_test.py @ 10\n" - "line: coverage_test.py @ 11\n" - "line: coverage_test.py @ 12\n" - "return: coverage_test.py @ 12\n" - ) + expected = ( + "call: coverage_test.py @ 10\n" + "line: coverage_test.py @ 11\n" + "line: coverage_test.py @ 12\n" + "return: coverage_test.py @ 12\n" + ) + assert expected == out @pytest.mark.expensive def test_atexit_gettrace(self): # pragma: no metacov diff --git a/tests/test_parser.py b/tests/test_parser.py index 14950c3d..6edb6d1a 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -254,19 +254,24 @@ class ParserMissingArcDescriptionTest(CoverageTest): thing(12) more_stuff(13) """) - assert parser.missing_arc_description(1, 2) == \ - "line 1 didn't jump to line 2, because the condition on line 1 was never true" - assert parser.missing_arc_description(1, 3) == \ - "line 1 didn't jump to line 3, because the condition on line 1 was never false" - assert parser.missing_arc_description(6, -5) == \ - "line 6 didn't return from function 'func5', " \ - "because the loop on line 6 didn't complete" - assert parser.missing_arc_description(6, 7) == \ - "line 6 didn't jump to line 7, because the loop on line 6 never started" - assert parser.missing_arc_description(11, 12) == \ - "line 11 didn't jump to line 12, because the condition on line 11 was never true" - assert parser.missing_arc_description(11, 13) == \ - "line 11 didn't jump to line 13, because the condition on line 11 was never false" + expected = "line 1 didn't jump to line 2, because the condition on line 1 was never true" + assert expected == parser.missing_arc_description(1, 2) + expected = "line 1 didn't jump to line 3, because the condition on line 1 was never false" + assert expected == parser.missing_arc_description(1, 3) + expected = ( + "line 6 didn't return from function 'func5', " + + "because the loop on line 6 didn't complete" + ) + assert expected == parser.missing_arc_description(6, -5) + expected = "line 6 didn't jump to line 7, because the loop on line 6 never started" + assert expected == parser.missing_arc_description(6, 7) + expected = "line 11 didn't jump to line 12, because the condition on line 11 was never true" + assert expected == parser.missing_arc_description(11, 12) + expected = ( + "line 11 didn't jump to line 13, " + + "because the condition on line 11 was never false" + ) + assert expected == parser.missing_arc_description(11, 13) def test_missing_arc_descriptions_for_small_callables(self): parser = self.parse_text(u"""\ @@ -278,14 +283,14 @@ class ParserMissingArcDescriptionTest(CoverageTest): ] x = 7 """) - assert parser.missing_arc_description(2, -2) == \ - "line 2 didn't finish the lambda on line 2" - assert parser.missing_arc_description(3, -3) == \ - "line 3 didn't finish the generator expression on line 3" - assert parser.missing_arc_description(4, -4) == \ - "line 4 didn't finish the dictionary comprehension on line 4" - assert parser.missing_arc_description(5, -5) == \ - "line 5 didn't finish the set comprehension on line 5" + expected = "line 2 didn't finish the lambda on line 2" + assert expected == parser.missing_arc_description(2, -2) + expected = "line 3 didn't finish the generator expression on line 3" + assert expected == parser.missing_arc_description(3, -3) + expected = "line 4 didn't finish the dictionary comprehension on line 4" + assert expected == parser.missing_arc_description(4, -4) + expected = "line 5 didn't finish the set comprehension on line 5" + assert expected == parser.missing_arc_description(5, -5) def test_missing_arc_descriptions_for_exceptions(self): parser = self.parse_text(u"""\ @@ -296,10 +301,16 @@ class ParserMissingArcDescriptionTest(CoverageTest): except ValueError: print("yikes") """) - assert parser.missing_arc_description(3, 4) == \ - "line 3 didn't jump to line 4, because the exception caught by line 3 didn't happen" - assert parser.missing_arc_description(5, 6) == \ - "line 5 didn't jump to line 6, because the exception caught by line 5 didn't happen" + expected = ( + "line 3 didn't jump to line 4, " + + "because the exception caught by line 3 didn't happen" + ) + assert expected == parser.missing_arc_description(3, 4) + expected = ( + "line 5 didn't jump to line 6, " + + "because the exception caught by line 5 didn't happen" + ) + assert expected == parser.missing_arc_description(5, 6) def test_missing_arc_descriptions_for_finally(self): parser = self.parse_text(u"""\ @@ -324,36 +335,56 @@ class ParserMissingArcDescriptionTest(CoverageTest): that_thing(19) """) if env.PYBEHAVIOR.finally_jumps_back: - assert parser.missing_arc_description(18, 5) == \ - "line 18 didn't jump to line 5, because the break on line 5 wasn't executed" - assert parser.missing_arc_description(5, 19) == \ - "line 5 didn't jump to line 19, because the break on line 5 wasn't executed" - assert parser.missing_arc_description(18, 10) == \ - "line 18 didn't jump to line 10, because the continue on line 10 wasn't executed" - assert parser.missing_arc_description(10, 2) == \ - "line 10 didn't jump to line 2, because the continue on line 10 wasn't executed" - assert parser.missing_arc_description(18, 14) == \ - "line 18 didn't jump to line 14, because the return on line 14 wasn't executed" - assert parser.missing_arc_description(14, -1) == \ - "line 14 didn't return from function 'function', " \ - "because the return on line 14 wasn't executed" - assert parser.missing_arc_description(18, -1) == \ - "line 18 didn't except from function 'function', " \ - "because the raise on line 16 wasn't executed" + expected = "line 18 didn't jump to line 5, because the break on line 5 wasn't executed" + assert expected == parser.missing_arc_description(18, 5) + expected = "line 5 didn't jump to line 19, because the break on line 5 wasn't executed" + assert expected == parser.missing_arc_description(5, 19) + expected = ( + "line 18 didn't jump to line 10, " + + "because the continue on line 10 wasn't executed" + ) + assert expected == parser.missing_arc_description(18, 10) + expected = ( + "line 10 didn't jump to line 2, " + + "because the continue on line 10 wasn't executed" + ) + assert expected == parser.missing_arc_description(10, 2) + expected = ( + "line 18 didn't jump to line 14, " + + "because the return on line 14 wasn't executed" + ) + assert expected == parser.missing_arc_description(18, 14) + expected = ( + "line 14 didn't return from function 'function', " + + "because the return on line 14 wasn't executed" + ) + assert expected == parser.missing_arc_description(14, -1) + expected = ( + "line 18 didn't except from function 'function', " + + "because the raise on line 16 wasn't executed" + ) + assert expected == parser.missing_arc_description(18, -1) else: - assert parser.missing_arc_description(18, 19) == \ - "line 18 didn't jump to line 19, because the break on line 5 wasn't executed" - assert parser.missing_arc_description(18, 2) == \ - "line 18 didn't jump to line 2, " \ - "because the continue on line 10 wasn't executed" \ - " or " \ + expected = ( + "line 18 didn't jump to line 19, " + + "because the break on line 5 wasn't executed" + ) + assert expected == parser.missing_arc_description(18, 19) + expected = ( + "line 18 didn't jump to line 2, " + + "because the continue on line 10 wasn't executed" + + " or " + "the continue on line 12 wasn't executed" - assert parser.missing_arc_description(18, -1) == \ - "line 18 didn't except from function 'function', " \ - "because the raise on line 16 wasn't executed" \ - " or " \ - "line 18 didn't return from function 'function', " \ + ) + assert expected == parser.missing_arc_description(18, 2) + expected = ( + "line 18 didn't except from function 'function', " + + "because the raise on line 16 wasn't executed" + + " or " + + "line 18 didn't return from function 'function', " + "because the return on line 14 wasn't executed" + ) + assert expected == parser.missing_arc_description(18, -1) def test_missing_arc_descriptions_bug460(self): parser = self.parse_text(u"""\ @@ -364,8 +395,7 @@ class ParserMissingArcDescriptionTest(CoverageTest): } x = 6 """) - assert parser.missing_arc_description(2, -3) == \ - "line 3 didn't finish the lambda on line 3" + assert parser.missing_arc_description(2, -3) == "line 3 didn't finish the lambda on line 3" class ParserFileTest(CoverageTest): @@ -396,9 +426,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, "Wrong for %r" % fname def test_encoding(self): self.make_file("encoded.py", """\ diff --git a/tests/test_phystokens.py b/tests/test_phystokens.py index 26a72d28..c7375cb5 100644 --- a/tests/test_phystokens.py +++ b/tests/test_phystokens.py @@ -130,9 +130,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, "Wrong encoding in %r" % source def test_detect_source_encoding_not_in_comment(self): if env.PYPY3: # pragma: no metacov @@ -196,9 +194,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, "Wrong encoding in %r" % neutered def test_two_encoding_declarations(self): input_src = textwrap.dedent(u"""\ diff --git a/tests/test_plugins.py b/tests/test_plugins.py index 12ce7c1e..f53de4fb 100644 --- a/tests/test_plugins.py +++ b/tests/test_plugins.py @@ -1050,8 +1050,8 @@ class DynamicContextPluginTest(CoverageTest): # Labeled coverage is collected data = cov.get_data() filenames = self.get_measured_filenames(data) - assert ['', 'doctest:HTML_TAG', 'test:HTML_TAG', 'test:RENDERERS'] == \ - sorted(data.measured_contexts()) + expected = ['', 'doctest:HTML_TAG', 'test:HTML_TAG', 'test:RENDERERS'] + assert expected == sorted(data.measured_contexts()) data.set_query_context("doctest:HTML_TAG") assert [2] == data.lines(filenames['rendering.py']) data.set_query_context("test:HTML_TAG") diff --git a/tests/test_process.py b/tests/test_process.py index 8362c1e1..536199db 100644 --- a/tests/test_process.py +++ b/tests/test_process.py @@ -611,8 +611,10 @@ class ProcessTest(CoverageTest): assert "Exception" not in out out = self.run_command("coverage run -m no_such_module") - assert ("No module named no_such_module" in out) or \ + assert ( + ("No module named no_such_module" in out) or ("No module named 'no_such_module'" in out) + ) assert "warning" not in out assert "Exception" not in out @@ -825,11 +827,13 @@ class ProcessTest(CoverageTest): inst.save() """) out = self.run_command("python run_twice.py") - assert out == \ - "Run 1\n" \ - "Run 2\n" \ - "Coverage.py warning: Module foo was previously imported, but not measured " \ + expected = ( + "Run 1\n" + + "Run 2\n" + + "Coverage.py warning: Module foo was previously imported, but not measured " + "(module-not-measured)\n" + ) + assert expected == out def test_module_name(self): # https://github.com/nedbat/coveragepy/issues/478 @@ -1256,15 +1260,15 @@ class FailUnderTest(CoverageTest): def test_report_43_is_not_ok(self): st, out = self.run_command_status("coverage report --fail-under=44") assert st == 2 - assert self.last_line_squeezed(out) == \ - "Coverage failure: total of 43 is less than fail-under=44" + expected = "Coverage failure: total of 43 is less than fail-under=44" + assert expected == self.last_line_squeezed(out) def test_report_42p86_is_not_ok(self): self.make_file(".coveragerc", "[report]\nprecision = 2") st, out = self.run_command_status("coverage report --fail-under=42.88") assert st == 2 - assert self.last_line_squeezed(out) == \ - "Coverage failure: total of 42.86 is less than fail-under=42.88" + expected = "Coverage failure: total of 42.86 is less than fail-under=42.88" + assert expected == self.last_line_squeezed(out) class FailUnderNoFilesTest(CoverageTest): @@ -1550,9 +1554,11 @@ class ProcessStartupTest(ProcessCoverageMixin, CoverageTest): # assert that there are *no* extra data files left over after a combine data_files = glob.glob(os.getcwd() + '/.coverage*') - assert len(data_files) == 1, \ - "Expected only .coverage after combine, looks like there are " \ + msg = ( + "Expected only .coverage after combine, looks like there are " + "extra data files that were not cleaned up: %r" % data_files + ) + assert len(data_files) == 1, msg class ProcessStartupWithSourceTest(ProcessCoverageMixin, CoverageTest): diff --git a/tests/test_summary.py b/tests/test_summary.py index 1d74af9c..e3694000 100644 --- a/tests/test_summary.py +++ b/tests/test_summary.py @@ -562,8 +562,7 @@ class SummaryTest(UsingModulesMixin, CoverageTest): errmsg = re.sub(r"parse '.*mycode.py", "parse 'mycode.py", errmsg) # The actual error message varies version to version errmsg = re.sub(r": '.*' at", ": 'error' at", errmsg) - assert "Couldn't parse 'mycode.py' as Python source: 'error' at line 1" == \ - errmsg + assert errmsg == "Couldn't parse 'mycode.py' as Python source: 'error' at line 1" def test_accenteddotpy_not_python(self): if env.JYTHON: @@ -923,8 +922,8 @@ class TestSummaryReporterConfiguration(CoverageTest): """Assert that the `words` appear in order in `text`.""" indexes = list(map(text.find, words)) assert -1 not in indexes - assert indexes == sorted(indexes), \ - "The words %r don't appear in order in %r" % (words, text) + msg = "The words %r don't appear in order in %r" % (words, text) + assert indexes == sorted(indexes), msg def test_sort_report_by_stmts(self): # Sort the text report by the Stmts column. diff --git a/tests/test_templite.py b/tests/test_templite.py index 8d808554..770e97f9 100644 --- a/tests/test_templite.py +++ b/tests/test_templite.py @@ -55,8 +55,7 @@ class TempliteTest(CoverageTest): def test_passthrough(self): # Strings without variables are passed through unchanged. assert Templite("Hello").render() == "Hello" - assert Templite("Hello, 20% fun time!").render() == \ - "Hello, 20% fun time!" + assert Templite("Hello, 20% fun time!").render() == "Hello, 20% fun time!" def test_variables(self): # Variables use {{var}} syntax. diff --git a/tests/test_version.py b/tests/test_version.py index ce2e88e6..00d65624 100644 --- a/tests/test_version.py +++ b/tests/test_version.py @@ -29,7 +29,6 @@ class VersionTest(CoverageTest): assert _make_version(5, 10, 2, 'candidate', 7) == "5.10.2rc7" def test_make_url(self): - assert _make_url(4, 0, 0, 'final', 0) == \ - "https://coverage.readthedocs.io" - assert _make_url(4, 1, 2, 'beta', 3) == \ - "https://coverage.readthedocs.io/en/coverage-4.1.2b3" + assert _make_url(4, 0, 0, 'final', 0) == "https://coverage.readthedocs.io" + expected = "https://coverage.readthedocs.io/en/coverage-4.1.2b3" + assert _make_url(4, 1, 2, 'beta', 3) == expected diff --git a/tests/test_xml.py b/tests/test_xml.py index 15f07698..13e015d6 100644 --- a/tests/test_xml.py +++ b/tests/test_xml.py @@ -275,8 +275,7 @@ class XmlPackageStructureTest(XmlTestHelpers, CoverageTest): def assert_package_and_class_tags(self, cov, result): """Check the XML package and class tags from `cov` match `result`.""" - assert unbackslash(list(self.package_and_class_tags(cov))) == \ - unbackslash(result) + assert unbackslash(list(self.package_and_class_tags(cov))) == unbackslash(result) def test_package_names(self): self.make_tree(width=1, depth=3) -- cgit v1.2.1