[ILibraryView / Pattern] flatten() should raise PatternError if asked to preserve ports from a repeated ref

This commit is contained in:
Jan Petykiewicz 2026-03-30 21:17:33 -07:00
commit c32168dc64
4 changed files with 36 additions and 0 deletions

View file

@ -77,6 +77,20 @@ def test_library_flatten_preserves_ports_only_child() -> None:
assert tuple(flat_parent.ports["P1"].offset) == (11.0, 12.0)
def test_library_flatten_repeated_ref_with_ports_raises() -> None:
lib = Library()
child = Pattern(ports={"P1": Port((1, 2), 0)})
child.polygon((1, 0), vertices=[[0, 0], [1, 0], [0, 1]])
lib["child"] = child
parent = Pattern()
parent.ref("child", repetition=Grid(a_vector=(10, 0), a_count=2))
lib["parent"] = parent
with pytest.raises(PatternError, match='Cannot flatten ports from repeated ref'):
lib.flatten("parent", flatten_ports=True)
def test_lazy_library() -> None:
lib = LazyLibrary()
called = 0