test_wiki_graph.py¶
tests/test_wiki_graph.py
The wiki's system graph (round 3, P1a): one typed model at several zoom levels.
test_a_file_belongs_to_its_package_unless_a_grouping_is_declared
None test_wiki_graph.test_a_file_belongs_to_its_package_unless_a_grouping_is_declared()
Component rules.
Checks
assert component_of("clew/query/x.py") == "clew/query"assert component_of("clew/cli.py") == "clew"assert component_of("setup.py") == "(root)"assert component_of("clew/query/x.py", (("Query layer", ("clew/query/*",)),)) == "Query layer"
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-WIKI-019 | measured | test_a_file_belongs_to_its_package_unless_a_grouping_is_declared → component_of |
Source · 8 lines
def test_a_file_belongs_to_its_package_unless_a_grouping_is_declared() -> None:
"""@brief Component rules."""
assert component_of("clew/query/x.py") == "clew/query"
assert component_of("clew/cli.py") == "clew"
assert component_of("setup.py") == "(root)"
assert component_of("clew/query/x.py", (("Query layer", ("clew/query/*",)),)) == "Query layer"
Activity · 4 steps
test_components_links_and_layout
None test_wiki_graph.test_components_links_and_layout(Path db)
Container level.
Checks
assert {"pkg/api", "pkg/core", "tests"} <= set(comps)assert link["calls"] == 1assert comps["pkg/api"]["y"] < comps["pkg/core"]["y"]assert comps["tests"]["test"] is True and comps["pkg/core"]["test"] is False
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-QUERY-001 | measured | test_components_links_and_layout → build_graph → connect |
| REQ-DDB-QUERY-003 | measured | test_components_links_and_layout → build_graph → _links → table_exists |
| REQ-DDB-WIKI-019 | measured | test_components_links_and_layout → build_graph |
Source · 16 lines
def test_components_links_and_layout(db: Path) -> None:
"""CALLERS ABOVE CALLEES: pkg/api calls pkg/core, so it sits in a higher layer.
@brief Container level.
"""
graph = build_graph(db, [], None)
comps = {c["id"]: c for c in graph["components"]}
assert {"pkg/api", "pkg/core", "tests"} <= set(comps)
link = next(
edge for edge in graph["links"] if (edge["from"], edge["to"]) == ("pkg/api", "pkg/core")
)
assert link["calls"] == 1
assert comps["pkg/api"]["y"] < comps["pkg/core"]["y"]
assert comps["tests"]["test"] is True and comps["pkg/core"]["test"] is False
Activity · 7 steps
test_lens_facts_ride_on_components_and_absent_sources_stay_absent
None test_wiki_graph.test_lens_facts_ride_on_components_and_absent_sources_stay_absent(Path db)
Lens facts.
Checks
assert plain["pkg/core"]["requirements"] == {"PASS": 1}assert "requirements" not in plain["pkg/api"]assert all("changed" not in c for c in plain.values())assert measured["pkg/core"]["changed"] == 1 and measured["pkg/api"]["changed"] == 0
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-QUERY-001 | measured | test_lens_facts_ride_on_components_and_absent_sources_stay_absent → build_graph → connect |
| REQ-DDB-QUERY-003 | measured | test_lens_facts_ride_on_components_and_absent_sources_stay_absent → build_graph → _links → table_exists |
| REQ-DDB-WIKI-019 | measured | test_lens_facts_ride_on_components_and_absent_sources_stay_absent → build_graph |
| REQ-DDB-WIKI-054 | inferred | test_lens_facts_ride_on_components_and_absent_sources_stay_absent → all |
Source · 15 lines
def test_lens_facts_ride_on_components_and_absent_sources_stay_absent(db: Path) -> None:
"""NO IMPACT REPORT, NO `changed` KEY; an empty report is a measured zero everywhere.
@brief Lens facts.
"""
evidence = [_Row("R-1", "PASS", (("save", "pkg/core/store.py", 1),))]
plain = {c["id"]: c for c in build_graph(db, evidence, None)["components"]}
assert plain["pkg/core"]["requirements"] == {"PASS": 1}
assert "requirements" not in plain["pkg/api"]
assert all("changed" not in c for c in plain.values())
impact = [{"req_id": "R-1", "functions": [{"name": "save", "file": "pkg/core/store.py"}]}]
measured = {c["id"]: c for c in build_graph(db, evidence, impact)["components"]}
assert measured["pkg/core"]["changed"] == 1 and measured["pkg/api"]["changed"] == 0
Activity · 8 steps
test_the_point_cloud_places_every_function_inside_its_box
None test_wiki_graph.test_the_point_cloud_places_every_function_inside_its_box(Path db)
Code level.
Checks
assert box is not Noneassert save["tier"] == "PASS" and "changed" not in save
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-QUERY-001 | measured | test_the_point_cloud_places_every_function_inside_its_box → build_graph → connect |
| REQ-DDB-QUERY-003 | measured | test_the_point_cloud_places_every_function_inside_its_box → build_graph → _links → table_exists |
| REQ-DDB-WIKI-019 | measured | test_the_point_cloud_places_every_function_inside_its_box → build_graph |
Source · 13 lines
def test_the_point_cloud_places_every_function_inside_its_box(db: Path) -> None:
"""@brief Code level."""
graph = build_graph(db, [_Row("R-1", "PASS", (("save", "pkg/core/store.py", 1),))], None)
comps = {c["id"]: c for c in graph["components"]}
for point in graph["symbols"]:
box = next(
c
for c in comps.values()
if c["x"] <= point["x"] <= c["x"] + c["w"] and c["y"] <= point["y"] <= c["y"] + c["h"]
)
assert box is not None
save = next(p for p in graph["symbols"] if p["name"] == "save")
assert save["tier"] == "PASS" and "changed" not in save1 more lines, not shown