[PortList] plugged() failure shouldn't dirty the ports
This commit is contained in:
parent
35b42c397b
commit
395ad4df9d
2 changed files with 26 additions and 1 deletions
|
|
@ -182,9 +182,30 @@ def test_port_list_plugged_missing_port_raises() -> None:
|
|||
pl.plugged({"missing": "B"})
|
||||
assert set(pl.ports) == {"A", "B"}
|
||||
|
||||
|
||||
def test_port_list_plugged_reused_port_raises_atomically() -> None:
|
||||
class MyPorts(PortList):
|
||||
def __init__(self) -> None:
|
||||
self._ports = {"A": Port((0, 0), None), "B": Port((0, 0), None), "C": Port((0, 0), None)}
|
||||
|
||||
@property
|
||||
def ports(self) -> dict[str, Port]:
|
||||
return self._ports
|
||||
|
||||
@ports.setter
|
||||
def ports(self, val: dict[str, Port]) -> None:
|
||||
self._ports = val
|
||||
|
||||
for connections in ({"A": "A"}, {"A": "B", "C": "B"}):
|
||||
pl = MyPorts()
|
||||
with pytest.raises(PortError, match="Each port may appear in at most one connection"):
|
||||
pl.plugged(connections)
|
||||
assert set(pl.ports) == {"A", "B", "C"}
|
||||
|
||||
pl = MyPorts()
|
||||
with pytest.raises(PortError, match="Connection destination ports were not found"):
|
||||
pl.plugged({"A": "missing"})
|
||||
assert set(pl.ports) == {"A", "B"}
|
||||
assert set(pl.ports) == {"A", "B", "C"}
|
||||
|
||||
|
||||
def test_port_list_plugged_mismatch() -> None:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue