Skip to content

Commit 124ef0a

Browse files
committed
test: no longer need to support multiple 'lines'
Since 3.10 is our minimum, and it conforms to PEP 626, we know what lines will be reported, and don't need multiple options.
1 parent 207f818 commit 124ef0a

File tree

2 files changed

+13
-55
lines changed

2 files changed

+13
-55
lines changed

tests/coveragetest.py

Lines changed: 7 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def check_coverage(
145145
self,
146146
text: str,
147147
*,
148-
lines: Sequence[TLineNo] | Sequence[list[TLineNo]] | None = None,
148+
lines: Sequence[TLineNo] | None = None,
149149
missing: str = "",
150150
report: str = "",
151151
excludes: Iterable[str] | None = None,
@@ -157,10 +157,9 @@ def check_coverage(
157157
"""Check the coverage measurement of `text`.
158158
159159
The source `text` is run and measured. `lines` are the line numbers
160-
that are executable, or a list of possible line numbers, any of which
161-
could match. `missing` are the lines not executed, `excludes` are
162-
regexes to match against for excluding lines, and `report` is the text
163-
of the measurement report.
160+
that are executable, `missing` are the lines not executed, `excludes`
161+
are regexes to match against for excluding lines, and `report` is the
162+
text of the measurement report.
164163
165164
For branch measurement, `branchz` is a string that can be decoded into
166165
arcs in the code (see `arcz_to_arcs` for the encoding scheme).
@@ -200,42 +199,9 @@ def check_coverage(
200199
analysis = cov._analyze(mod)
201200
statements = sorted(analysis.statements)
202201
if lines:
203-
if isinstance(lines[0], int):
204-
# lines is just a list of numbers, it must match the statements
205-
# found in the code.
206-
assert statements == lines, f"lines: {statements!r} != {lines!r}"
207-
else:
208-
# lines is a list of possible line number lists, one of them
209-
# must match.
210-
for i, line_list in enumerate(lines): # pylint: disable=unused-variable
211-
if statements == line_list:
212-
# PYVERSIONS: we might be able to trim down multiple
213-
# lines passed into this function.
214-
# Uncomment this code, run the whole test suite, then
215-
# sort /tmp/check_coverage_multi_line.out to group the
216-
# tests together and see if any of the `lines` elements
217-
# haven't been used.
218-
# One of the calls in test_successful_coverage passes
219-
# three `lines` elements, only one of which is right.
220-
# We need to keep that test until we can delete the
221-
# multi-lines option entirely.
222-
#
223-
# import inspect, platform
224-
# frinfo = inspect.getframeinfo(inspect.currentframe().f_back)
225-
# version = "{} {}.{}".format(
226-
# platform.python_implementation(),
227-
# *sys.version_info[:2],
228-
# )
229-
# with open("/tmp/check_coverage_multi_line.out", "a") as f:
230-
# print(
231-
# f"{frinfo.filename}@{frinfo.lineno}: "
232-
# + f"lines {i + 1}/{len(lines)}: {version}",
233-
# file=f,
234-
# )
235-
break
236-
else:
237-
assert False, f"None of the lines choices matched {statements!r}"
238-
202+
# lines is a list of numbers, it must match the statements
203+
# found in the code.
204+
assert statements == lines, f"lines: {statements!r} != {lines!r}"
239205
missing_formatted = analysis.missing_formatted()
240206
msg = f"missing: {missing_formatted!r} != {missing!r}"
241207
assert missing_formatted == missing, msg

tests/test_coverage.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,6 @@ def test_successful_coverage(self) -> None:
2626
""",
2727
lines=[1, 2],
2828
)
29-
# You can provide a list of possible statement matches.
30-
self.check_coverage(
31-
"""\
32-
a = 1
33-
b = 2
34-
""",
35-
lines=([100], [1, 2], [1723, 47]),
36-
)
3729
# You can specify missing lines.
3830
self.check_coverage(
3931
"""\
@@ -167,7 +159,7 @@ def test_expression(self) -> None:
167159
12
168160
23
169161
""",
170-
lines=([1, 2], [2]),
162+
lines=[1, 2],
171163
missing="",
172164
)
173165
self.check_coverage(
@@ -176,7 +168,7 @@ def test_expression(self) -> None:
176168
23
177169
a = 3
178170
""",
179-
lines=([1, 2, 3], [3]),
171+
lines=[1, 2, 3],
180172
missing="",
181173
)
182174
self.check_coverage(
@@ -185,7 +177,7 @@ def test_expression(self) -> None:
185177
1 + \\
186178
2
187179
""",
188-
lines=([1, 2], [2]),
180+
lines=[1, 2],
189181
missing="",
190182
)
191183
self.check_coverage(
@@ -195,7 +187,7 @@ def test_expression(self) -> None:
195187
2
196188
a = 4
197189
""",
198-
lines=([1, 2, 4], [4]),
190+
lines=[1, 2, 4],
199191
missing="",
200192
)
201193

@@ -700,7 +692,7 @@ def test_extra_doc_string(self) -> None:
700692
b = 3
701693
assert (a,b) == (1,3)
702694
""",
703-
lines=([1, 3, 4], [1, 2, 3, 4]),
695+
lines=[1, 2, 3, 4],
704696
missing="",
705697
)
706698
self.check_coverage(
@@ -713,7 +705,7 @@ def test_extra_doc_string(self) -> None:
713705
c = 6
714706
assert (a,b,c) == (1,3,6)
715707
""",
716-
lines=([1, 3, 6, 7], [1, 2, 3, 4, 5, 6, 7]),
708+
lines=[1, 2, 3, 4, 5, 6, 7],
717709
missing="",
718710
)
719711

0 commit comments

Comments
 (0)