Skip to content

Commit fbf382d

Browse files
committed
Add checks for conduit filter order
- It's not allowed to have a reducer after a repeater -> taking the last of a repeated message is not useful - It's not allowed to have a repeat filter after a pad filter -> it would repeat nil messages
1 parent f4d1820 commit fbf382d

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

‎ymmsl/v0_2/model.py‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,21 @@ def __init__(
126126
self.__check_reference(self.sender)
127127
self.__check_reference(self.receiver)
128128

129+
# Check if filters are in the correct order:
130+
err_msg = None
131+
for i in range(len(self.filters) - 1):
132+
pair = self.filters[i : i + 2]
133+
if pair == [ConduitFilter.REPEAT, ConduitFilter.LAST]:
134+
err_msg = "'repeat' filter must come after 'last'"
135+
break
136+
if pair == [ConduitFilter.PAD, ConduitFilter.LAST]:
137+
err_msg = "'pad' filter must come after 'last'"
138+
break
139+
if pair == [ConduitFilter.PAD, ConduitFilter.REPEAT]:
140+
err_msg = "'pad' filter must come after 'repeat'"
141+
if err_msg is not None:
142+
raise RuntimeError(f"Invalid conduit filter for {self}: {err_msg}.")
143+
129144
def __str__(self) -> str:
130145
"""Return a string representation of the object."""
131146
if not self.filters:

‎ymmsl/v0_2/tests/test_model.py‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,21 @@ def test_conduit_filter() -> None:
2121
assert ConduitFilter.PAD.is_repeater()
2222

2323

24+
def test_conduit_order() -> None:
25+
Conduit("a", "b", "last last")
26+
Conduit("a", "b", "last pad")
27+
Conduit("a", "b", "last repeat")
28+
Conduit("a", "b", "repeat repeat")
29+
Conduit("a", "b", "repeat pad")
30+
Conduit("a", "b", "pad pad")
31+
with pytest.raises(RuntimeError):
32+
Conduit("a", "b", "repeat last")
33+
with pytest.raises(RuntimeError):
34+
Conduit("a", "b", "pad last")
35+
with pytest.raises(RuntimeError):
36+
Conduit("a", "b", "pad repeat")
37+
38+
2439
def test_conduit_access() -> None:
2540
conduit = Conduit("macro.out", "micro.in")
2641

0 commit comments

Comments
 (0)