Rewrite DesignGraph builder as original Periscope graph.py.

Src module classifies refs, infers net type/voltage, and prefers board nets
when a .kicad_pcb is present. PinScope graph.py remains in dependency/.
This commit is contained in:
2026-09-20 18:32:36 +02:00
parent 5a1d31ce7b
commit 7ff049f6d0
2 changed files with 417 additions and 0 deletions
+50
View File
@@ -0,0 +1,50 @@
"""Native graph builder lives in periscope/src; via≠pad stays on the KiCad PCB parser."""
from __future__ import annotations
from pathlib import Path
import backend.periscopex.graph as graph
from backend.periscopex.graph import _classify_component, _infer_net_properties
from backend.periscopex.models import ComponentType, NetType
from backend.periscopex.parsers_kicad_pcb import LayoutPad, LayoutVia
def test_graph_module_is_src_rewrite():
path = Path(graph.__file__).resolve()
assert path.parts[-5:] == ("periscope", "src", "backend", "periscopex", "graph.py")
text = path.read_text(encoding="utf-8")
assert "Native Periscope overlay" not in text
assert "original Periscope orchestration" in text
def test_classify_prefixes_and_unknown():
assert _classify_component("FB1", "") == ComponentType.INDUCTOR
assert _classify_component("RN4", "") == ComponentType.RESISTOR
assert _classify_component("F1", "") == ComponentType.FUSE
assert _classify_component("R10", "") == ComponentType.RESISTOR
assert _classify_component("9", "") == ComponentType.UNKNOWN
assert _classify_component("9", "CONN_HEADER") == ComponentType.CONNECTOR
def test_infer_ground_power_signal():
assert _infer_net_properties("GND") == (NetType.GROUND, 0.0)
assert _infer_net_properties("AGND") == (NetType.GROUND, 0.0)
ntype, volts = _infer_net_properties("+3V3")
assert ntype == NetType.POWER
assert volts == 3.3
ntype, volts = _infer_net_properties("3V3_DIGITAL")
assert ntype == NetType.POWER
assert volts == 3.3
ntype, volts = _infer_net_properties("I2C1_SCL")
assert ntype == NetType.SIGNAL
assert volts is None
def test_via_is_not_pad():
via = LayoutVia(x=0.0, y=0.0, net="GND", drill=0.3)
pad = LayoutPad(number="1", x=0.0, y=0.0, net="GND")
assert type(via) is not type(pad)
assert not hasattr(via, "number")
assert pad.number == "1"
assert via.net == "GND"