54 lines
2.0 KiB
Python
54 lines
2.0 KiB
Python
from __future__ import annotations
|
|
|
|
import unittest
|
|
|
|
from techviz.layout import DiagramLayout, EdgePath, NodeBox
|
|
from techviz.quality import validate_layout
|
|
from techviz.spec import VizSpec
|
|
|
|
|
|
class QualityTests(unittest.TestCase):
|
|
def test_detects_edge_passing_through_unrelated_node(self) -> None:
|
|
spec = VizSpec.from_dict(
|
|
{
|
|
"version": "1.0",
|
|
"id": "quality-case",
|
|
"title": "Quality case",
|
|
"question": "Does an edge cross a node?",
|
|
"type": "architecture",
|
|
"direction": "LR",
|
|
"summary": "Synthetic quality test.",
|
|
"alt": "Synthetic diagram with three nodes.",
|
|
"long_description": "A line from A to C passes through unrelated node B.",
|
|
"source_context": {},
|
|
"groups": [],
|
|
"nodes": [
|
|
{"id": "a", "label": "A", "kind": "service", "evidence": [], "assumption": True},
|
|
{"id": "b", "label": "B", "kind": "service", "evidence": [], "assumption": True},
|
|
{"id": "c", "label": "C", "kind": "service", "evidence": [], "assumption": True}
|
|
],
|
|
"edges": [
|
|
{"id": "a-to-c", "from": "a", "to": "c", "label": "calls", "kind": "request", "evidence": [], "assumption": True}
|
|
]
|
|
}
|
|
)
|
|
layout = DiagramLayout(
|
|
width=500,
|
|
height=240,
|
|
nodes={
|
|
"a": NodeBox("a", 20, 80, 100, 60, ["A"]),
|
|
"b": NodeBox("b", 190, 80, 100, 60, ["B"]),
|
|
"c": NodeBox("c", 360, 80, 100, 60, ["C"]),
|
|
},
|
|
groups={},
|
|
edges={
|
|
"a-to-c": EdgePath("a-to-c", [(120, 110), (360, 110)], 240, 70)
|
|
},
|
|
)
|
|
issues = validate_layout(spec, layout)
|
|
self.assertTrue(any(issue.code == "edge-through-node" for issue in issues))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|