forked from ChelseaKR/tods-validate
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_registry.py
More file actions
64 lines (46 loc) · 1.95 KB
/
Copy pathtest_registry.py
File metadata and controls
64 lines (46 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
"""Sanity checks on the rule registry itself."""
from pathlib import Path
from tods_validate.findings import Severity
from tods_validate.rules import all_rules
FIXTURES = Path(__file__).parent / "fixtures" / "invalid"
_SEVERITY_LETTERS = {Severity.ERROR: "E", Severity.WARNING: "W", Severity.INFO: "I"}
def test_ids_are_unique() -> None:
ids = [r.id for r in all_rules()]
assert len(ids) == len(set(ids))
def test_id_letter_matches_severity() -> None:
for r in all_rules():
prefix, code = r.id.split("-")
assert prefix == "TODS"
assert code[0] == _SEVERITY_LETTERS[r.severity], r.id
def test_every_rule_cites_the_spec() -> None:
for r in all_rules():
assert r.spec_section.startswith("https://tods-transit.org/spec/"), r.id
def test_every_rule_has_a_dedicated_broken_fixture() -> None:
fixture_dirs = {p.name for p in FIXTURES.iterdir() if p.is_dir()}
rule_ids = {r.id for r in all_rules()}
assert fixture_dirs == rule_ids
def test_descriptions_are_written_out() -> None:
for r in all_rules():
assert r.title
assert not r.title.endswith(".")
assert len(r.description) > 40, f"{r.id} description too thin"
# The highest-frequency rules: those with root-cause cluster hints in
# report.py (TODS-E307, E308, E309, E314, W206), plus the common structural
# rules E104 and E106. These must carry a worked before/after fix example.
_HIGH_FREQUENCY_RULE_IDS = {
"TODS-E104",
"TODS-E106",
"TODS-E307",
"TODS-E308",
"TODS-E309",
"TODS-E314",
"TODS-W206",
}
def test_high_frequency_rules_have_worked_examples() -> None:
rules_by_id = {r.id: r for r in all_rules()}
for rule_id in _HIGH_FREQUENCY_RULE_IDS:
assert rule_id in rules_by_id, rule_id
example = rules_by_id[rule_id].example
assert example, f"{rule_id} is missing a worked before/after example"
assert "Before:" in example, rule_id
assert "After:" in example, rule_id