forked from ChelseaKR/tods-validate
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_machine_interfaces.py
More file actions
57 lines (43 loc) · 1.6 KB
/
Copy pathtest_machine_interfaces.py
File metadata and controls
57 lines (43 loc) · 1.6 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
"""The rules subcommand and the published JSON Schema for reports."""
import json
from pathlib import Path
import jsonschema
from click.testing import CliRunner
from conftest import FIXTURES, VALID_GTFS, VALID_TODS
from tods_validate.cli import main
from tods_validate.rules import all_rules
SCHEMA = json.loads(
(Path(__file__).parent.parent / "docs" / "report.schema.json").read_text(encoding="utf-8")
)
def _report(*args: str) -> dict:
result = CliRunner().invoke(main, ["validate", *args, "--format", "json"])
return json.loads(result.output)
def test_clean_report_matches_schema() -> None:
payload = _report(str(VALID_TODS), "--gtfs", str(VALID_GTFS))
jsonschema.validate(payload, SCHEMA)
def test_findings_report_matches_schema() -> None:
payload = _report(str(FIXTURES / "invalid" / "TODS-E307"))
jsonschema.validate(payload, SCHEMA)
assert payload["summary"]["errors"] >= 1
def test_rules_json_lists_every_rule() -> None:
result = CliRunner().invoke(main, ["rules", "--format", "json"])
assert result.exit_code == 0, result.output
payload = json.loads(result.output)
assert {r["id"] for r in payload} == {r.id for r in all_rules()}
sample = payload[0]
assert set(sample) == {
"id",
"severity",
"title",
"description",
"specSection",
"needsGtfs",
"category",
"defaultEnabled",
"interpretation",
}
def test_rules_text_lists_every_rule() -> None:
result = CliRunner().invoke(main, ["rules"])
assert result.exit_code == 0
for r in all_rules():
assert r.id in result.output