forked from ChelseaKR/oscal-validate
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_constraint_coverage.py
More file actions
44 lines (31 loc) · 1.41 KB
/
Copy pathtest_constraint_coverage.py
File metadata and controls
44 lines (31 loc) · 1.41 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
"""The published coverage table must match the vendored files it describes.
A repository that publishes "78 of 340 constraints" and then quietly drifts is
making a claim it no longer checks. `make coverage-doc` regenerates the file;
this test fails if the committed copy is stale.
"""
from __future__ import annotations
import subprocess
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parent.parent
COVERAGE = ROOT / "docs" / "CONSTRAINT-COVERAGE.md"
def _generated() -> str:
result = subprocess.run(
[sys.executable, str(ROOT / "tools" / "constraint_coverage.py"), "/dev/stdout"],
capture_output=True,
check=True,
text=True,
)
return result.stdout.rsplit("wrote /dev/stdout", 1)[0]
def test_the_committed_coverage_table_is_current() -> None:
assert COVERAGE.read_text(encoding="utf-8") == _generated()
def test_the_coverage_table_lists_every_constraint() -> None:
from oscal_validate.metaschema import load_metaschema
text = COVERAGE.read_text(encoding="utf-8")
for constraint in load_metaschema().constraints:
if constraint.identifier:
assert f"`{constraint.identifier}`" in text, constraint.identifier
def test_the_coverage_table_never_claims_a_clean_run_means_conformance() -> None:
text = COVERAGE.read_text(encoding="utf-8")
assert "Neither passed nor failed" in text
assert "may still violate any of these" in text