diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2021-01-31 10:10:47 -0500 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2021-01-31 10:10:47 -0500 |
commit | d02be78c3a0ee3022be56c623bb9bdcad1e9acd4 (patch) | |
tree | 1e74153bb4741f6a9e2f1e1f55d2b9960a490bb3 /tests/test_parser.py | |
parent | a035bde3320a501720ae722dc6b54fe7ff5c8647 (diff) | |
download | python-coveragepy-git-nedbat/unittest2pytest.tar.gz |
style: fix long lines and avoid backslashesnedbat/unittest2pytest
Diffstat (limited to 'tests/test_parser.py')
-rw-r--r-- | tests/test_parser.py | 142 |
1 files changed, 85 insertions, 57 deletions
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", """\ |