[ILibraryView / Pattern] flatten() shouldn't drop ports-only patterns if flatten_ports=True

This commit is contained in:
Jan Petykiewicz 2026-03-30 21:11:00 -07:00
commit b843ffb4d3
4 changed files with 38 additions and 3 deletions

View file

@ -2,7 +2,9 @@ import pytest
from typing import cast, TYPE_CHECKING
from ..library import Library, LazyLibrary
from ..pattern import Pattern
from ..error import LibraryError
from ..error import LibraryError, PatternError
from ..ports import Port
from ..repetition import Grid
if TYPE_CHECKING:
from ..shapes import Polygon
@ -59,6 +61,22 @@ def test_library_flatten() -> None:
assert tuple(assert_vertices[0]) == (10.0, 10.0)
def test_library_flatten_preserves_ports_only_child() -> None:
lib = Library()
child = Pattern(ports={"P1": Port((1, 2), 0)})
lib["child"] = child
parent = Pattern()
parent.ref("child", offset=(10, 10))
lib["parent"] = parent
flat_parent = lib.flatten("parent", flatten_ports=True)["parent"]
assert set(flat_parent.ports) == {"P1"}
assert cast("Port", flat_parent.ports["P1"]).rotation == 0
assert tuple(flat_parent.ports["P1"].offset) == (11.0, 12.0)
def test_lazy_library() -> None:
lib = LazyLibrary()
called = 0