[Pattern] improve atomicity of place(), plug(), interface()
This commit is contained in:
parent
395ad4df9d
commit
9767ee4e62
2 changed files with 63 additions and 11 deletions
|
|
@ -5,10 +5,11 @@ from numpy.testing import assert_equal, assert_allclose
|
|||
from numpy import pi
|
||||
|
||||
from ..error import PatternError
|
||||
from ..abstract import Abstract
|
||||
from ..pattern import Pattern
|
||||
from ..shapes import Polygon
|
||||
from ..ref import Ref
|
||||
from ..ports import Port
|
||||
from ..ports import Port, PortError
|
||||
from ..label import Label
|
||||
from ..repetition import Grid
|
||||
|
||||
|
|
@ -134,6 +135,18 @@ def test_pattern_place_requires_abstract_for_reference() -> None:
|
|||
with pytest.raises(PatternError, match='Must provide an `Abstract`'):
|
||||
parent.place(child)
|
||||
|
||||
assert not parent.ports
|
||||
|
||||
|
||||
def test_pattern_place_append_requires_pattern_atomically() -> None:
|
||||
parent = Pattern()
|
||||
child = Abstract("child", {"A": Port((1, 2), 0)})
|
||||
|
||||
with pytest.raises(PatternError, match='Must provide a full `Pattern`'):
|
||||
parent.place(child, append=True)
|
||||
|
||||
assert not parent.ports
|
||||
|
||||
|
||||
def test_pattern_interface() -> None:
|
||||
source = Pattern()
|
||||
|
|
@ -151,6 +164,34 @@ def test_pattern_interface() -> None:
|
|||
assert iface.ports["out_A"].ptype == "test"
|
||||
|
||||
|
||||
def test_pattern_interface_duplicate_port_map_targets_raise() -> None:
|
||||
source = Pattern()
|
||||
source.ports["A"] = Port((10, 20), 0)
|
||||
source.ports["B"] = Port((30, 40), pi)
|
||||
|
||||
with pytest.raises(PortError, match='Duplicate targets in `port_map`'):
|
||||
Pattern.interface(source, port_map={"A": "X", "B": "X"})
|
||||
|
||||
|
||||
def test_pattern_interface_empty_port_map_copies_no_ports() -> None:
|
||||
source = Pattern()
|
||||
source.ports["A"] = Port((10, 20), 0)
|
||||
source.ports["B"] = Port((30, 40), pi)
|
||||
|
||||
assert not Pattern.interface(source, port_map={}).ports
|
||||
assert not Pattern.interface(source, port_map=[]).ports
|
||||
|
||||
|
||||
def test_pattern_plug_requires_abstract_for_reference_atomically() -> None:
|
||||
parent = Pattern(ports={"X": Port((0, 0), 0)})
|
||||
child = Pattern(ports={"A": Port((0, 0), pi)})
|
||||
|
||||
with pytest.raises(PatternError, match='Must provide an `Abstract`'):
|
||||
parent.plug(child, {"X": "A"})
|
||||
|
||||
assert set(parent.ports) == {"X"}
|
||||
|
||||
|
||||
def test_pattern_append_port_conflict_is_atomic() -> None:
|
||||
pat1 = Pattern()
|
||||
pat1.ports["A"] = Port((0, 0), 0)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue