@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,154 @@
|
|
|
1
|
+
"""Ticket tw/s3-skeleton/06: rules.toml scoring, the Fast feedback pillar, stdout and --no-open.
|
|
2
|
+
|
|
3
|
+
The anchor tests pin the logistic curve on total runtime and on branch coverage (branch arcs only,
|
|
4
|
+
not statements plus branches).
|
|
5
|
+
Interface: see rules_fixture.py. TEST_WEIGH_IN_RULES=<path> replaces the skill's rules.toml.
|
|
6
|
+
"""
|
|
7
|
+
import os
|
|
8
|
+
import stat
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
|
|
11
|
+
import pytest
|
|
12
|
+
|
|
13
|
+
from fixture_repo import FAKECLOCK, build_repo, load, snapshots, weigh as _weigh
|
|
14
|
+
from rules_fixture import sha256, write_rules
|
|
15
|
+
|
|
16
|
+
KEY = "github.com/jesdi/demo"
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def weigh(repo, home, *flags, cache, rules=None, now=None):
|
|
20
|
+
if rules:
|
|
21
|
+
os.environ["TEST_WEIGH_IN_RULES"] = str(rules)
|
|
22
|
+
try:
|
|
23
|
+
return _weigh(repo, home, *flags, cache=cache, now=now)
|
|
24
|
+
finally:
|
|
25
|
+
os.environ.pop("TEST_WEIGH_IN_RULES", None)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def set_test_duration(repo, seconds):
|
|
29
|
+
"""The 40 tests of the default repo take `seconds` each: total runtime is 40 * seconds."""
|
|
30
|
+
site = next((repo / ".venv" / "lib").glob("python*/site-packages"))
|
|
31
|
+
(site / "fakeclock.py").write_text(FAKECLOCK.replace("1.125", repr(seconds)))
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def last_snapshot(home):
|
|
35
|
+
return load(snapshots(home, KEY)[-1])
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def test_anchors_score_90_and_10(tmp_path, home, cache):
|
|
39
|
+
repo = build_repo(tmp_path / "demo") # 40 tests x 1.125 s = 45 s
|
|
40
|
+
at_target = write_rules(tmp_path / "target.toml", total_runtime=dict(target=45, bad=450))
|
|
41
|
+
at_bad = write_rules(tmp_path / "bad.toml", total_runtime=dict(target=450, bad=45))
|
|
42
|
+
r1 = weigh(repo, home, cache=cache, rules=at_target, now="2026-01-01T00:00:00Z")
|
|
43
|
+
assert r1.returncode == 0, r1.stdout + r1.stderr
|
|
44
|
+
r2 = weigh(repo, home, cache=cache, rules=at_bad, now="2026-01-01T00:00:01Z")
|
|
45
|
+
assert r2.returncode == 0, r2.stdout + r2.stderr
|
|
46
|
+
first, second = (load(p)["metrics"]["total_runtime"] for p in snapshots(home, KEY))
|
|
47
|
+
assert first["value"] == pytest.approx(45)
|
|
48
|
+
assert first["score"] == pytest.approx(90, abs=0.01)
|
|
49
|
+
assert second["score"] == pytest.approx(10, abs=0.01)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def add_half_covered_branch(repo):
|
|
53
|
+
"""A module with one `if` (2 branch arcs, 4 statements) and a test taking only the true arm: 50% branch coverage."""
|
|
54
|
+
(repo / "demo" / "pick.py").write_text("def pick(x):\n if x:\n return 1\n return 2\n")
|
|
55
|
+
(repo / "tests" / "test_pick.py").write_text("from demo import pick\n\n\ndef test_pick_true():\n assert pick.pick(True) == 1\n")
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def test_branch_coverage_counts_branch_arcs_only_and_hits_the_anchors(tmp_path, home, cache):
|
|
59
|
+
repo = build_repo(tmp_path / "demo")
|
|
60
|
+
add_half_covered_branch(repo)
|
|
61
|
+
at_target = write_rules(tmp_path / "target.toml", branch_coverage=dict(target=50, bad=10))
|
|
62
|
+
at_bad = write_rules(tmp_path / "bad.toml", branch_coverage=dict(target=90, bad=50))
|
|
63
|
+
for rules, now in ((at_target, "2026-01-01T00:00:00Z"), (at_bad, "2026-01-01T00:00:01Z")):
|
|
64
|
+
result = weigh(repo, home, cache=cache, rules=rules, now=now)
|
|
65
|
+
assert result.returncode == 0, result.stdout + result.stderr
|
|
66
|
+
first, second = (load(p)["metrics"]["branch_coverage"] for p in snapshots(home, KEY))
|
|
67
|
+
assert first["value"] == pytest.approx(50)
|
|
68
|
+
assert first["score"] == pytest.approx(90, abs=0.01)
|
|
69
|
+
assert second["score"] == pytest.approx(10, abs=0.01)
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def test_faster_runtime_scores_higher_even_beyond_the_bad_anchor(tmp_path, home, cache):
|
|
73
|
+
repo = build_repo(tmp_path / "demo")
|
|
74
|
+
set_test_duration(repo, 30) # 1,200 s, past the 600 s bad anchor
|
|
75
|
+
r1 = weigh(repo, home, cache=cache, now="2026-01-01T00:00:00Z")
|
|
76
|
+
assert r1.returncode == 0, r1.stdout + r1.stderr
|
|
77
|
+
set_test_duration(repo, 22.5) # 900 s
|
|
78
|
+
r2 = weigh(repo, home, cache=cache, now="2026-01-01T00:00:01Z")
|
|
79
|
+
assert r2.returncode == 0, r2.stdout + r2.stderr
|
|
80
|
+
first, second = (load(p) for p in snapshots(home, KEY))
|
|
81
|
+
assert first["inventory"]["runtime_seconds"] == pytest.approx(1200)
|
|
82
|
+
assert second["inventory"]["runtime_seconds"] == pytest.approx(900)
|
|
83
|
+
assert second["pillars"]["feedback"]["score"] > first["pillars"]["feedback"]["score"]
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def test_fast_feedback_weights_not_summing_to_one_stop_the_run(tmp_path, home, cache):
|
|
87
|
+
repo = build_repo(tmp_path / "demo")
|
|
88
|
+
rules = write_rules(tmp_path / "rules.toml", tests_over_10s=dict(weight=.10)) # .40 .30 .15 .10
|
|
89
|
+
result = weigh(repo, home, cache=cache, rules=rules)
|
|
90
|
+
assert result.returncode == 2
|
|
91
|
+
assert "Fast feedback" in result.stdout + result.stderr
|
|
92
|
+
assert snapshots(home, KEY) == []
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def test_equal_anchors_stop_the_run_naming_the_metric(tmp_path, home, cache):
|
|
96
|
+
repo = build_repo(tmp_path / "demo")
|
|
97
|
+
rules = write_rules(tmp_path / "rules.toml", branch_coverage=dict(target=80, bad=80))
|
|
98
|
+
result = weigh(repo, home, cache=cache, rules=rules)
|
|
99
|
+
assert result.returncode == 2
|
|
100
|
+
assert "branch coverage" in (result.stdout + result.stderr).lower()
|
|
101
|
+
assert snapshots(home, KEY) == []
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def test_edited_rules_keep_the_version_and_change_the_hash(tmp_path, home, cache):
|
|
105
|
+
repo = build_repo(tmp_path / "demo")
|
|
106
|
+
before = write_rules(tmp_path / "before.toml", branch_coverage=dict(bad=50))
|
|
107
|
+
after = write_rules(tmp_path / "after.toml", branch_coverage=dict(bad=60))
|
|
108
|
+
for rules, now in ((before, "2026-01-01T00:00:00Z"), (after, "2026-01-01T00:00:01Z")):
|
|
109
|
+
result = weigh(repo, home, cache=cache, rules=rules, now=now)
|
|
110
|
+
assert result.returncode == 0, result.stdout + result.stderr
|
|
111
|
+
first, second = (load(p)["rules"] for p in snapshots(home, KEY))
|
|
112
|
+
assert (first["version"], second["version"]) == (1, 1)
|
|
113
|
+
assert first["sha256"] == sha256(before)
|
|
114
|
+
assert second["sha256"] == sha256(after)
|
|
115
|
+
assert first["sha256"] != second["sha256"]
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def test_shipped_rules_are_version_1_and_hashed(run, home):
|
|
119
|
+
_, result = run()
|
|
120
|
+
assert result.returncode == 0, result.stdout + result.stderr
|
|
121
|
+
rules = last_snapshot(home)["rules"]
|
|
122
|
+
shipped = Path(__file__).resolve().parent.parent / "rules.toml"
|
|
123
|
+
assert rules["version"] == 1
|
|
124
|
+
assert rules["sha256"] == sha256(shipped)
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
@pytest.fixture
|
|
128
|
+
def browser_log(tmp_path, monkeypatch):
|
|
129
|
+
"""Fake browser launchers first on PATH: each one appends its name to the log when run."""
|
|
130
|
+
bin_dir, log = tmp_path / "fakebin", tmp_path / "opened.log"
|
|
131
|
+
bin_dir.mkdir()
|
|
132
|
+
for name in ("open", "xdg-open", "osascript", "sensible-browser", "x-www-browser", "gio", "wslview"):
|
|
133
|
+
script = bin_dir / name
|
|
134
|
+
script.write_text(f'#!/bin/sh\necho {name} "$@" >> "{log}"\n')
|
|
135
|
+
script.chmod(script.stat().st_mode | stat.S_IEXEC)
|
|
136
|
+
monkeypatch.setenv("PATH", f"{bin_dir}{os.pathsep}{os.environ['PATH']}")
|
|
137
|
+
monkeypatch.setenv("BROWSER", str(bin_dir / "open"))
|
|
138
|
+
return log
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
def test_no_open_opens_no_browser_and_prints_the_dashboard_path(run, home, browser_log):
|
|
142
|
+
_, result = run("--no-open")
|
|
143
|
+
assert result.returncode == 0, result.stdout + result.stderr
|
|
144
|
+
dashboard = home / ".test-weigh-in" / KEY / "dashboard.html"
|
|
145
|
+
assert dashboard.is_file()
|
|
146
|
+
assert str(dashboard) in result.stdout
|
|
147
|
+
assert not browser_log.exists()
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
def test_without_no_open_the_dashboard_is_opened(run, home, browser_log):
|
|
151
|
+
_, result = run()
|
|
152
|
+
assert result.returncode == 0, result.stdout + result.stderr
|
|
153
|
+
assert str(home / ".test-weigh-in" / KEY / "dashboard.html") in result.stdout
|
|
154
|
+
assert browser_log.exists()
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"""The boundaries of the smell rules (spec requirement 18), through weigh.py; the suite is described in rule_repo.py."""
|
|
2
|
+
import json
|
|
3
|
+
import re
|
|
4
|
+
|
|
5
|
+
import pytest
|
|
6
|
+
|
|
7
|
+
from fixture_repo import load, weigh
|
|
8
|
+
from rule_repo import rules_suite
|
|
9
|
+
|
|
10
|
+
KEY = "github.com/jesdi/demo"
|
|
11
|
+
T = "tests/test_rules.py::"
|
|
12
|
+
M = "tests/test_maint_rules.py::"
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
@pytest.fixture(scope="module")
|
|
16
|
+
def home(tmp_path_factory, cache):
|
|
17
|
+
root = tmp_path_factory.mktemp("rules")
|
|
18
|
+
(root / "home").mkdir()
|
|
19
|
+
result = weigh(rules_suite(root / "work" / "demo"), root / "home", "--no-open", cache=cache)
|
|
20
|
+
assert result.returncode == 0, result.stdout + result.stderr
|
|
21
|
+
return root / "home" / ".test-weigh-in" / KEY
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
@pytest.fixture(scope="module")
|
|
25
|
+
def snap(home):
|
|
26
|
+
return load(sorted(home.glob("*.json"))[-1])
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
@pytest.fixture(scope="module")
|
|
30
|
+
def page(home):
|
|
31
|
+
"""The data the dashboard renders, as weigh.py wrote it into the page."""
|
|
32
|
+
return json.loads(re.search(r"const data = (.*);\n", (home / "dashboard.html").read_text()).group(1))
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def worst(page, key):
|
|
36
|
+
return {w["test"]: w["reason"] for w in next(p for p in page["pillars"] if p["key"] == key)["worst"]}
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def smelly(snap, smell):
|
|
40
|
+
return {n.removeprefix(T) for n, t in snap["tests"].items() if smell in t["smells"]}
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def test_check_and_expect_helpers_are_assertions(snap):
|
|
44
|
+
assert snap["tests"][T + "test_check"]["outcome"] == "passed"
|
|
45
|
+
assert smelly(snap, "No assertion") == {"TestA::test_board", "TestOther::test_inherited", "TestDiamond::test_diamond"}
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def test_call_count_and_call_args_assertions_are_interaction_only_and_one_beside_a_result_check_is_not(snap):
|
|
49
|
+
assert smelly(snap, "Interaction-only") == {"test_call_count", "test_call_args"}
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def test_four_monkeypatch_setattr_calls_are_mock_heavy_and_three_are_not(snap):
|
|
53
|
+
assert smelly(snap, "Mock-heavy") == {"test_setattr_4"}
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def test_a_private_name_read_through_a_conftest_module_is_not_private_access(snap):
|
|
57
|
+
assert smelly(snap, "Private access") == {"test_module_private", "test_local_private"}
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def test_same_named_methods_of_two_classes_are_checked_apart(snap):
|
|
61
|
+
a, b = snap["tests"][T + "TestA::test_board"], snap["tests"][T + "TestB::test_board"]
|
|
62
|
+
assert "No assertion" in a["smells"] and "No assertion" not in b["smells"]
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def test_an_inherited_test_is_its_base_class_method_not_a_same_named_one(snap):
|
|
66
|
+
child = snap["tests"][T + "TestChild::test_inherited"]
|
|
67
|
+
assert child["outcome"] == "passed"
|
|
68
|
+
assert "No assertion" not in child["smells"] and child["lines"] == 2
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def maint(snap, smell):
|
|
72
|
+
return {n.removeprefix(M) for n, t in snap["tests"].items() if n.startswith(M) and smell in t["smells"]}
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def test_a_literal_path_held_in_a_variable_is_a_mystery_guest(snap):
|
|
76
|
+
assert maint(snap, "Mystery guest") == {"test_guest_name", "test_guest_path"}
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def test_a_check_helper_closes_an_act_then_assert_cycle(snap):
|
|
80
|
+
assert maint(snap, "Eager test") == {"test_eager_helpers"}
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def test_a_handler_that_calls_a_check_helper_does_not_swallow(snap):
|
|
84
|
+
assert snap["tests"][M + "test_swallow_checked"]["outcome"] == "passed"
|
|
85
|
+
assert not maint(snap, "Swallowed exception")
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def test_a_long_test_without_smells_ranks_among_the_worst_maintainability_tests(snap, page):
|
|
89
|
+
assert snap["tests"][M + "test_long"]["smells"] == []
|
|
90
|
+
assert worst(page, "maintainability")[M + "test_long"] == "54 lines"
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def test_slow_tests_without_a_real_sleep_rank_among_the_worst_feedback_tests(page):
|
|
94
|
+
reasons = worst(page, "feedback")
|
|
95
|
+
assert len(reasons) == 10
|
|
96
|
+
assert all(re.fullmatch(r"\d+\.\d\d s", r) for r in reasons.values())
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"""Ticket tw/s5-smells/09: No assertion, Interaction-only, Mock-heavy and Private access, through weigh.py.
|
|
2
|
+
|
|
3
|
+
Interface the tests pin (the spec leaves the JSON keys open): each entry of the snapshot's `tests` has `smells`, a list
|
|
4
|
+
of the smell names "No assertion", "Interaction-only", "Mock-heavy", "Private access"; the metrics hollow_tests,
|
|
5
|
+
mock_heavy, interaction_only and private_access hold the percentage of all tests (0-100) that have the smell.
|
|
6
|
+
"""
|
|
7
|
+
import pytest
|
|
8
|
+
|
|
9
|
+
from fixture_repo import load, snapshots, weigh
|
|
10
|
+
from smell_repo import smelly_suite
|
|
11
|
+
|
|
12
|
+
KEY = "github.com/jesdi/demo"
|
|
13
|
+
T = "tests/test_smells.py::"
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@pytest.fixture(scope="module")
|
|
17
|
+
def snap(tmp_path_factory, cache):
|
|
18
|
+
root = tmp_path_factory.mktemp("smells")
|
|
19
|
+
(root / "home").mkdir()
|
|
20
|
+
repo = smelly_suite(root / "work" / "demo")
|
|
21
|
+
result = weigh(repo, root / "home", cache=cache)
|
|
22
|
+
assert result.returncode == 0, result.stdout + result.stderr
|
|
23
|
+
return load(snapshots(root / "home", KEY)[-1])
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def smelly(snap, smell):
|
|
27
|
+
return {n for n, t in snap["tests"].items() if smell in t.get("smells", [])}
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def names(*tests):
|
|
31
|
+
return {T + t for t in tests}
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def test_a_test_without_assertion_has_the_smell_and_is_hollow(snap):
|
|
35
|
+
assert T + "test_board_renders" in smelly(snap, "No assertion")
|
|
36
|
+
assert snap["metrics"]["hollow_tests"]["value"] == pytest.approx(100 * 4 / len(snap["tests"]))
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def test_failing_erroring_and_skipped_tests_are_checked_and_counted(snap):
|
|
40
|
+
assert {T + "test_fail_hollow", T + "test_error_hollow", T + "test_skipped_hollow"} <= smelly(snap, "No assertion")
|
|
41
|
+
assert smelly(snap, "No assertion") == names("test_board_renders", "test_fail_hollow", "test_error_hollow", "test_skipped_hollow")
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def test_a_custom_assertion_helper_from_conftest_is_an_assertion(snap):
|
|
45
|
+
assert "smells" in snap["tests"][T + "test_board"]
|
|
46
|
+
assert T + "test_board" not in smelly(snap, "No assertion")
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def test_pytest_raises_is_an_assertion(snap):
|
|
50
|
+
assert "smells" in snap["tests"][T + "test_invalid"]
|
|
51
|
+
assert T + "test_invalid" not in smelly(snap, "No assertion")
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def test_pytest_warns_and_an_assertion_in_a_nested_helper_are_assertions(snap):
|
|
55
|
+
assert "smells" in snap["tests"][T + "test_warns"]
|
|
56
|
+
assert not {T + "test_warns", T + "test_nested_helper"} & smelly(snap, "No assertion")
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def test_more_than_three_mock_constructs_is_mock_heavy(snap):
|
|
60
|
+
assert smelly(snap, "Mock-heavy") == names("test_b_heavy")
|
|
61
|
+
assert snap["metrics"]["mock_heavy"]["value"] == pytest.approx(100 / len(snap["tests"]))
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def test_asserting_only_on_a_mock_is_interaction_only(snap):
|
|
65
|
+
assert smelly(snap, "Interaction-only") == names("test_notify")
|
|
66
|
+
assert snap["metrics"]["interaction_only"]["value"] == pytest.approx(100 / len(snap["tests"]))
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def test_importing_a_private_name_is_private_access_but_dunder_and_conftest_names_are_not(snap):
|
|
70
|
+
assert smelly(snap, "Private access") == names("test_b_private")
|
|
71
|
+
assert snap["metrics"]["private_access"]["value"] == pytest.approx(100 / len(snap["tests"]))
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
|
|
3
|
+
from fixture_repo import build_repo, git, load, short_sha, site_files, snapshots, weigh
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def ok(result):
|
|
7
|
+
assert result.returncode == 0, result.stdout + result.stderr
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def one_snapshot(home, key):
|
|
11
|
+
(snap,) = snapshots(home, key)
|
|
12
|
+
return load(snap)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def test_uv_repo_measured_without_touching_it(tmp_path, home, cache):
|
|
16
|
+
repo = build_repo(tmp_path / "demo")
|
|
17
|
+
before = site_files(repo)
|
|
18
|
+
result = weigh(repo, home, cache=cache)
|
|
19
|
+
ok(result)
|
|
20
|
+
assert len(snapshots(home, "github.com/jesdi/demo")) == 1
|
|
21
|
+
assert git(repo, "status", "--porcelain") == ""
|
|
22
|
+
assert site_files(repo) == before
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def test_inventory_counts_lines_and_runtime(run, home):
|
|
26
|
+
_, result = run(test_lines=6000, source_lines=4000)
|
|
27
|
+
ok(result)
|
|
28
|
+
inv = one_snapshot(home, "github.com/jesdi/demo")["inventory"]
|
|
29
|
+
assert (inv["tests"], inv["test_files"], inv["test_lines"], inv["source_lines"]) == (40, 8, 6000, 4000)
|
|
30
|
+
assert inv["runtime_seconds"] == pytest.approx(45)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def test_pytest_args_select_tests_and_are_recorded(run, home):
|
|
34
|
+
_, result = run("--pytest-args", "-m 'not e2e'")
|
|
35
|
+
ok(result)
|
|
36
|
+
snap = one_snapshot(home, "github.com/jesdi/demo")
|
|
37
|
+
assert snap["inventory"]["tests"] == 30
|
|
38
|
+
assert snap["pytest_args"] == "-m 'not e2e'"
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def test_repo_pytest_version_is_used_not_the_overlays(run, home):
|
|
42
|
+
_, result = run(pytest_version="7.4.4")
|
|
43
|
+
ok(result)
|
|
44
|
+
assert one_snapshot(home, "github.com/jesdi/demo")["pytest_version"].startswith("7.4")
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
@pytest.mark.parametrize(
|
|
48
|
+
"origin, name, key",
|
|
49
|
+
[
|
|
50
|
+
("git@github.com:jesdi/api.git", "api", "github.com/jesdi/api"),
|
|
51
|
+
("https://github.com/acme/api.git", "api", "github.com/acme/api"),
|
|
52
|
+
("git@github.com:a-b/c.git", "x", "github.com/a-b/c"),
|
|
53
|
+
("git@github.com:a/b-c.git", "y", "github.com/a/b-c"),
|
|
54
|
+
("git@gitlab.com:jesdi/api.git", "y", "gitlab.com/jesdi/api"),
|
|
55
|
+
(None, "scratch", "local/scratch"),
|
|
56
|
+
],
|
|
57
|
+
)
|
|
58
|
+
def test_repo_key_comes_from_origin(run, home, origin, name, key):
|
|
59
|
+
_, result = run(origin=origin, name=name)
|
|
60
|
+
ok(result)
|
|
61
|
+
assert len(snapshots(home, key)) == 1
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def test_second_run_adds_a_snapshot_and_keeps_the_first(run, home, cache):
|
|
65
|
+
repo, result = run()
|
|
66
|
+
ok(result)
|
|
67
|
+
(first,) = snapshots(home, "github.com/jesdi/demo")
|
|
68
|
+
content = first.read_bytes()
|
|
69
|
+
ok(weigh(repo, home, cache=cache))
|
|
70
|
+
assert len(snapshots(home, "github.com/jesdi/demo")) == 2
|
|
71
|
+
assert first.read_bytes() == content
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def test_dirty_tree_is_recorded(tmp_path, home, cache):
|
|
75
|
+
repo = build_repo(tmp_path / "demo")
|
|
76
|
+
(repo / "demo" / "board.py").write_text("def render(n):\n return str(n) + ''\n")
|
|
77
|
+
ok(weigh(repo, home, cache=cache))
|
|
78
|
+
snap = one_snapshot(home, "github.com/jesdi/demo")
|
|
79
|
+
assert git(repo, "rev-parse", "HEAD").startswith(snap["commit"])
|
|
80
|
+
assert snap["commit"] == short_sha(repo)
|
|
81
|
+
assert snap["dirty"] is True
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def test_same_second_runs_get_suffixed_names(run, home, cache):
|
|
85
|
+
now = "2026-01-02T03:04:05Z"
|
|
86
|
+
repo, result = run(now=now)
|
|
87
|
+
ok(result)
|
|
88
|
+
ok(weigh(repo, home, cache=cache, now=now))
|
|
89
|
+
names = sorted(p.name for p in snapshots(home, "github.com/jesdi/demo"))
|
|
90
|
+
stem = f"20260102T030405Z_{short_sha(repo)}"
|
|
91
|
+
assert names == sorted([stem + ".json", stem + "-2.json"])
|
|
File without changes
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
from demo import board, config
|
|
3
|
+
@pytest.mark.e2e
|
|
4
|
+
def test_board_0():
|
|
5
|
+
assert board.render(0) == "0"
|
|
6
|
+
assert config.load() == {}
|
|
7
|
+
@pytest.mark.e2e
|
|
8
|
+
def test_board_1():
|
|
9
|
+
assert board.render(1) == "1"
|
|
10
|
+
assert config.load() == {}
|
|
11
|
+
def test_board_2():
|
|
12
|
+
assert board.render(2) == "2"
|
|
13
|
+
assert config.load() == {}
|
|
14
|
+
def test_board_3():
|
|
15
|
+
assert board.render(3) == "3"
|
|
16
|
+
assert config.load() == {}
|
|
17
|
+
def test_board_4():
|
|
18
|
+
assert board.render(4) == "4"
|
|
19
|
+
assert config.load() == {}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
from demo import board, config
|
|
3
|
+
@pytest.mark.e2e
|
|
4
|
+
def test_config_0():
|
|
5
|
+
assert board.render(0) == "0"
|
|
6
|
+
assert config.load() == {}
|
|
7
|
+
@pytest.mark.e2e
|
|
8
|
+
def test_config_1():
|
|
9
|
+
assert board.render(1) == "1"
|
|
10
|
+
assert config.load() == {}
|
|
11
|
+
def test_config_2():
|
|
12
|
+
assert board.render(2) == "2"
|
|
13
|
+
assert config.load() == {}
|
|
14
|
+
def test_config_3():
|
|
15
|
+
assert board.render(3) == "3"
|
|
16
|
+
assert config.load() == {}
|
|
17
|
+
def test_config_4():
|
|
18
|
+
assert board.render(4) == "4"
|
|
19
|
+
assert config.load() == {}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
from demo import board, config
|
|
3
|
+
@pytest.mark.e2e
|
|
4
|
+
def test_parser_0():
|
|
5
|
+
assert board.render(0) == "0"
|
|
6
|
+
assert config.load() == {}
|
|
7
|
+
@pytest.mark.e2e
|
|
8
|
+
def test_parser_1():
|
|
9
|
+
assert board.render(1) == "1"
|
|
10
|
+
assert config.load() == {}
|
|
11
|
+
def test_parser_2():
|
|
12
|
+
assert board.render(2) == "2"
|
|
13
|
+
assert config.load() == {}
|
|
14
|
+
def test_parser_3():
|
|
15
|
+
assert board.render(3) == "3"
|
|
16
|
+
assert config.load() == {}
|
|
17
|
+
def test_parser_4():
|
|
18
|
+
assert board.render(4) == "4"
|
|
19
|
+
assert config.load() == {}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
from demo import board, config
|
|
3
|
+
@pytest.mark.e2e
|
|
4
|
+
def test_render_0():
|
|
5
|
+
assert board.render(0) == "0"
|
|
6
|
+
assert config.load() == {}
|
|
7
|
+
@pytest.mark.e2e
|
|
8
|
+
def test_render_1():
|
|
9
|
+
assert board.render(1) == "1"
|
|
10
|
+
assert config.load() == {}
|
|
11
|
+
def test_render_2():
|
|
12
|
+
assert board.render(2) == "2"
|
|
13
|
+
assert config.load() == {}
|
|
14
|
+
def test_render_3():
|
|
15
|
+
assert board.render(3) == "3"
|
|
16
|
+
assert config.load() == {}
|
|
17
|
+
def test_render_4():
|
|
18
|
+
assert board.render(4) == "4"
|
|
19
|
+
assert config.load() == {}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
from demo import board, config
|
|
3
|
+
def test_report_0():
|
|
4
|
+
assert board.render(0) == "0"
|
|
5
|
+
assert config.load() == {}
|
|
6
|
+
def test_report_1():
|
|
7
|
+
assert board.render(1) == "1"
|
|
8
|
+
assert config.load() == {}
|
|
9
|
+
def test_report_2():
|
|
10
|
+
assert board.render(2) == "2"
|
|
11
|
+
assert config.load() == {}
|
|
12
|
+
def test_report_3():
|
|
13
|
+
assert board.render(3) == "3"
|
|
14
|
+
assert config.load() == {}
|
|
15
|
+
def test_report_4():
|
|
16
|
+
assert board.render(4) == "4"
|
|
17
|
+
assert config.load() == {}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
from demo import board, config
|
|
3
|
+
@pytest.mark.e2e
|
|
4
|
+
def test_session_0():
|
|
5
|
+
assert board.render(0) == "0"
|
|
6
|
+
assert config.load() == {}
|
|
7
|
+
@pytest.mark.e2e
|
|
8
|
+
def test_session_1():
|
|
9
|
+
assert board.render(1) == "1"
|
|
10
|
+
assert config.load() == {}
|
|
11
|
+
def test_session_2():
|
|
12
|
+
assert board.render(2) == "2"
|
|
13
|
+
assert config.load() == {}
|
|
14
|
+
def test_session_3():
|
|
15
|
+
assert board.render(3) == "3"
|
|
16
|
+
assert config.load() == {}
|
|
17
|
+
def test_session_4():
|
|
18
|
+
assert board.render(4) == "4"
|
|
19
|
+
assert config.load() == {}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
from demo import board, config
|
|
3
|
+
def test_store_0():
|
|
4
|
+
assert board.render(0) == "0"
|
|
5
|
+
assert config.load() == {}
|
|
6
|
+
def test_store_1():
|
|
7
|
+
assert board.render(1) == "1"
|
|
8
|
+
assert config.load() == {}
|
|
9
|
+
def test_store_2():
|
|
10
|
+
assert board.render(2) == "2"
|
|
11
|
+
assert config.load() == {}
|
|
12
|
+
def test_store_3():
|
|
13
|
+
assert board.render(3) == "3"
|
|
14
|
+
assert config.load() == {}
|
|
15
|
+
def test_store_4():
|
|
16
|
+
assert board.render(4) == "4"
|
|
17
|
+
assert config.load() == {}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
from demo import board, config
|
|
3
|
+
def test_sync_0():
|
|
4
|
+
assert board.render(0) == "0"
|
|
5
|
+
assert config.load() == {}
|
|
6
|
+
def test_sync_1():
|
|
7
|
+
assert board.render(1) == "1"
|
|
8
|
+
assert config.load() == {}
|
|
9
|
+
def test_sync_2():
|
|
10
|
+
assert board.render(2) == "2"
|
|
11
|
+
assert config.load() == {}
|
|
12
|
+
def test_sync_3():
|
|
13
|
+
assert board.render(3) == "3"
|
|
14
|
+
assert config.load() == {}
|
|
15
|
+
def test_sync_4():
|
|
16
|
+
assert board.render(4) == "4"
|
|
17
|
+
assert config.load() == {}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
version = 1
|