[data_to_ports] don't leave the pattern dirty if we error out part-way

This commit is contained in:
Jan Petykiewicz 2026-04-01 19:10:50 -07:00
commit 0830dce50c
2 changed files with 23 additions and 3 deletions

View file

@ -98,3 +98,21 @@ def test_data_to_ports_hierarchical_repeated_ref_warns_and_keeps_best_effort(
assert "A" in parent.ports
assert_allclose(parent.ports["A"].offset, [5, 0], atol=1e-10)
assert any("importing only the base instance ports" in record.message for record in caplog.records)
def test_data_to_ports_hierarchical_collision_is_atomic() -> None:
lib = Library()
child = Pattern()
layer = (10, 0)
child.label(layer=layer, string="A:type1 0", offset=(5, 0))
lib["child"] = child
parent = Pattern()
parent.ref("child", offset=(0, 0))
parent.ref("child", offset=(10, 0))
with pytest.raises(PortError, match="Device ports conflict with existing ports"):
data_to_ports([layer], lib, parent, max_depth=1)
assert not parent.ports