Skip to content

Commit

Permalink
test(refactor): tests no longer need to account for differences in mi…
Browse files Browse the repository at this point in the history
…ssing statements
  • Loading branch information
nedbat committed May 13, 2024
1 parent e05f60c commit 5c70761
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 33 deletions.
13 changes: 3 additions & 10 deletions tests/coveragetest.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def check_coverage(
self,
text: str,
lines: Sequence[TLineNo] | Sequence[list[TLineNo]] | None = None,
missing: str | Sequence[str] = "",
missing: str = "",
report: str = "",
excludes: Iterable[str] | None = None,
partials: Iterable[str] = (),
Expand Down Expand Up @@ -226,15 +226,8 @@ def check_coverage(
assert False, f"None of the lines choices matched {statements!r}"

missing_formatted = analysis.missing_formatted()
if isinstance(missing, str):
msg = f"missing: {missing_formatted!r} != {missing!r}"
assert missing_formatted == missing, msg
else:
for missing_list in missing:
if missing_formatted == missing_list:
break
else:
assert False, f"None of the missing choices matched {missing_formatted!r}"
msg = f"missing: {missing_formatted!r} != {missing!r}"
assert missing_formatted == missing, msg

if arcs is not None:
# print("Possible arcs:")
Expand Down
26 changes: 3 additions & 23 deletions tests/test_coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,6 @@ def test_successful_coverage(self) -> None:
[1,2,3],
missing="3",
)
# You can specify a list of possible missing lines.
self.check_coverage("""\
a = 1
if a == 2:
a = 3
""",
[1,2,3],
missing=("47-49", "3", "100,102"),
)

def test_failed_coverage(self) -> None:
# If the lines are wrong, the message shows right and wrong.
Expand Down Expand Up @@ -79,17 +70,6 @@ def test_failed_coverage(self) -> None:
[1,2,3],
missing="37",
)
# If the missing lines possibilities are wrong, the msg shows right.
msg = r"None of the missing choices matched '3'"
with pytest.raises(AssertionError, match=msg):
self.check_coverage("""\
a = 1
if a == 2:
a = 3
""",
[1,2,3],
missing=("37", "4-10"),
)

def test_exceptions_really_fail(self) -> None:
# An assert in the checked code will really raise up to us.
Expand Down Expand Up @@ -502,6 +482,7 @@ def test_continue(self) -> None:
)

def test_strange_unexecuted_continue(self) -> None:
# This used to be true, but no longer is:
# Peephole optimization of jumps to jumps can mean that some statements
# never hit the line tracer. The behavior is different in different
# versions of Python, so be careful when running this test.
Expand Down Expand Up @@ -529,7 +510,7 @@ def test_strange_unexecuted_continue(self) -> None:
assert a == 33 and b == 50 and c == 50
""",
lines=[1,2,3,4,5,6,8,9,10, 12,13,14,15,16,17,19,20,21],
missing=["", "6"],
missing="",
)

def test_import(self) -> None:
Expand Down Expand Up @@ -682,14 +663,13 @@ def test_module_docstring(self) -> None:
""",
[2, 3],
)
lines = [2, 3, 4]
self.check_coverage("""\
# Start with a comment, because it changes the behavior(!?)
'''I am a module docstring.'''
a = 3
b = 4
""",
lines,
[2, 3, 4],
)


Expand Down

0 comments on commit 5c70761

Please sign in to comment.