Compare commits
No commits in common. "d03fafcaf6718d9af4bb9d23667d92c961a17507" and "b44c962e079882f119a6b524660349134fa1ae63" have entirely different histories.
d03fafcaf6
...
b44c962e07
4 changed files with 2 additions and 114 deletions
|
|
@ -294,9 +294,8 @@ class ILibraryView(Mapping[str, 'Pattern'], metaclass=ABCMeta):
|
||||||
def flatten_single(name: str) -> None:
|
def flatten_single(name: str) -> None:
|
||||||
flattened[name] = None
|
flattened[name] = None
|
||||||
pat = self[name].deepcopy()
|
pat = self[name].deepcopy()
|
||||||
refs_by_target = tuple((target, tuple(refs)) for target, refs in pat.refs.items())
|
|
||||||
|
|
||||||
for target, refs in refs_by_target:
|
for target in pat.refs:
|
||||||
if target is None:
|
if target is None:
|
||||||
continue
|
continue
|
||||||
if dangling_ok and target not in self:
|
if dangling_ok and target not in self:
|
||||||
|
|
@ -311,7 +310,7 @@ class ILibraryView(Mapping[str, 'Pattern'], metaclass=ABCMeta):
|
||||||
if target_pat.is_empty() and not ports_only: # avoid some extra allocations
|
if target_pat.is_empty() and not ports_only: # avoid some extra allocations
|
||||||
continue
|
continue
|
||||||
|
|
||||||
for ref in refs:
|
for ref in pat.refs[target]:
|
||||||
if flatten_ports and ref.repetition is not None and target_pat.ports:
|
if flatten_ports and ref.repetition is not None and target_pat.ports:
|
||||||
raise PatternError(
|
raise PatternError(
|
||||||
f'Cannot flatten ports from repeated ref to {target!r}; '
|
f'Cannot flatten ports from repeated ref to {target!r}; '
|
||||||
|
|
|
||||||
|
|
@ -328,9 +328,6 @@ class PortList(metaclass=ABCMeta):
|
||||||
duplicates = (set(self.ports.keys()) - set(mapping.keys())) & set(mapping.values())
|
duplicates = (set(self.ports.keys()) - set(mapping.keys())) & set(mapping.values())
|
||||||
if duplicates:
|
if duplicates:
|
||||||
raise PortError(f'Unrenamed ports would be overwritten: {duplicates}')
|
raise PortError(f'Unrenamed ports would be overwritten: {duplicates}')
|
||||||
missing = set(mapping) - set(self.ports)
|
|
||||||
if missing:
|
|
||||||
raise PortError(f'Ports to rename were not found: {missing}')
|
|
||||||
|
|
||||||
for kk, vv in mapping.items():
|
for kk, vv in mapping.items():
|
||||||
if vv is None or vv != kk:
|
if vv is None or vv != kk:
|
||||||
|
|
@ -368,8 +365,6 @@ class PortList(metaclass=ABCMeta):
|
||||||
Returns:
|
Returns:
|
||||||
self
|
self
|
||||||
"""
|
"""
|
||||||
if names[0] == names[1]:
|
|
||||||
raise PortError(f'Port names must be distinct: {names[0]!r}')
|
|
||||||
new_ports = {
|
new_ports = {
|
||||||
names[0]: Port(offset, rotation=rotation, ptype=ptype),
|
names[0]: Port(offset, rotation=rotation, ptype=ptype),
|
||||||
names[1]: Port(offset, rotation=rotation + pi, ptype=ptype),
|
names[1]: Port(offset, rotation=rotation + pi, ptype=ptype),
|
||||||
|
|
@ -400,14 +395,6 @@ class PortList(metaclass=ABCMeta):
|
||||||
Raises:
|
Raises:
|
||||||
`PortError` if the ports are not properly aligned.
|
`PortError` if the ports are not properly aligned.
|
||||||
"""
|
"""
|
||||||
if not connections:
|
|
||||||
raise PortError('Must provide at least one port connection')
|
|
||||||
missing_a = set(connections) - set(self.ports)
|
|
||||||
if missing_a:
|
|
||||||
raise PortError(f'Connection source ports were not found: {missing_a}')
|
|
||||||
missing_b = set(connections.values()) - set(self.ports)
|
|
||||||
if missing_b:
|
|
||||||
raise PortError(f'Connection destination ports were not found: {missing_b}')
|
|
||||||
a_names, b_names = list(zip(*connections.items(), strict=True))
|
a_names, b_names = list(zip(*connections.items(), strict=True))
|
||||||
a_ports = [self.ports[pp] for pp in a_names]
|
a_ports = [self.ports[pp] for pp in a_names]
|
||||||
b_ports = [self.ports[pp] for pp in b_names]
|
b_ports = [self.ports[pp] for pp in b_names]
|
||||||
|
|
|
||||||
|
|
@ -166,24 +166,6 @@ def test_library_flatten_repeated_ref_with_ports_raises() -> None:
|
||||||
lib.flatten("parent", flatten_ports=True)
|
lib.flatten("parent", flatten_ports=True)
|
||||||
|
|
||||||
|
|
||||||
def test_library_flatten_dangling_ok_nested_preserves_dangling_refs() -> None:
|
|
||||||
lib = Library()
|
|
||||||
child = Pattern()
|
|
||||||
child.ref("missing")
|
|
||||||
lib["child"] = child
|
|
||||||
|
|
||||||
parent = Pattern()
|
|
||||||
parent.ref("child")
|
|
||||||
lib["parent"] = parent
|
|
||||||
|
|
||||||
flat = lib.flatten("parent", dangling_ok=True)
|
|
||||||
|
|
||||||
assert set(flat["child"].refs) == {"missing"}
|
|
||||||
assert flat["child"].has_refs()
|
|
||||||
assert set(flat["parent"].refs) == {"missing"}
|
|
||||||
assert flat["parent"].has_refs()
|
|
||||||
|
|
||||||
|
|
||||||
def test_lazy_library() -> None:
|
def test_lazy_library() -> None:
|
||||||
lib = LazyLibrary()
|
lib = LazyLibrary()
|
||||||
called = 0
|
called = 0
|
||||||
|
|
|
||||||
|
|
@ -70,44 +70,6 @@ def test_port_list_rename() -> None:
|
||||||
assert "B" in pl.ports
|
assert "B" in pl.ports
|
||||||
|
|
||||||
|
|
||||||
def test_port_list_rename_missing_port_raises() -> None:
|
|
||||||
class MyPorts(PortList):
|
|
||||||
def __init__(self) -> None:
|
|
||||||
self._ports = {"A": Port((0, 0), 0)}
|
|
||||||
|
|
||||||
@property
|
|
||||||
def ports(self) -> dict[str, Port]:
|
|
||||||
return self._ports
|
|
||||||
|
|
||||||
@ports.setter
|
|
||||||
def ports(self, val: dict[str, Port]) -> None:
|
|
||||||
self._ports = val
|
|
||||||
|
|
||||||
pl = MyPorts()
|
|
||||||
with pytest.raises(PortError, match="Ports to rename were not found"):
|
|
||||||
pl.rename_ports({"missing": "B"})
|
|
||||||
assert set(pl.ports) == {"A"}
|
|
||||||
|
|
||||||
|
|
||||||
def test_port_list_add_port_pair_requires_distinct_names() -> None:
|
|
||||||
class MyPorts(PortList):
|
|
||||||
def __init__(self) -> None:
|
|
||||||
self._ports: dict[str, Port] = {}
|
|
||||||
|
|
||||||
@property
|
|
||||||
def ports(self) -> dict[str, Port]:
|
|
||||||
return self._ports
|
|
||||||
|
|
||||||
@ports.setter
|
|
||||||
def ports(self, val: dict[str, Port]) -> None:
|
|
||||||
self._ports = val
|
|
||||||
|
|
||||||
pl = MyPorts()
|
|
||||||
with pytest.raises(PortError, match="Port names must be distinct"):
|
|
||||||
pl.add_port_pair(names=("A", "A"))
|
|
||||||
assert not pl.ports
|
|
||||||
|
|
||||||
|
|
||||||
def test_port_list_plugged() -> None:
|
def test_port_list_plugged() -> None:
|
||||||
class MyPorts(PortList):
|
class MyPorts(PortList):
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
|
|
@ -126,48 +88,6 @@ def test_port_list_plugged() -> None:
|
||||||
assert not pl.ports # Both should be removed
|
assert not pl.ports # Both should be removed
|
||||||
|
|
||||||
|
|
||||||
def test_port_list_plugged_empty_raises() -> None:
|
|
||||||
class MyPorts(PortList):
|
|
||||||
def __init__(self) -> None:
|
|
||||||
self._ports = {"A": Port((10, 10), 0), "B": Port((10, 10), pi)}
|
|
||||||
|
|
||||||
@property
|
|
||||||
def ports(self) -> dict[str, Port]:
|
|
||||||
return self._ports
|
|
||||||
|
|
||||||
@ports.setter
|
|
||||||
def ports(self, val: dict[str, Port]) -> None:
|
|
||||||
self._ports = val
|
|
||||||
|
|
||||||
pl = MyPorts()
|
|
||||||
with pytest.raises(PortError, match="Must provide at least one port connection"):
|
|
||||||
pl.plugged({})
|
|
||||||
assert set(pl.ports) == {"A", "B"}
|
|
||||||
|
|
||||||
|
|
||||||
def test_port_list_plugged_missing_port_raises() -> None:
|
|
||||||
class MyPorts(PortList):
|
|
||||||
def __init__(self) -> None:
|
|
||||||
self._ports = {"A": Port((10, 10), 0), "B": Port((10, 10), pi)}
|
|
||||||
|
|
||||||
@property
|
|
||||||
def ports(self) -> dict[str, Port]:
|
|
||||||
return self._ports
|
|
||||||
|
|
||||||
@ports.setter
|
|
||||||
def ports(self, val: dict[str, Port]) -> None:
|
|
||||||
self._ports = val
|
|
||||||
|
|
||||||
pl = MyPorts()
|
|
||||||
with pytest.raises(PortError, match="Connection source ports were not found"):
|
|
||||||
pl.plugged({"missing": "B"})
|
|
||||||
assert set(pl.ports) == {"A", "B"}
|
|
||||||
|
|
||||||
with pytest.raises(PortError, match="Connection destination ports were not found"):
|
|
||||||
pl.plugged({"A": "missing"})
|
|
||||||
assert set(pl.ports) == {"A", "B"}
|
|
||||||
|
|
||||||
|
|
||||||
def test_port_list_plugged_mismatch() -> None:
|
def test_port_list_plugged_mismatch() -> None:
|
||||||
class MyPorts(PortList):
|
class MyPorts(PortList):
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue