@jesdi/skills 0.0.80 → 0.0.82
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -1
- package/skills/crap-gate/launcher.sh +104 -0
- package/skills/crap-gate/run.sh +15 -75
- package/skills/crap-gate/test_launcher.py +39 -0
- package/skills/implement-spec/launcher.sh +104 -0
- package/skills/implement-spec/run.sh +10 -89
- package/skills/implement-spec/tests/test_launcher.py +138 -0
- package/skills/test-prune/SKILL.md +4 -2
- package/skills/test-prune/prune_strengthen.py +24 -12
- package/skills/test-prune/tests/test_prune_guards.py +1 -1
- package/skills/test-prune/tests/test_prune_inputs.py +10 -5
- package/skills/test-prune/tests/test_prune_strengthen.py +34 -12
- package/skills/test-weigh-in/SKILL.md +16 -0
- package/skills/test-weigh-in/dashboard.html +112 -0
- package/skills/test-weigh-in/launcher.sh +104 -0
- package/skills/test-weigh-in/rules.toml +134 -0
- package/skills/test-weigh-in/run.sh +21 -0
- package/skills/test-weigh-in/tests/brittle_repo.py +79 -0
- package/skills/test-weigh-in/tests/conftest.py +35 -0
- package/skills/test-weigh-in/tests/fixture_repo.py +99 -0
- package/skills/test-weigh-in/tests/kill_repo.py +87 -0
- package/skills/test-weigh-in/tests/maint_repo.py +139 -0
- package/skills/test-weigh-in/tests/map_fixture.py +56 -0
- package/skills/test-weigh-in/tests/pt_repo.py +46 -0
- package/skills/test-weigh-in/tests/red_repo.py +44 -0
- package/skills/test-weigh-in/tests/rule_repo.py +208 -0
- package/skills/test-weigh-in/tests/rules_fixture.py +65 -0
- package/skills/test-weigh-in/tests/smell_repo.py +138 -0
- package/skills/test-weigh-in/tests/test_brittleness.py +75 -0
- package/skills/test-weigh-in/tests/test_brittleness_history.py +168 -0
- package/skills/test-weigh-in/tests/test_coverage_run.py +201 -0
- package/skills/test-weigh-in/tests/test_coverage_value.py +76 -0
- package/skills/test-weigh-in/tests/test_dashboard_map.py +20 -0
- package/skills/test-weigh-in/tests/test_interpreters.py +115 -0
- package/skills/test-weigh-in/tests/test_kill_matrix.py +126 -0
- package/skills/test-weigh-in/tests/test_maintainability_smells.py +113 -0
- package/skills/test-weigh-in/tests/test_mutation_recovery.py +67 -0
- package/skills/test-weigh-in/tests/test_mutation_sampling.py +53 -0
- package/skills/test-weigh-in/tests/test_mutation_score.py +140 -0
- package/skills/test-weigh-in/tests/test_mutation_stale.py +30 -0
- package/skills/test-weigh-in/tests/test_mutmut_contract.py +43 -0
- package/skills/test-weigh-in/tests/test_ruff_pt_smells.py +45 -0
- package/skills/test-weigh-in/tests/test_runs.py +156 -0
- package/skills/test-weigh-in/tests/test_score.py +26 -0
- package/skills/test-weigh-in/tests/test_scoring.py +154 -0
- package/skills/test-weigh-in/tests/test_smell_rules.py +96 -0
- package/skills/test-weigh-in/tests/test_smells.py +71 -0
- package/skills/test-weigh-in/tests/test_walking_skeleton.py +91 -0
- package/skills/test-weigh-in/tests/testdata/default_repo/demo/__init__.py +0 -0
- package/skills/test-weigh-in/tests/testdata/default_repo/demo/board.py +2 -0
- package/skills/test-weigh-in/tests/testdata/default_repo/demo/config.py +2 -0
- package/skills/test-weigh-in/tests/testdata/default_repo/pyproject.toml +8 -0
- package/skills/test-weigh-in/tests/testdata/default_repo/tests/test_board.py +19 -0
- package/skills/test-weigh-in/tests/testdata/default_repo/tests/test_config.py +19 -0
- package/skills/test-weigh-in/tests/testdata/default_repo/tests/test_parser.py +19 -0
- package/skills/test-weigh-in/tests/testdata/default_repo/tests/test_render.py +19 -0
- package/skills/test-weigh-in/tests/testdata/default_repo/tests/test_report.py +17 -0
- package/skills/test-weigh-in/tests/testdata/default_repo/tests/test_session.py +19 -0
- package/skills/test-weigh-in/tests/testdata/default_repo/tests/test_store.py +17 -0
- package/skills/test-weigh-in/tests/testdata/default_repo/tests/test_sync.py +17 -0
- package/skills/test-weigh-in/tests/testdata/default_repo/uv.lock +1 -0
- package/skills/test-weigh-in/weigh.py +133 -0
- package/skills/test-weigh-in/weigh_coverage.py +154 -0
- package/skills/test-weigh-in/weigh_dashboard.py +72 -0
- package/skills/test-weigh-in/weigh_env.py +112 -0
- package/skills/test-weigh-in/weigh_git.py +119 -0
- package/skills/test-weigh-in/weigh_inventory.py +49 -0
- package/skills/test-weigh-in/weigh_mutation.py +190 -0
- package/skills/test-weigh-in/weigh_pytest_plugin.py +70 -0
- package/skills/test-weigh-in/weigh_ruff.py +22 -0
- package/skills/test-weigh-in/weigh_rules.py +65 -0
- package/skills/test-weigh-in/weigh_runs.py +134 -0
- package/skills/test-weigh-in/weigh_score.py +80 -0
- package/skills/test-weigh-in/weigh_smells.py +355 -0
- package/skills/test-weigh-in/weigh_snapshot.py +49 -0
- package/skills-manifest.json +13 -7
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
"""Ticket tw/s4-coverage/07: the coverage run, flakiness, red suites, unique coverage and the overlay race.
|
|
2
|
+
|
|
3
|
+
Snapshot interface the tests pin (the spec leaves the JSON keys open), on top of fixture_repo.py:
|
|
4
|
+
tests[node].coverage {repo-relative path: sorted covered lines}: the union of the test's passing cases,
|
|
5
|
+
{} for a failed or skipped test
|
|
6
|
+
tests[node].flaky true when the outcome differs between the plain and the coverage run
|
|
7
|
+
tests[node].unique_coverage number of lines the test covers that no other passing test covers
|
|
8
|
+
overlaps [{"tests": [node, node], "jaccard": float}] for passing pairs with jaccard >= 0.9
|
|
9
|
+
metrics.branch_coverage / metrics.no_unique_coverage {value, score}; value in percent
|
|
10
|
+
Stdout: "<n> flaky test(s)" and "<n> tests are failing" warnings.
|
|
11
|
+
"""
|
|
12
|
+
import time
|
|
13
|
+
from concurrent.futures import ThreadPoolExecutor
|
|
14
|
+
|
|
15
|
+
import pytest
|
|
16
|
+
|
|
17
|
+
import fixture_repo
|
|
18
|
+
from fixture_repo import FAKECLOCK, build_repo, git, load, snapshots, weigh
|
|
19
|
+
from red_repo import FAILING, SKIPPED, red_suite, skipped_suite
|
|
20
|
+
|
|
21
|
+
KEY = "github.com/jesdi/demo"
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def ok(result):
|
|
25
|
+
assert result.returncode == 0, result.stdout + result.stderr
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def commit(repo, files):
|
|
29
|
+
for rel, text in files.items():
|
|
30
|
+
(repo / rel).parent.mkdir(parents=True, exist_ok=True)
|
|
31
|
+
(repo / rel).write_text(text)
|
|
32
|
+
git(repo, "add", "-A")
|
|
33
|
+
git(repo, "commit", "-q", "-m", "extra")
|
|
34
|
+
return repo
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def snap(home):
|
|
38
|
+
(path,) = snapshots(home, KEY)
|
|
39
|
+
return load(path)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
PARSE = "".join(f"def f{k}():\n return {k}\n" for k in range(14)) # f<k> body is line 2k+2
|
|
43
|
+
PARSE_TEST = '''import pytest
|
|
44
|
+
from demo import parse
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
@pytest.mark.parametrize("n", range(14))
|
|
48
|
+
def test_parse(n):
|
|
49
|
+
getattr(parse, f"f{n}")()
|
|
50
|
+
assert n != 13
|
|
51
|
+
'''
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def test_a_parametrized_test_is_one_test_with_the_union_of_its_passing_cases(tmp_path, home, cache):
|
|
55
|
+
repo = build_repo(tmp_path / "demo")
|
|
56
|
+
site = next((repo / ".venv" / "lib").glob("python*/site-packages"))
|
|
57
|
+
(site / "fakeclock.py").write_text(FAKECLOCK.replace("1.125", "0.1"))
|
|
58
|
+
commit(repo, {"demo/parse.py": PARSE, "tests/test_parse.py": PARSE_TEST})
|
|
59
|
+
result = weigh(repo, home, "--pytest-args", "tests/test_parse.py", cache=cache)
|
|
60
|
+
ok(result)
|
|
61
|
+
data = snap(home)
|
|
62
|
+
assert (data["inventory"]["tests"], data["inventory"]["cases"]) == (1, 14)
|
|
63
|
+
test = data["tests"]["tests/test_parse.py::test_parse"]
|
|
64
|
+
assert (test["outcome"], test["cases"]) == ("failed", 14)
|
|
65
|
+
assert test["duration"] == pytest.approx(1.4)
|
|
66
|
+
assert test["coverage"]["demo/parse.py"] == [2 * k + 2 for k in range(13)]
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
RETRY = 'import sys\n\n\ndef test_retry():\n assert "coverage" not in sys.modules\n'
|
|
70
|
+
# covered by test_solo alone, so its unique coverage keeps no_unique_coverage below 100%
|
|
71
|
+
SOLO = {"demo/solo.py": "def solo():\n return 1\n",
|
|
72
|
+
"tests/test_solo.py": "from demo.solo import solo\n\n\ndef test_solo():\n assert solo() == 1\n"}
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def test_a_test_that_differs_between_the_runs_is_flaky(tmp_path, home, cache):
|
|
76
|
+
repo = commit(build_repo(tmp_path / "demo"), {"tests/test_retry.py": RETRY, **SOLO})
|
|
77
|
+
result = weigh(repo, home, "--pytest-args", "tests/test_retry.py tests/test_board.py tests/test_solo.py", cache=cache)
|
|
78
|
+
ok(result)
|
|
79
|
+
tests = snap(home)["tests"]
|
|
80
|
+
assert tests["tests/test_retry.py::test_retry"]["flaky"] is True
|
|
81
|
+
assert [n for n, t in tests.items() if t.get("flaky")] == ["tests/test_retry.py::test_retry"]
|
|
82
|
+
assert "1 flaky test" in result.stdout
|
|
83
|
+
# failing under coverage, test_retry gives no value: it is out of the count, yet in the base of all tests
|
|
84
|
+
others = [t for n, t in tests.items() if n != "tests/test_retry.py::test_retry"]
|
|
85
|
+
assert snap(home)["metrics"]["no_unique_coverage"]["value"] == pytest.approx(
|
|
86
|
+
100 * sum(not t["unique_coverage"] for t in others) / len(tests))
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def test_a_repo_inside_a_folder_named_tests_keeps_its_source_coverage(tmp_path, home, cache):
|
|
90
|
+
repo = commit(build_repo(tmp_path / "tests" / "demo"), SOLO)
|
|
91
|
+
ok(weigh(repo, home, "--pytest-args", "tests/test_solo.py", cache=cache))
|
|
92
|
+
assert snap(home)["tests"]["tests/test_solo.py::test_solo"]["coverage"]["demo/solo.py"] == [2]
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def test_a_red_suite_is_measured_without_the_failing_tests_value(tmp_path, home, cache):
|
|
96
|
+
repo = red_suite(tmp_path / "demo")
|
|
97
|
+
result = weigh(repo, home, cache=cache)
|
|
98
|
+
ok(result)
|
|
99
|
+
data = snap(home)
|
|
100
|
+
inv = data["inventory"]
|
|
101
|
+
assert inv["tests"] == 40 and inv["runtime_seconds"] == pytest.approx(45)
|
|
102
|
+
assert inv["test_lines"] == sum(len(p.read_text().splitlines()) for p in (repo / "tests").glob("test_*.py"))
|
|
103
|
+
failed = {n for n, t in data["tests"].items() if t["outcome"] == "failed"}
|
|
104
|
+
assert failed == set(FAILING)
|
|
105
|
+
assert all(data["tests"][n]["coverage"] == {} for n in failed)
|
|
106
|
+
assert not any(set(pair["tests"]) & failed for pair in data["overlaps"])
|
|
107
|
+
assert data["metrics"]["branch_coverage"]["value"] == pytest.approx(50)
|
|
108
|
+
# failing tests give no value: not in the count, yet in the base, a percentage of all 40 tests (req 17)
|
|
109
|
+
passed = [t for t in data["tests"].values() if t["outcome"] == "passed"]
|
|
110
|
+
assert all(data["tests"][n]["unique_coverage"] == 0 for n in failed)
|
|
111
|
+
assert data["metrics"]["no_unique_coverage"]["value"] == pytest.approx(
|
|
112
|
+
100 * sum(not t["unique_coverage"] for t in passed) / 40)
|
|
113
|
+
assert data["pillars"]["regression"]["partial"] and data["pillars"]["economy"]["partial"]
|
|
114
|
+
assert "3 tests are failing" in result.stdout
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def test_skipped_tests_cost_without_value(tmp_path, home, cache):
|
|
118
|
+
repo = skipped_suite(tmp_path / "demo")
|
|
119
|
+
result = weigh(repo, home, cache=cache)
|
|
120
|
+
ok(result)
|
|
121
|
+
data = snap(home)
|
|
122
|
+
assert data["inventory"]["tests"] == 40
|
|
123
|
+
assert data["inventory"]["test_lines"] == sum(len(p.read_text().splitlines()) for p in (repo / "tests").glob("test_*.py"))
|
|
124
|
+
for node in SKIPPED:
|
|
125
|
+
assert data["tests"][node]["outcome"] == "skipped"
|
|
126
|
+
assert data["tests"][node]["coverage"] == {}
|
|
127
|
+
assert not any(set(pair["tests"]) & set(SKIPPED) for pair in data["overlaps"])
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
BOARD = ["def render(n):", " return str(n)", *[f"# line {n}" for n in range(3, 9)], "def part1():",
|
|
131
|
+
*[f" _ = {n}" for n in range(10, 21)], "def part2():", *[f" _ = {n}" for n in range(22, 26)],
|
|
132
|
+
"def part3():", " _ = 27"]
|
|
133
|
+
BOARD_TESTS = '''from demo import board
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
def _make(name, *parts):
|
|
137
|
+
def run():
|
|
138
|
+
for part in parts:
|
|
139
|
+
getattr(board, part)()
|
|
140
|
+
return run
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
test_board_empty = _make("test_board_empty", "part1")
|
|
144
|
+
test_board_none = _make("test_board_none", "part1", "{other}")
|
|
145
|
+
'''
|
|
146
|
+
EMPTY, NONE = "tests/test_board_cases.py::test_board_empty", "tests/test_board_cases.py::test_board_none"
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
def board_run(tmp_path, home, cache, other):
|
|
150
|
+
assert BOARD.index("def part1():") == 8 and BOARD.index("def part2():") == 20
|
|
151
|
+
repo = commit(build_repo(tmp_path / "demo"), {"demo/board.py": "\n".join(BOARD) + "\n",
|
|
152
|
+
"tests/test_board_cases.py": BOARD_TESTS.replace("{other}", other)})
|
|
153
|
+
ok(weigh(repo, home, "--pytest-args", "tests/test_board_cases.py", cache=cache))
|
|
154
|
+
return snap(home)
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
def test_a_test_covered_by_another_has_no_unique_coverage_and_a_far_pair_is_no_overlap(tmp_path, home, cache):
|
|
158
|
+
data = board_run(tmp_path, home, cache, "part2") # lines 10-20 against 10-25: Jaccard 11/15
|
|
159
|
+
assert data["tests"][EMPTY]["coverage"]["demo/board.py"] == list(range(10, 21))
|
|
160
|
+
assert data["tests"][NONE]["coverage"]["demo/board.py"] == [*range(10, 21), *range(22, 26)]
|
|
161
|
+
assert data["tests"][EMPTY]["unique_coverage"] == 0
|
|
162
|
+
assert data["tests"][NONE]["unique_coverage"] > 0
|
|
163
|
+
assert data["metrics"]["no_unique_coverage"]["value"] == pytest.approx(50)
|
|
164
|
+
assert data["overlaps"] == []
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
def test_a_pair_at_jaccard_09_or_more_is_an_overlap(tmp_path, home, cache):
|
|
168
|
+
data = board_run(tmp_path, home, cache, "part3") # lines 10-20 against 10-20 and 27: Jaccard 11/12
|
|
169
|
+
(pair,) = data["overlaps"]
|
|
170
|
+
assert sorted(pair["tests"]) == sorted([EMPTY, NONE])
|
|
171
|
+
assert pair["jaccard"] == pytest.approx(11 / 12)
|
|
172
|
+
assert data["tests"][EMPTY]["unique_coverage"] == 0
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
def test_two_first_runs_share_one_complete_overlay(tmp_path, home, cache, monkeypatch):
|
|
176
|
+
fresh = tmp_path / "fresh-cache"
|
|
177
|
+
repos = [build_repo(tmp_path / "work" / name, origin=f"git@github.com:jesdi/{name}.git") for name in ("a", "b")]
|
|
178
|
+
homes = [home / name for name in ("a", "b")]
|
|
179
|
+
for h in homes:
|
|
180
|
+
h.mkdir()
|
|
181
|
+
real = fixture_repo.uv()
|
|
182
|
+
slow = tmp_path / "slow-uv" # the overlay install takes 3s, so the second run starts while the first is mid-build
|
|
183
|
+
slow.write_text(f'#!/bin/sh\ncase "$1" in pip) sleep 3;; esac\nexec {real} "$@"\n')
|
|
184
|
+
slow.chmod(0o755)
|
|
185
|
+
monkeypatch.setattr(fixture_repo, "uv", lambda: str(slow))
|
|
186
|
+
|
|
187
|
+
def staggered(i):
|
|
188
|
+
time.sleep(i)
|
|
189
|
+
return weigh(repos[i], homes[i], cache=fresh)
|
|
190
|
+
|
|
191
|
+
with ThreadPoolExecutor(2) as pool:
|
|
192
|
+
results = list(pool.map(staggered, (0, 1)))
|
|
193
|
+
for result in results:
|
|
194
|
+
ok(result)
|
|
195
|
+
for name, h in zip("ab", homes):
|
|
196
|
+
(path,) = snapshots(h, f"github.com/jesdi/{name}")
|
|
197
|
+
tests = load(path)["tests"]
|
|
198
|
+
assert len(tests) == 40 and all(t["coverage"] for t in tests.values())
|
|
199
|
+
(overlay,) = fresh.iterdir()
|
|
200
|
+
assert overlay.name.startswith("overlay-")
|
|
201
|
+
assert (overlay / "weigh_pytest_plugin.py").is_file() and (overlay / "coverage").is_dir()
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"""The coverage run's value data: branches count in uniqueness and overlap, an expected failure keeps its coverage,
|
|
2
|
+
and a coverage report that fails stops the run instead of reading as empty coverage."""
|
|
3
|
+
import subprocess
|
|
4
|
+
import sys
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
import pytest
|
|
8
|
+
|
|
9
|
+
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
|
|
10
|
+
|
|
11
|
+
from fixture_repo import build_repo, git, load, snapshots, weigh
|
|
12
|
+
from weigh_env import SetupError
|
|
13
|
+
from weigh_runs import _report
|
|
14
|
+
|
|
15
|
+
KEY = "github.com/jesdi/demo"
|
|
16
|
+
FLAG = "def flag(x):\n if x:\n pass\n return 2\n"
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def run(tmp_path, home, cache, files, args):
|
|
20
|
+
repo = build_repo(tmp_path / "demo")
|
|
21
|
+
for rel, text in files.items():
|
|
22
|
+
(repo / rel).write_text(text)
|
|
23
|
+
git(repo, "add", "-A")
|
|
24
|
+
git(repo, "commit", "-q", "-m", "extra")
|
|
25
|
+
result = weigh(repo, home, "--pytest-args", args, cache=cache)
|
|
26
|
+
assert result.returncode == 0, result.stdout + result.stderr
|
|
27
|
+
(path,) = snapshots(home, KEY)
|
|
28
|
+
return load(path)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def test_a_test_that_alone_takes_a_branch_has_unique_coverage_on_the_same_lines(tmp_path, home, cache):
|
|
32
|
+
tests = ("from demo.flag import flag\n\n\ndef test_both():\n flag(True)\n flag(False)\n\n\n"
|
|
33
|
+
"def test_true():\n flag(True)\n")
|
|
34
|
+
data = run(tmp_path, home, cache, {"demo/flag.py": FLAG, "tests/test_flag.py": tests}, "tests/test_flag.py")
|
|
35
|
+
both, true = data["tests"]["tests/test_flag.py::test_both"], data["tests"]["tests/test_flag.py::test_true"]
|
|
36
|
+
assert both["coverage"] == true["coverage"] == {"demo/flag.py": [2, 3, 4]}
|
|
37
|
+
assert both["branches"] == {"demo/flag.py": [[2, 3], [2, 4]]} and true["branches"] == {"demo/flag.py": [[2, 3]]}
|
|
38
|
+
assert (both["unique_coverage"], true["unique_coverage"]) == (1, 0)
|
|
39
|
+
assert data["overlaps"] == [] # 4 of 5 lines and branches shared: Jaccard 0.8
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def test_a_branch_of_a_multi_line_condition_counts_as_unique(tmp_path, home, cache):
|
|
43
|
+
# the tracer records the true branch from line 3, the condition's last line; the report from line 2, its first
|
|
44
|
+
source = "def both(a, b):\n if (a\n and b):\n return 1\n return 2\n"
|
|
45
|
+
tests = ("from demo.both import both\n\n\ndef test_both_true():\n both(1, 1)\n\n\n"
|
|
46
|
+
"def test_first_false():\n both(0, 1)\n")
|
|
47
|
+
data = run(tmp_path, home, cache, {"demo/both.py": source, "tests/test_both.py": tests}, "tests/test_both.py")
|
|
48
|
+
true = data["tests"]["tests/test_both.py::test_both_true"]
|
|
49
|
+
assert [2, 4] in true["branches"]["demo/both.py"]
|
|
50
|
+
assert true["unique_coverage"] > 0
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
@pytest.mark.parametrize("arg", ["a, b", "$HOME"])
|
|
54
|
+
def test_a_test_id_with_a_comma_or_a_dollar_name_keeps_its_coverage(tmp_path, home, cache, arg):
|
|
55
|
+
# coverage splits its config lists at commas and expands $NAME there: the context regex must survive both
|
|
56
|
+
tests = ("import pytest\nfrom demo.flag import flag\n\n\n"
|
|
57
|
+
f"@pytest.mark.parametrize('arg', [{arg!r}])\ndef test_odd(arg):\n flag(True)\n")
|
|
58
|
+
data = run(tmp_path, home, cache, {"demo/flag.py": FLAG, "tests/test_odd.py": tests}, "tests/test_odd.py")
|
|
59
|
+
assert data["tests"]["tests/test_odd.py::test_odd"]["coverage"] == {"demo/flag.py": [2, 3, 4]}
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def test_an_expected_failure_keeps_its_coverage(tmp_path, home, cache):
|
|
63
|
+
tests = ("import pytest\nfrom demo.flag import flag\n\n\n@pytest.mark.xfail\ndef test_xfail():\n"
|
|
64
|
+
" flag(False)\n assert False\n")
|
|
65
|
+
data = run(tmp_path, home, cache, {"demo/flag.py": FLAG, "tests/test_xfail.py": tests}, "tests/test_xfail.py")
|
|
66
|
+
test = data["tests"]["tests/test_xfail.py::test_xfail"]
|
|
67
|
+
assert test["outcome"] == "passed" and test["coverage"] == {"demo/flag.py": [2, 4]}
|
|
68
|
+
assert test["unique_coverage"] > 0 and data["metrics"]["no_unique_coverage"]["value"] == 0
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def test_a_failing_coverage_report_is_an_error_with_its_output(tmp_path):
|
|
72
|
+
def coverage(*args):
|
|
73
|
+
return subprocess.CompletedProcess(args, 1, "", "Couldn't parse demo/x.py")
|
|
74
|
+
|
|
75
|
+
with pytest.raises(SetupError, match="coverage json exited 1:\nCouldn't parse demo/x.py"):
|
|
76
|
+
_report(coverage, tmp_path / "rc", tmp_path / "data", tmp_path / "out.json", "(?!)")
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"""The Map tab draws the tests that give value: a test that passed only in the plain run (flaky) is not a dot."""
|
|
2
|
+
import json
|
|
3
|
+
import sys
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
|
|
7
|
+
|
|
8
|
+
import map_fixture
|
|
9
|
+
from weigh_dashboard import write_dashboard
|
|
10
|
+
from weigh_rules import load
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def test_a_flaky_test_is_not_drawn(tmp_path):
|
|
14
|
+
map_fixture.build(tmp_path)
|
|
15
|
+
data = json.loads((tmp_path / "snapshot.json").read_text())
|
|
16
|
+
data["tests"]["tests/test_twin.py::test_twin_1"]["flaky"] = True
|
|
17
|
+
html = write_dashboard(tmp_path, data, load()).read_text()
|
|
18
|
+
page = json.loads(html.split("const data = ", 1)[1].split(";\n", 1)[0])
|
|
19
|
+
drawn = {d["test"] for d in page["map"]}
|
|
20
|
+
assert drawn == set(map_fixture.COVERAGE) - {"tests/test_twin.py::test_twin_1"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import shutil
|
|
2
|
+
import subprocess
|
|
3
|
+
|
|
4
|
+
import pytest
|
|
5
|
+
|
|
6
|
+
from fixture_repo import FAKECLOCK, build_repo, git, load, snapshots, uv, weigh
|
|
7
|
+
|
|
8
|
+
KEY = "github.com/jesdi/demo"
|
|
9
|
+
MARKER_CONFTEST = "def pytest_sessionstart(session):\n open({marker!r}, 'a').close()\n"
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def make_venv(path, pytest_version, python="3.12"):
|
|
13
|
+
"""A venv at `path` holding pytest and the fake clock the default repo's pytest config asks for."""
|
|
14
|
+
subprocess.run([uv(), "venv", "-q", "--python", python, str(path)], check=True)
|
|
15
|
+
subprocess.run([uv(), "pip", "install", "-q", "--python", str(path / "bin" / "python"), f"pytest=={pytest_version}"], check=True)
|
|
16
|
+
site = next((path / "lib").glob("python*/site-packages"))
|
|
17
|
+
(site / "fakeclock.py").write_text(FAKECLOCK)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def commit_all(repo):
|
|
21
|
+
git(repo, "add", "-A")
|
|
22
|
+
git(repo, "commit", "-q", "-m", "reshape")
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def plain_repo(tmp_path, venv_dir="venv", pytest_version="8.1.1", python="3.12"):
|
|
26
|
+
"""The default repo reshaped to a requirements.txt project: no uv.lock, its only venv in `venv_dir`."""
|
|
27
|
+
repo = build_repo(tmp_path / "demo")
|
|
28
|
+
shutil.rmtree(repo / ".venv")
|
|
29
|
+
git(repo, "rm", "-q", "uv.lock")
|
|
30
|
+
(repo / "requirements.txt").write_text(f"pytest=={pytest_version}\n")
|
|
31
|
+
if venv_dir:
|
|
32
|
+
make_venv(repo / venv_dir, pytest_version, python)
|
|
33
|
+
commit_all(repo)
|
|
34
|
+
return repo
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def guarded(repo, tmp_path):
|
|
38
|
+
"""Make any pytest session in `repo` leave a marker file; returns the marker's path."""
|
|
39
|
+
marker = tmp_path / "pytest-ran"
|
|
40
|
+
(repo / "conftest.py").write_text(MARKER_CONFTEST.format(marker=str(marker)))
|
|
41
|
+
commit_all(repo)
|
|
42
|
+
return marker
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def test_uv_repo_without_venv_gets_one_from_its_lock(tmp_path, home, cache):
|
|
46
|
+
repo = build_repo(tmp_path / "demo")
|
|
47
|
+
shutil.rmtree(repo / ".venv")
|
|
48
|
+
(repo / "pyproject.toml").write_text(
|
|
49
|
+
'[project]\nname = "demo"\nversion = "0.0.0"\nrequires-python = ">=3.10"\ndependencies = ["pytest==8.3.5"]\n'
|
|
50
|
+
'[tool.pytest.ini_options]\npythonpath = ["."]\nmarkers = ["e2e: slow end-to-end test"]\n'
|
|
51
|
+
)
|
|
52
|
+
(repo / "uv.lock").unlink() # the template lock is a stub uv cannot parse
|
|
53
|
+
subprocess.run([uv(), "lock", "-q"], cwd=repo, check=True)
|
|
54
|
+
commit_all(repo)
|
|
55
|
+
lock = (repo / "uv.lock").read_bytes()
|
|
56
|
+
result = weigh(repo, home, cache=cache)
|
|
57
|
+
assert result.returncode == 0, result.stdout + result.stderr
|
|
58
|
+
assert (repo / ".venv" / "bin" / "python").is_file()
|
|
59
|
+
assert (repo / "uv.lock").read_bytes() == lock
|
|
60
|
+
assert len(snapshots(home, KEY)) == 1
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def test_plain_venv_repo_is_measured_with_its_venv(tmp_path, home, cache):
|
|
64
|
+
repo = plain_repo(tmp_path)
|
|
65
|
+
result = weigh(repo, home, cache=cache)
|
|
66
|
+
assert result.returncode == 0, result.stdout + result.stderr
|
|
67
|
+
(snap,) = snapshots(home, KEY)
|
|
68
|
+
assert load(snap)["pytest_version"].startswith("8.1")
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def test_no_interpreter_stops_and_names_the_python_flag(tmp_path, home, cache):
|
|
72
|
+
repo = plain_repo(tmp_path, venv_dir=None)
|
|
73
|
+
result = weigh(repo, home, cache=cache)
|
|
74
|
+
assert result.returncode != 0
|
|
75
|
+
assert "--python" in result.stdout + result.stderr
|
|
76
|
+
assert snapshots(home, KEY) == []
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def test_explicit_python_wins_over_the_repos_venv(tmp_path, home, cache):
|
|
80
|
+
repo = build_repo(tmp_path / "demo")
|
|
81
|
+
make_venv(tmp_path / "py312", "8.2.2")
|
|
82
|
+
result = weigh(repo, home, "--python", str(tmp_path / "py312" / "bin" / "python"), cache=cache)
|
|
83
|
+
assert result.returncode == 0, result.stdout + result.stderr
|
|
84
|
+
(snap,) = snapshots(home, KEY)
|
|
85
|
+
assert load(snap)["pytest_version"].startswith("8.2")
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def test_pytest_at_the_minimum_is_accepted(tmp_path, home, cache):
|
|
89
|
+
repo = build_repo(tmp_path / "demo", pytest_version="7.0.0")
|
|
90
|
+
result = weigh(repo, home, cache=cache)
|
|
91
|
+
assert result.returncode == 0, result.stdout + result.stderr
|
|
92
|
+
(snap,) = snapshots(home, KEY)
|
|
93
|
+
assert load(snap)["pytest_version"].startswith("7.0")
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def test_pytest_below_the_minimum_is_refused_before_any_test(tmp_path, home, cache):
|
|
97
|
+
repo = plain_repo(tmp_path, venv_dir=".venv", pytest_version="6.2.5")
|
|
98
|
+
marker = guarded(repo, tmp_path)
|
|
99
|
+
result = weigh(repo, home, cache=cache)
|
|
100
|
+
assert result.returncode != 0
|
|
101
|
+
message = result.stdout + result.stderr
|
|
102
|
+
assert "6.2.5" in message and "7.0" in message
|
|
103
|
+
assert not marker.exists()
|
|
104
|
+
assert snapshots(home, KEY) == []
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def test_python_below_the_minimum_is_refused_before_any_test(tmp_path, home, cache):
|
|
108
|
+
repo = plain_repo(tmp_path, venv_dir=".venv", pytest_version="8.3.5", python="3.9")
|
|
109
|
+
marker = guarded(repo, tmp_path)
|
|
110
|
+
result = weigh(repo, home, cache=cache)
|
|
111
|
+
assert result.returncode != 0
|
|
112
|
+
message = result.stdout + result.stderr
|
|
113
|
+
assert "3.9" in message and "3.10" in message
|
|
114
|
+
assert not marker.exists()
|
|
115
|
+
assert snapshots(home, KEY) == []
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"""The sampled kill matrix of `--mutation`, read from the snapshot.
|
|
2
|
+
|
|
3
|
+
Snapshot interface the tests pin (the spec leaves the JSON keys open):
|
|
4
|
+
mutation.sampled list of the sampled mutant ids (mutmut names, e.g. demo.parser.x_parse__mutmut_3)
|
|
5
|
+
mutation.mutants {id: {"line": source line of the mutation}} for the sampled mutants
|
|
6
|
+
mutation.matrix {id: [ids of the tests that kill it]}, a row for every sampled mutant
|
|
7
|
+
tests[node] booleans "subsumed", "hollow" (killed none of >= 2 sampled mutants on its lines)
|
|
8
|
+
and "insufficient_evidence" (fewer than 2 sampled mutants on its lines)
|
|
9
|
+
metrics hollow_tests and subsumed_in_kill_matrix are percentages of all tests
|
|
10
|
+
"""
|
|
11
|
+
import re
|
|
12
|
+
|
|
13
|
+
import pytest
|
|
14
|
+
|
|
15
|
+
from fixture_repo import load, snapshots, weigh
|
|
16
|
+
from kill_repo import matrix_repo, sample_repo, shift_repo
|
|
17
|
+
|
|
18
|
+
KEY = "github.com/jesdi/demo"
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def function_of(mutant):
|
|
22
|
+
return re.search(r"\.x_(\w+?)__mutmut_\d+$", mutant)[1]
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def mutate(factory, name, tmp_path_factory, cache, *flags, nows=("2026-01-01T00:00:00Z",)):
|
|
26
|
+
home = tmp_path_factory.mktemp(name + "-home")
|
|
27
|
+
repo = factory(tmp_path_factory.mktemp(name) / "demo")
|
|
28
|
+
snaps = []
|
|
29
|
+
for now in nows:
|
|
30
|
+
result = weigh(repo, home, "--mutation", "--no-open", *flags, cache=cache, now=now)
|
|
31
|
+
assert result.returncode == 0, result.stdout + result.stderr
|
|
32
|
+
snaps.append(load(snapshots(home, KEY)[-1]))
|
|
33
|
+
return snaps
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
@pytest.fixture(scope="module")
|
|
37
|
+
def twice(tmp_path_factory, cache):
|
|
38
|
+
return mutate(sample_repo, "twice", tmp_path_factory, cache, nows=("2026-01-01T00:00:00Z", "2026-01-02T00:00:00Z"))
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
@pytest.fixture(scope="module")
|
|
42
|
+
def everything(tmp_path_factory, cache):
|
|
43
|
+
return mutate(sample_repo, "all", tmp_path_factory, cache, "--matrix-per-function", "all")[0]
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
@pytest.fixture(scope="module")
|
|
47
|
+
def ops(tmp_path_factory, cache):
|
|
48
|
+
return mutate(matrix_repo, "ops", tmp_path_factory, cache)[0]
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
@pytest.fixture(scope="module")
|
|
52
|
+
def shift(tmp_path_factory, cache):
|
|
53
|
+
return mutate(shift_repo, "shift", tmp_path_factory, cache)[0]
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def by_function(snap, name):
|
|
57
|
+
return [m for m in snap["mutation"]["sampled"] if function_of(m) == name]
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def test_two_runs_list_the_same_sampled_mutants_and_kill_matrix(twice):
|
|
61
|
+
first, second = (s["mutation"] for s in twice)
|
|
62
|
+
assert first["sampled"] and first["matrix"]
|
|
63
|
+
assert first["sampled"] == second["sampled"]
|
|
64
|
+
assert first["matrix"] == second["matrix"]
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def test_at_most_three_mutants_per_function_on_different_lines(twice):
|
|
68
|
+
snap = twice[0]
|
|
69
|
+
parse = by_function(snap, "parse")
|
|
70
|
+
assert len(parse) == 3
|
|
71
|
+
assert len({snap["mutation"]["mutants"][m]["line"] for m in parse}) == 3
|
|
72
|
+
assert len(by_function(snap, "noop")) == 1
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def test_all_takes_every_mutant_of_the_function(everything):
|
|
76
|
+
matrix = everything["mutation"]["matrix"]
|
|
77
|
+
parse = {m for m in matrix if function_of(m) == "parse"}
|
|
78
|
+
assert len(parse) == 12
|
|
79
|
+
assert len({everything["mutation"]["mutants"][m]["line"] for m in parse}) == 6
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def test_matrix_row_records_every_killing_test(twice):
|
|
83
|
+
snap = twice[0]
|
|
84
|
+
tests = snap["tests"]
|
|
85
|
+
ok, edge = (next(n for n in tests if n.endswith("::" + t)) for t in ("test_parse_ok", "test_parse_edge"))
|
|
86
|
+
rows = [snap["mutation"]["matrix"][m] for m in by_function(snap, "parse")]
|
|
87
|
+
assert rows
|
|
88
|
+
for row in rows:
|
|
89
|
+
assert {ok, edge} <= set(row)
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def test_test_killing_what_another_kills_is_subsumed(ops):
|
|
93
|
+
tests = ops["tests"]
|
|
94
|
+
a = next(t for n, t in tests.items() if n.endswith("::test_a"))
|
|
95
|
+
assert a["subsumed"] is True
|
|
96
|
+
assert a["insufficient_evidence"] is False
|
|
97
|
+
assert ops["metrics"]["subsumed_in_kill_matrix"]["value"] == pytest.approx(100 * sum(t["subsumed"] for t in tests.values()) / len(tests))
|
|
98
|
+
assert ops["metrics"]["subsumed_in_kill_matrix"]["value"] > 0
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def test_single_sampled_mutant_is_insufficient_evidence_and_counts_nowhere(shift):
|
|
102
|
+
tests = shift["tests"]
|
|
103
|
+
invalid = next(t for n, t in tests.items() if n.endswith("::test_parse_invalid"))
|
|
104
|
+
assert invalid["insufficient_evidence"] is True
|
|
105
|
+
assert invalid["subsumed"] is False
|
|
106
|
+
assert invalid["hollow"] is False
|
|
107
|
+
assert shift["metrics"]["subsumed_in_kill_matrix"]["value"] == 0
|
|
108
|
+
assert shift["metrics"]["hollow_tests"]["value"] == 0
|
|
109
|
+
assert shift["metrics"]["no_unique_coverage"]["value"] == 0
|
|
110
|
+
assert shift["metrics"]["duplicate_clusters"]["value"] == 0
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def test_test_that_kills_none_of_four_sampled_mutants_is_hollow(ops):
|
|
114
|
+
tests = ops["tests"]
|
|
115
|
+
roundtrip = next(t for n, t in tests.items() if n.endswith("::test_session_roundtrip"))
|
|
116
|
+
assert roundtrip["hollow"] is True
|
|
117
|
+
assert roundtrip["insufficient_evidence"] is False
|
|
118
|
+
assert ops["metrics"]["hollow_tests"]["value"] == pytest.approx(100 * sum(t["hollow"] for t in tests.values()) / len(tests))
|
|
119
|
+
assert ops["metrics"]["hollow_tests"]["value"] > 0
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def test_regression_and_economy_get_their_full_weights(twice):
|
|
123
|
+
snap = twice[0]
|
|
124
|
+
assert {"hollow_tests", "pseudo_tested_functions", "subsumed_in_kill_matrix"} <= snap["metrics"].keys()
|
|
125
|
+
assert snap["pillars"]["regression"]["partial"] is False
|
|
126
|
+
assert snap["pillars"]["economy"]["partial"] is False
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"""Ticket tw/s5-smells/10: Eager test, Conditional test logic, Mystery guest, Swallowed exception, Real sleep and
|
|
2
|
+
Duplicate body, the partial default tier and the chat summary, through weigh.py.
|
|
3
|
+
|
|
4
|
+
Interface the tests pin (the spec leaves the JSON keys open), on top of test_smells.py and test_coverage_run.py:
|
|
5
|
+
tests[node].smells adds the names "Eager test", "Conditional test logic", "Mystery guest", "Swallowed exception",
|
|
6
|
+
"Real sleep" and "Duplicate body"
|
|
7
|
+
clusters [[node, ...]]: one list of node ids per duplicate-body cluster
|
|
8
|
+
metrics.duplicate_clusters {value, score}: percent of all tests that sit in a duplicate-body cluster
|
|
9
|
+
Stdout: one line per pillar holding its name, its displayed score and the word "partial" when the pillar is partial;
|
|
10
|
+
the inventory line ("<n> tests"); "<n> flaky test(s)"; the node ids of the 3 worst tests of the lowest pillar; the paths
|
|
11
|
+
of the snapshot and the dashboard.
|
|
12
|
+
"""
|
|
13
|
+
import re
|
|
14
|
+
|
|
15
|
+
import pytest
|
|
16
|
+
|
|
17
|
+
from fixture_repo import load, snapshots, weigh
|
|
18
|
+
from maint_repo import cluster_suite, smell_suite, summary_suite
|
|
19
|
+
|
|
20
|
+
KEY = "github.com/jesdi/demo"
|
|
21
|
+
NODE = re.compile(r"tests/[\w/]+\.py::\w+")
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def build(tmp_path_factory, cache, name, make):
|
|
25
|
+
root = tmp_path_factory.mktemp(name)
|
|
26
|
+
(root / "home").mkdir()
|
|
27
|
+
result = weigh(make(root / "work" / "demo"), root / "home", cache=cache)
|
|
28
|
+
assert result.returncode == 0, result.stdout + result.stderr
|
|
29
|
+
path = snapshots(root / "home", KEY)[-1]
|
|
30
|
+
return load(path), result, path, root / "home" / ".test-weigh-in" / KEY / "dashboard.html"
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
@pytest.fixture(scope="module")
|
|
34
|
+
def smells(tmp_path_factory, cache):
|
|
35
|
+
return build(tmp_path_factory, cache, "maint", smell_suite)[0]
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
@pytest.fixture(scope="module")
|
|
39
|
+
def cluster(tmp_path_factory, cache):
|
|
40
|
+
return build(tmp_path_factory, cache, "cluster", cluster_suite)[0]
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
@pytest.fixture(scope="module")
|
|
44
|
+
def summary(tmp_path_factory, cache):
|
|
45
|
+
return build(tmp_path_factory, cache, "summary", summary_suite)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def smelly(snap, smell):
|
|
49
|
+
return {n for n, t in snap["tests"].items() if smell in t.get("smells", [])}
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def test_three_act_then_assert_cycles_are_an_eager_test_and_two_are_not(smells):
|
|
53
|
+
assert "smells" in smells["tests"]["tests/test_maint.py::test_flow_2"]
|
|
54
|
+
assert smelly(smells, "Eager test") == {"tests/test_maint.py::test_flow_3"}
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def test_a_loop_over_literals_is_conditional_test_logic(smells):
|
|
58
|
+
assert smelly(smells, "Conditional test logic") == {"tests/test_maint.py::test_parse_all"}
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def test_a_home_path_is_a_mystery_guest_but_tmp_path_is_not(smells):
|
|
62
|
+
assert "smells" in smells["tests"]["tests/test_guest.py::test_a"]
|
|
63
|
+
assert smelly(smells, "Mystery guest") == {"tests/test_guest.py::test_b"}
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def test_a_try_except_that_does_nothing_is_a_swallowed_exception(smells):
|
|
67
|
+
assert smelly(smells, "Swallowed exception") == {"tests/test_maint.py::test_load"}
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def test_a_non_zero_sleep_is_a_real_sleep_and_a_zero_sleep_is_not(smells):
|
|
71
|
+
assert "smells" in smells["tests"]["tests/test_sleep.py::test_a"]
|
|
72
|
+
assert smelly(smells, "Real sleep") == {"tests/test_sleep.py::test_b"}
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def test_tests_differing_in_a_literal_and_a_name_form_one_duplicate_cluster(cluster):
|
|
76
|
+
intents = [f"tests/test_intent.py::test_intent_{i}" for i in range(1, 5)]
|
|
77
|
+
assert cluster["inventory"]["tests"] == 40
|
|
78
|
+
assert [sorted(c) for c in cluster["clusters"]] == [intents]
|
|
79
|
+
assert smelly(cluster, "Duplicate body") == set(intents)
|
|
80
|
+
assert cluster["metrics"]["duplicate_clusters"]["value"] == pytest.approx(10)
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def test_a_run_without_mutation_weights_regression_and_economy_by_their_partial_weights(cluster):
|
|
84
|
+
m, p = cluster["metrics"], cluster["pillars"]
|
|
85
|
+
assert p["regression"]["partial"] and p["economy"]["partial"]
|
|
86
|
+
assert p["regression"]["score"] == pytest.approx(.6 * m["branch_coverage"]["score"] + .4 * m["hollow_tests"]["score"])
|
|
87
|
+
assert p["economy"]["score"] == pytest.approx(.6 * m["no_unique_coverage"]["score"] + .4 * m["duplicate_clusters"]["score"])
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def test_the_chat_summary_reports_scores_inventory_flaky_worst_tests_and_paths_without_advice(summary):
|
|
91
|
+
snap, result, snapshot, dashboard = summary
|
|
92
|
+
out = result.stdout
|
|
93
|
+
scores = {k: p["score"] for k, p in snap["pillars"].items()}
|
|
94
|
+
assert min(scores, key=lambda k: float("inf") if scores[k] is None else scores[k]) == "economy"
|
|
95
|
+
assert scores["maintainability"] is not None
|
|
96
|
+
names = {"regression": "Protection against regressions", "refactoring": "Resistance to refactoring",
|
|
97
|
+
"feedback": "Fast feedback", "maintainability": "Maintainability", "economy": "Economy"}
|
|
98
|
+
for key, name in names.items():
|
|
99
|
+
(line,) = [l for l in out.splitlines() if l.startswith(name)]
|
|
100
|
+
assert re.search(r"\b\d{1,2}\b", line)
|
|
101
|
+
if key in ("regression", "economy"):
|
|
102
|
+
assert "partial" in line.lower()
|
|
103
|
+
elif key in ("feedback", "maintainability"):
|
|
104
|
+
assert "partial" not in line.lower()
|
|
105
|
+
assert "40 tests" in out
|
|
106
|
+
assert "1 flaky test" in out
|
|
107
|
+
worst = set(NODE.findall(out)) - {"tests/test_retry.py::test_retry"}
|
|
108
|
+
assert len(worst) == 3
|
|
109
|
+
for node in worst:
|
|
110
|
+
t = snap["tests"][node]
|
|
111
|
+
assert "Duplicate body" in t["smells"] or t["unique_coverage"] == 0
|
|
112
|
+
assert str(snapshot) in out and str(dashboard) in out
|
|
113
|
+
assert not re.search(r"\b(consider|should|recommend|suggest|try|fix|improve|you)\b", out, re.I)
|