Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions ymmsl/v0_2/ports.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,14 +196,14 @@ class Ports:
ports:
f_init: a
o_f: b
+timeline1:
timeline timeline1:
o_i: c d
s: e
+timeline2:
timeline timeline2:
o_i: f
s: g h

Note that the + symbol is not a part of the timeline name, it's just there to
Note that 'timeline ' is not a part of the timeline name, it's just there to
make it a bit easier to distinguish timelines from operators.

On the Python side, this class acts like a dictionary mapping port names to Port
Expand Down Expand Up @@ -351,17 +351,18 @@ def _yatiml_init(
self._add_ports(Operator.S, s)

for tl_tag, tl_ports in _yatiml_extra.items():
if not tl_tag.startswith("+"):
if not tl_tag.startswith("timeline "):
raise RuntimeError(
f'Invalid operator "{tl_tag}". Please use f_init, o_i, s, or'
" o_f, or prepend a + to the timeline name."
' o_f, or prepend "timeline " to the timeline name.'
)
tl_tag = tl_tag.removeprefix("timeline ")

if "o_i" in tl_ports:
self._add_ports(Operator.O_I, tl_ports["o_i"], tl_tag[1:])
self._add_ports(Operator.O_I, tl_ports["o_i"], tl_tag)

if "s" in tl_ports:
self._add_ports(Operator.S, tl_ports["s"], tl_tag[1:])
self._add_ports(Operator.S, tl_ports["s"], tl_tag)

additional_keys = set(tl_ports.keys()) - {"o_i", "s"}
if additional_keys:
Expand Down Expand Up @@ -406,7 +407,7 @@ def unique(timelines: List[Timeline]) -> List[Timeline]:
timeline_attrs: _PortsSubAttrs = OrderedDict()
add_ports(timeline_attrs, Operator.O_I, "o_i", timeline)
add_ports(timeline_attrs, Operator.S, "s", timeline)
attrs[f"+{timeline}"] = timeline_attrs
attrs[f"timeline {timeline}"] = timeline_attrs

add_ports(attrs, Operator.O_F, "o_f", Timeline(""))
return attrs
18 changes: 10 additions & 8 deletions ymmsl/v0_2/tests/test_ports.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,10 @@ def test_load_ports_with_timelines() -> None:
text = (
"f_init: a b\n"
"o_f: c\n"
"+timeline1:\n"
"timeline timeline1:\n"
" o_i: d\n"
" s: e f\n"
"+timeline2:\n"
"timeline timeline2:\n"
" o_i: g h\n"
)

Expand Down Expand Up @@ -245,7 +245,9 @@ def test_load_ports_invalid_operator() -> None:
def test_load_ports_invalid_timeline() -> None:
load = yatiml.load_function(Ports, Port, Operator, Timeline)

text = "f_init: a b\n+timeline1:\n o_i: d\n s: e f\ntimeline2:\n o_i: g h\n"
text = (
"f_init: a b\ntimeline timeline1:\n o_i: d\n s: e f\ntimeline2:\n o_i: g h\n"
)

with pytest.raises(yatiml.RecognitionError):
load(text)
Expand All @@ -256,12 +258,12 @@ def test_load_ports_invalid_timeline_operator() -> None:

text = (
"f_init: a b\n"
"+timeline1:\n"
"timeline timeline1:\n"
" o_i: d\n"
" s: e f\n"
"+timeline2:\n"
"timeline timeline2:\n"
" o_i: g h\n"
" +timeline3:\n"
" timeline timeline3:\n"
" o_i: i\n"
)

Expand Down Expand Up @@ -326,10 +328,10 @@ def test_dump_ports_with_timelines() -> None:

assert text == (
"f_init: init\n"
"+timeline1:\n"
"timeline timeline1:\n"
" o_i: out1\n"
" s: in1\n"
"+timeline2:\n"
"timeline timeline2:\n"
" o_i: out2\n"
" s: in2\n"
"o_f: final\n"
Expand Down