Castle: The best Real-Time/Embedded/HighTech language EVER. Attempt 2
Révision | 1fe9416066c5c173e52d00091e5e5bb77e701309 (tree) |
---|---|
l'heure | 2023-09-25 23:27:00 |
Auteur | Albert Mietus < albert AT mietus DOT nl > |
Commiter | Albert Mietus < albert AT mietus DOT nl > |
RPY: added ProtocolDataStructures (test&code&template)
@@ -4,8 +4,8 @@ | ||
4 | 4 | ## |
5 | 5 | ## EventIndexes (All {{events|length}} events of {{protocol.name}}) |
6 | 6 | ## |
7 | -{% block EventIndexes %} | |
8 | - {% for e in events %} | |
9 | - {{- m.EventIndexName(protocol.name, e.name) }} = {{e.indexNo}} | |
10 | - {% endfor %} | |
11 | -{% endblock %} | |
7 | + | |
8 | +{% for e in events %} | |
9 | + {{- m.EventIndexName(protocol.name, e.name) }} = {{e.indexNo}} | |
10 | +{% endfor %} | |
11 | + |
@@ -2,21 +2,21 @@ | ||
2 | 2 | |
3 | 3 | {% import "CastleMacros.jinja2" as m %} |
4 | 4 | |
5 | -{#GAM Note: do not put {% block ... inside the loop - does not work#} | |
6 | -{% block ProtocolDataStructures %} | |
7 | - {% for p in protocols %} | |
5 | +{#GAM Note: do not put {% block ... inside the loop - does not work#} | |
8 | 6 | |
9 | -{{- m.ProtocolName(p.name) -}} = buildin.CC_B_Protocol(name="{{ p.name }}", | |
10 | - kind=buildin.{{p.kind}}, | |
11 | - inherit_from=<ToDo>, | |
12 | - events = []) | |
13 | - {% for e in p.events %} | |
14 | -{{m.ProtocolName(p.name) }}.events.append( | |
15 | - buildin.CC_B_P_EventID(name="{{- e.name -}}", | |
16 | - seqNo={{- m.EventIndexName(p.name, e.name) }}, | |
17 | - part_of={{ m.ProtocolName(p.name) }} )) | |
18 | - {% endfor %} {# event #} | |
19 | - {% endfor %} {# protocols #} | |
20 | -{% endblock %} {# ProtocolDataStructures #} | |
7 | +{% for p in protocols %} | |
8 | + {{- m.ProtocolName(p.name) }} = buildin.CC_B_Protocol(name="{{ p.name }}", | |
9 | + kind=buildin.{{p.kind}}, | |
10 | + inherit_from={{m.ProtocolName(p.based_on.name)}} | |
11 | + events = []) {#- filled in below -- see design notes // limitation #} | |
12 | + | |
13 | + {% for e in p.events %} | |
14 | + {{- m.ProtocolName(p.name) }}.events.append(buildin.CC_B_P_EventID(name="{{- e.name -}}", | |
15 | + seqNo={{- m.EventIndexName(p.name, e.name) }}, | |
16 | + part_of={{ m.ProtocolName(p.name) }} )) | |
17 | + {% endfor %} {#- event #} | |
18 | + | |
19 | +{% endfor %} {# protocols #} | |
21 | 20 | |
22 | 21 | |
22 | + |
@@ -20,6 +20,10 @@ | ||
20 | 20 | #Put the Castle/generated imports here |
21 | 21 | {% endblock %} |
22 | 22 | |
23 | +{% block EventIndexes %} | |
23 | 24 | {% include 'EventIndexes.jinja2' %} |
25 | +{% endblock %} | |
24 | 26 | |
27 | +{% block ProtocolDataStructures %} | |
25 | 28 | {% include 'ProtocolDataStructures.jinja2' %} |
29 | +{% endblock %} |
@@ -11,14 +11,41 @@ | ||
11 | 11 | from . import T_Protocol |
12 | 12 | from . import assert_marker |
13 | 13 | |
14 | +protoData_PreFix = "cc_P_" #Keep in sync with implementation | |
15 | + | |
14 | 16 | @pytest.mark.skip("XXX ToDo:: The MockProtocol should go") |
15 | 17 | def test_ToDo(): pass |
16 | 18 | |
19 | +@pytest.fixture | |
20 | +def p_1e(): | |
21 | + "Protocol with 1 event" | |
22 | + p = EventProtocol(name="P1", events=(MockEvent(name="e1", indexNo=101),)) | |
23 | + logger.debug("%s", p) | |
24 | + return p | |
17 | 25 | |
18 | -def test_0(T_ProtocolDataStructures): | |
19 | - p1=EventProtocol(name="DEMO", events=(MockEvent(name="e1", indexNo=101), MockEvent(name="e2", indexNo=102))) | |
20 | - logger.debug(p1) | |
26 | +@pytest.fixture | |
27 | +def p_2e_1i(p_1e): | |
28 | + "Protocol with 2 events, and 1 inherited; so 3 in total" | |
29 | + p = EventProtocol(name="P2", events=(MockEvent(name="e2", indexNo=102), MockEvent(name="e3", indexNo=103)), based_on=p_1e) | |
30 | + logger.debug("%s", p) | |
31 | + return p | |
21 | 32 | |
22 | - out = T_ProtocolDataStructures.render(protocols=[p1]) | |
23 | - logger.info("\n---------- out:: ------------------------\n%s\n--------------------------------", out) | |
24 | - assert False, out | |
33 | +## | |
34 | +## assert_marker(.. `need`) CALCULATION | |
35 | +## 1*p (protocol dataclasses assignment | |
36 | +## 2*e (each event: 1 [ <P-name>...append ] + 1 part_of=<P-name> | |
37 | +## The inherited events dont' count | |
38 | + | |
39 | +def test_0(T_ProtocolDataStructures, p_1e): | |
40 | + out = T_ProtocolDataStructures.render(protocols=[p_1e]) | |
41 | + logger.debug("\n---------- out:: ------------------------\n%s\n--------------------------------", out) | |
42 | + | |
43 | + assert_marker(protoData_PreFix + 'P1', out, 1+2*1) | |
44 | + | |
45 | + | |
46 | +def test_0n(T_ProtocolDataStructures, p_1e, p_2e_1i): | |
47 | + out = T_ProtocolDataStructures.render(protocols=[p_1e, p_2e_1i]) | |
48 | + logger.debug("\n---------- out:: ------------------------\n%s\n--------------------------------", out) | |
49 | + | |
50 | + assert_marker(protoData_PreFix + 'P2', out, 1+2*2) | |
51 | + |