"""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"