|
11 | 11 |
|
12 | 12 | import pytest
|
13 | 13 |
|
14 |
| -import coverage |
15 | 14 | from coverage.plugin import CodeRegion
|
16 | 15 | from coverage.regions import code_regions
|
17 | 16 |
|
| 17 | +from tests.helpers import all_our_source_files |
| 18 | + |
18 | 19 |
|
19 | 20 | def test_code_regions() -> None:
|
20 | 21 | regions = code_regions(textwrap.dedent("""\
|
@@ -90,24 +91,21 @@ def test_real_code_regions() -> None:
|
90 | 91 | # Run code_regions on most of the coverage source code, checking that it
|
91 | 92 | # succeeds and there are no overlaps.
|
92 | 93 |
|
93 |
| - cov_dir = Path(coverage.__file__).parent.parent |
94 | 94 | any_fails = False
|
95 |
| - # To run against all the files in the tox venvs: |
96 |
| - # for source_file in cov_dir.rglob("*.py"): |
97 |
| - for sub in [".", "ci", "coverage", "lab", "tests"]: |
98 |
| - for source_file in (cov_dir / sub).glob("*.py"): |
99 |
| - regions = code_regions(source_file.read_text(encoding="utf-8")) |
100 |
| - for kind in ["function", "class"]: |
101 |
| - kind_regions = [reg for reg in regions if reg.kind == kind] |
102 |
| - line_counts = collections.Counter( |
103 |
| - lno for reg in kind_regions for lno in reg.lines |
| 95 | + for source_file, source in all_our_source_files(): |
| 96 | + regions = code_regions(source) |
| 97 | + for kind in ["function", "class"]: |
| 98 | + kind_regions = [reg for reg in regions if reg.kind == kind] |
| 99 | + line_counts = collections.Counter( |
| 100 | + lno for reg in kind_regions for lno in reg.lines |
| 101 | + ) |
| 102 | + overlaps = [line for line, count in line_counts.items() if count > 1] |
| 103 | + if overlaps: # pragma: only failure |
| 104 | + print( |
| 105 | + f"{kind.title()} overlaps in {source_file.relative_to(Path.cwd())}: " |
| 106 | + + f"{overlaps}" |
104 | 107 | )
|
105 |
| - overlaps = [line for line, count in line_counts.items() if count > 1] |
106 |
| - if overlaps: # pragma: only failure |
107 |
| - print( |
108 |
| - f"{kind.title()} overlaps in {source_file.relative_to(Path.cwd())}: " |
109 |
| - + f"{overlaps}" |
110 |
| - ) |
111 |
| - any_fails = True |
| 108 | + any_fails = True |
| 109 | + |
112 | 110 | if any_fails:
|
113 | 111 | pytest.fail("Overlaps were found") # pragma: only failure
|
0 commit comments