Files
FacereDataset/tools/epro2/tests/test_pro_writer.py
Knowit 3c00edf6db tools/epro2/kicad: --all emits paired .kicad_pro + .kicad_sch + .kicad_pcb per BOARD
KiCad pairs project files purely by basename + same directory: a folder
holding `Foo.kicad_pro`, `Foo.kicad_sch`, `Foo.kicad_pcb` opens as one
project on double-click of the .kicad_pro, with cross-tool navigation
(open footprint from schematic etc) wired up automatically.

  - pro_writer.write_kicad_pro() renders the minimal KiCad 8 JSON we
    need: meta.filename pinning the basename, sheets=[[<root_uuid>,
    ""]] binding the schematic root, and stub blocks for board /
    schematic / net_settings / erc that KiCad expects to find on the
    first GUI load.
  - root_sch_writer.write_root_sheet() now accepts an optional
    root_uuid so the caller can pass the same uuid into the .kicad_pro
    and .kicad_sch (the binding fails silently with mismatched ids).
  - CLI gains `--all`: groups SCH/PCB docs by their META.board uuid
    (1:1 in EPRO2), strips SCH-/PCB- editor prefixes from titles to
    derive a shared project basename, and emits one directory per
    BOARD with paired files. BOARDs whose SCH is DELETE_DOC (LCD-BD on
    ESP-VoCat) still get a .kicad_pro with sheets:[] + .kicad_pcb so
    pcbnew opens cleanly.

ESP-VoCat smoke: 6 boards → 6 project dirs, all pairs validated by
kicad-cli sch erc / pcb export svg. The CoreBoard pro/sch/pcb trio
shares root uuid 366d3e53...c2fccbe4330b end-to-end.

68 → 71 unit tests pass.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-29 00:39:58 +08:00

39 lines
1.6 KiB
Python

"""Project file emitter regression."""
import json
from tools.epro2.kicad.pro_writer import write_kicad_pro
def test_pro_carries_filename_and_root_sheet_uuid():
"""The .kicad_pro must record (a) its own filename so KiCad confirms
the basename matches the .kicad_sch / .kicad_pcb siblings, and (b)
the root sheet uuid in the `sheets` array — that's how KiCad binds
the project to the schematic root. A `sheets: []` pro file works
for "open a one-off PCB" but loses cross-tool navigation in the
schematic editor."""
text = write_kicad_pro("EchoEar-CoreBoard", root_sheet_uuid="abc-123")
j = json.loads(text)
assert j["meta"]["filename"] == "EchoEar-CoreBoard.kicad_pro"
assert j["sheets"] == [["abc-123", ""]]
def test_pro_without_root_uuid_emits_empty_sheets_array():
"""When called for a board that has only a PCB (the SCH was
DELETE_DOC), there's no root sheet uuid. Emit `sheets: []` so
the project file still parses — KiCad will simply not show a
schematic editor on open."""
text = write_kicad_pro("OnlyPcb", root_sheet_uuid=None)
j = json.loads(text)
assert j["sheets"] == []
def test_pro_top_level_keys_present_for_kicad_8():
"""KiCad 8 expects certain top-level keys to exist (it'll
backfill missing ones but with a "save changes?" prompt every
open). Smoke-test: assert the keys that GUI reads at startup."""
text = write_kicad_pro("X")
j = json.loads(text)
for key in ("board", "meta", "schematic", "sheets", "net_settings"):
assert key in j, f"missing top-level key: {key}"