by adom
Publish molecule sources to the Adom wiki (STEP, board, schematic, <slug>-fab.zip, export.json); the wiki's 3D model registry builds the GLB, footprint and symbol. Checks the bundle the way the registry does, publishes private, waits for the build, sets the hero from the built model, then makes the page public. Board mode still converts plain boards. Also writes APM render assets and component dependencies. Companion to adom-wiki model import.
master
AdityaAngajala
Preserve source for molecule-publish-3.0.0
33f54d8
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
"""The skill's copies of the molecule contract files match the contract release it names; run with unittest."""
import hashlib
import importlib.util
import json
import subprocess
import sys
import tempfile
import unittest
from pathlib import Path
SCRIPTS = Path(__file__).resolve().parents[1] / "scripts"
def sha256(path):
return hashlib.sha256(path.read_bytes()).hexdigest()
def load(name):
spec = importlib.util.spec_from_file_location(name, SCRIPTS / f"{name}.py")
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
return module
class ContractCopyTests(unittest.TestCase):
def setUp(self):
self.contract = json.loads((SCRIPTS / "contract.json").read_text(encoding="utf-8"))
self.versions = self.contract["versions"]
def test_contract_is_the_molecule_contract(self):
self.assertEqual(self.contract["schema"], "adom.molecule-contract/1")
self.assertEqual([r["name"] for r in self.contract["recipes"]], ["molecule-circuit", "molecule-board", "molecule-step"])
self.assertEqual(self.versions["publisherMinimum"], "3.0.0")
self.assertEqual(self.versions["cliMinimum"], "1.8.0")
def test_pin_names_is_the_programs_names_py(self):
self.assertEqual(sha256(SCRIPTS / "pin_names.py"), self.versions["namesPy"])
def test_pins_json_is_the_contracts(self):
self.assertEqual(sha256(SCRIPTS / "pins.json"), self.versions["pins"])
def test_fab_bundle_is_the_one_the_program_vendors(self):
self.assertEqual(sha256(SCRIPTS / "fab_bundle.py"), self.versions["fabBundle"]["sha256"])
def test_self_check_reports_no_drift(self):
run = subprocess.run([sys.executable, "-B", str(SCRIPTS / "pin_names.py"), "--self-check", str(SCRIPTS / "contract.json")],
capture_output=True, text=True, timeout=60)
self.assertEqual(run.returncode, 0, run.stderr)
self.assertEqual(json.loads(run.stdout), {"namesPy": self.versions["namesPy"], "pins": self.versions["pins"]})
self.assertNotIn("warning", run.stderr)
def test_pin_names_reads_altium_boards_through_pcbdoc_beside_it(self):
self.assertTrue((SCRIPTS / "pcbdoc.py").is_file())
with tempfile.TemporaryDirectory() as d:
board = Path(d) / "x.PcbDoc"
board.write_bytes(b"not a compound file")
run = subprocess.run([sys.executable, "-B", str(SCRIPTS / "pin_names.py"), "check", str(board), "--json"],
capture_output=True, text=True, timeout=60)
self.assertEqual(run.returncode, 1, run.stderr)
checks = json.loads(run.stdout)["checks"]
self.assertEqual([c["id"] for c in checks], ["board-read"])
self.assertIn("not an OLE2 compound file", checks[0]["detail"])
def test_component_graph_reads_the_furniture_rule_from_pins_json(self):
graph = load("component_graph")
near = json.loads((SCRIPTS / "pins.json").read_text(encoding="utf-8"))["designators"]["nearMiss"]
self.assertEqual(graph.FURNITURE_REFS.pattern, near["pattern"])
self.assertEqual(graph.classify({"ref": "mp3", "footprint": "MachinePinMediumShort"}), "furniture")
self.assertEqual(graph.classify({"ref": "MC12", "footprint": "MachineContactMedium"}), "furniture")
self.assertEqual(graph.classify({"ref": "U1", "footprint": "SOIC-8"}), "electrical")
if __name__ == "__main__":
unittest.main()