Skip to content

Commit 5c70761

Browse files
committed
test(refactor): tests no longer need to account for differences in missing statements
1 parent e05f60c commit 5c70761

File tree

2 files changed

+6
-33
lines changed

2 files changed

+6
-33
lines changed

tests/coveragetest.py

+3-10
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def check_coverage(
151151
self,
152152
text: str,
153153
lines: Sequence[TLineNo] | Sequence[list[TLineNo]] | None = None,
154-
missing: str | Sequence[str] = "",
154+
missing: str = "",
155155
report: str = "",
156156
excludes: Iterable[str] | None = None,
157157
partials: Iterable[str] = (),
@@ -226,15 +226,8 @@ def check_coverage(
226226
assert False, f"None of the lines choices matched {statements!r}"
227227

228228
missing_formatted = analysis.missing_formatted()
229-
if isinstance(missing, str):
230-
msg = f"missing: {missing_formatted!r} != {missing!r}"
231-
assert missing_formatted == missing, msg
232-
else:
233-
for missing_list in missing:
234-
if missing_formatted == missing_list:
235-
break
236-
else:
237-
assert False, f"None of the missing choices matched {missing_formatted!r}"
229+
msg = f"missing: {missing_formatted!r} != {missing!r}"
230+
assert missing_formatted == missing, msg
238231

239232
if arcs is not None:
240233
# print("Possible arcs:")

tests/test_coverage.py

+3-23
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,6 @@ def test_successful_coverage(self) -> None:
4141
[1,2,3],
4242
missing="3",
4343
)
44-
# You can specify a list of possible missing lines.
45-
self.check_coverage("""\
46-
a = 1
47-
if a == 2:
48-
a = 3
49-
""",
50-
[1,2,3],
51-
missing=("47-49", "3", "100,102"),
52-
)
5344

5445
def test_failed_coverage(self) -> None:
5546
# If the lines are wrong, the message shows right and wrong.
@@ -79,17 +70,6 @@ def test_failed_coverage(self) -> None:
7970
[1,2,3],
8071
missing="37",
8172
)
82-
# If the missing lines possibilities are wrong, the msg shows right.
83-
msg = r"None of the missing choices matched '3'"
84-
with pytest.raises(AssertionError, match=msg):
85-
self.check_coverage("""\
86-
a = 1
87-
if a == 2:
88-
a = 3
89-
""",
90-
[1,2,3],
91-
missing=("37", "4-10"),
92-
)
9373

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

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

535516
def test_import(self) -> None:
@@ -682,14 +663,13 @@ def test_module_docstring(self) -> None:
682663
""",
683664
[2, 3],
684665
)
685-
lines = [2, 3, 4]
686666
self.check_coverage("""\
687667
# Start with a comment, because it changes the behavior(!?)
688668
'''I am a module docstring.'''
689669
a = 3
690670
b = 4
691671
""",
692-
lines,
672+
[2, 3, 4],
693673
)
694674

695675

0 commit comments

Comments
 (0)