Castle: The best Real-Time/Embedded/HighTech language EVER. Attempt 2
Révision | b2432bdd5231ad6a709d3dd967f7161ba52df9cd (tree) |
---|---|
l'heure | 2023-09-26 23:20:00 |
Auteur | Albert Mietus < albert AT mietus DOT nl > |
Commiter | Albert Mietus < albert AT mietus DOT nl > |
MockEvent & MockProtocol are gone from the tests now
@@ -8,16 +8,17 @@ | ||
8 | 8 | # CURRENT: The now current test, in TDD phase |
9 | 9 | # TODO: Some test that are needed soon |
10 | 10 | rPY_LAST = \ |
11 | - pytst/writers/RPy/test_0_templating.py \ | |
12 | 11 | pytst/aigr/test_0_AIGR.py \ |
13 | 12 | pytst/aigr/test_1_events.py \ |
14 | 13 | pytst/aigr/test_2a_protocolKind.py \ |
15 | 14 | pytst/aigr/test_2b_protocol.py \ |
15 | + pytst/aigr/test_2b_protocol.py \ | |
16 | + pytst/writers/RPy/test_0_templating.py \ | |
16 | 17 | pytst/writers/RPy/test_1_EventIndexes.py \ |
18 | + pytst/writers/RPy/test_2_ProtocolDataStructures.py \ | |
17 | 19 | # |
18 | 20 | rPY_CURRENT = \ |
19 | - pytst/aigr/test_2b_protocol.py \ | |
20 | - pytst/writers/RPy/test_2_ProtocolDataStructures.py \ | |
21 | + pytst/writers/RPy/test_1_EventIndexes.py \ | |
21 | 22 | # |
22 | 23 | CC2CPy_TODO = \ |
23 | 24 | pytst/writers/RPy/test_99_StartSieve.py \ |
@@ -10,13 +10,6 @@ | ||
10 | 10 | from castle.aigr import Event, Protocol |
11 | 11 | from castle.writers import RPy |
12 | 12 | |
13 | -@dataclass | |
14 | -class MockEvent(Event): | |
15 | - indexNo: int | |
16 | - | |
17 | -@dataclass | |
18 | -class MockProtocol(): | |
19 | - name: str | |
20 | 13 | |
21 | 14 | @pytest.fixture |
22 | 15 | def T_Protocol(): |
@@ -32,10 +25,13 @@ | ||
32 | 25 | |
33 | 26 | |
34 | 27 | |
35 | -def assert_marker(marker, txt, need, msg=None): | |
28 | +def assert_marker(marker, txt, need=None, msg=None): | |
36 | 29 | lines = txt.splitlines() |
37 | 30 | c = sum(1 if (marker in line) else 0 for line in lines) |
38 | - assert c == need, f"Needed {need} lines with '{marker}'-markers, found {c} -- in {len(lines)} lines" + ((+ ' ' + msg) if msg else "") | |
31 | + if need is None: | |
32 | + assert c > 0, f"Expected lines with '{marker}'-marker, found nothing in:\n----\n{txt}\n----" | |
33 | + else: | |
34 | + assert c == need, f"Needed {need} lines with '{marker}'-markers, found {c} -- in {len(lines)} lines" + ((+ ' ' + msg) if msg else "") | |
39 | 35 | |
40 | 36 | |
41 | 37 | def get_dirPath_of_file(f=__file__): |
@@ -5,9 +5,8 @@ | ||
5 | 5 | |
6 | 6 | from castle.aigr.types import TypedParameter |
7 | 7 | |
8 | -from castle.aigr import EventProtocol | |
8 | +from castle.aigr import EventProtocol, Event | |
9 | 9 | from . import T_EventIndexes |
10 | -from . import MockEvent | |
11 | 10 | from . import T_Protocol |
12 | 11 | from . import assert_marker |
13 | 12 |
@@ -15,10 +14,6 @@ | ||
15 | 14 | EventIndex_PreFix = "CC_P_" #Keep in sync with implementation |
16 | 15 | |
17 | 16 | |
18 | -@pytest.mark.skip("XXX ToDo:: The MockEvent should go") | |
19 | -def test_ToDo(): pass | |
20 | - | |
21 | - | |
22 | 17 | def test_template_0_NoEvent(T_EventIndexes): |
23 | 18 | p = EventProtocol("NoEventsMOCK", events=[]) |
24 | 19 | out=T_EventIndexes.render(protocol=p, events=p.events) |
@@ -29,29 +24,29 @@ | ||
29 | 24 | |
30 | 25 | |
31 | 26 | def test_template_1_event(T_EventIndexes): |
32 | - p = EventProtocol("MOCK", events=[MockEvent("input", indexNo=-7, typedParameters=[TypedParameter(name='event', type=int)])]) | |
27 | + p = EventProtocol("MOCK", events=[Event("input", typedParameters=[TypedParameter(name='event', type=int)])]) | |
33 | 28 | out=T_EventIndexes.render(protocol=p, events=p.events) |
34 | 29 | logger.debug("out::\n%s", out) |
35 | 30 | |
36 | 31 | assert_marker(EventIndex_PreFix, out, 1) |
37 | - assert_marker('=', out, 1) | |
32 | + assert_marker('= 0', out) | |
38 | 33 | |
39 | 34 | |
40 | 35 | def test_template_2_SomeEvent(T_EventIndexes): |
41 | - p = EventProtocol("MOCK", events=\ | |
42 | - [ MockEvent("one", indexNo=1), | |
43 | - MockEvent("two", indexNo=2), | |
44 | - MockEvent("three",indexNo=3), | |
45 | - MockEvent("four", indexNo=4)]) | |
36 | + p = EventProtocol("MOCK", events= [Event("one"), Event("two"), Event("three"), Event("four")]) | |
46 | 37 | out=T_EventIndexes.render(protocol=p, events=p.events) |
47 | 38 | logger.debug("out::\n%s", out) |
48 | 39 | |
49 | 40 | assert_marker(EventIndex_PreFix, out, 4) |
50 | - assert_marker('=', out, 4) | |
41 | + assert_marker('= 0', out) | |
42 | + assert_marker('= 1', out) | |
43 | + assert_marker('= 2', out) | |
44 | + assert_marker('= 3', out) | |
45 | + | |
51 | 46 | |
52 | 47 | |
53 | 48 | def test_EventIndexes_In_protocol(T_Protocol): |
54 | - out=T_Protocol.render(protocols=[EventProtocol(name="MOCK", events=[MockEvent("input", indexNo=-7)])]) | |
49 | + out=T_Protocol.render(protocols=[EventProtocol(name="MOCK", events=[Event("input")])]) | |
55 | 50 | logger.info("\n---------- out:: ------------------------\n%s\n--------------------------------", out) |
56 | 51 | assert True, "No assert (not maintainable) only check it runs" |
57 | 52 |
@@ -3,11 +3,10 @@ | ||
3 | 3 | import logging; logger = logging.getLogger(__name__) |
4 | 4 | import pytest |
5 | 5 | |
6 | -from castle.aigr import Event, EventProtocol | |
6 | +from castle.aigr import EventProtocol, Event | |
7 | 7 | from castle.aigr.types import TypedParameter |
8 | 8 | |
9 | 9 | from . import T_ProtocolDataStructures |
10 | -from . import MockEvent | |
11 | 10 | from . import T_Protocol |
12 | 11 | from . import assert_marker |
13 | 12 |
@@ -19,14 +18,14 @@ | ||
19 | 18 | @pytest.fixture |
20 | 19 | def p_1e(): |
21 | 20 | "Protocol with 1 event" |
22 | - p = EventProtocol(name="P1", events=(MockEvent(name="e1", indexNo=101),)) | |
21 | + p = EventProtocol(name="P1", events=(Event(name="e1"),)) | |
23 | 22 | logger.debug("%s", p) |
24 | 23 | return p |
25 | 24 | |
26 | 25 | @pytest.fixture |
27 | 26 | def p_2e_1i(p_1e): |
28 | 27 | "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) | |
28 | + p = EventProtocol(name="P2", events=(Event(name="e2"), Event(name="e3")), based_on=p_1e) | |
30 | 29 | logger.debug("%s", p) |
31 | 30 | return p |
32 | 31 |
@@ -1,20 +1,15 @@ | ||
1 | 1 | # (C) Albert Mietus, 2023. Part of Castle/CCastle project |
2 | 2 | |
3 | 3 | import logging; logger = logging.getLogger(__name__) |
4 | + | |
4 | 5 | import pytest |
5 | 6 | |
6 | -from castle.aigr.types import TypedParameter | |
7 | +from pytst.TestDoubles.protocols import StartSieve #XXX | |
7 | 8 | |
8 | 9 | from . import T_Protocol |
9 | -from . import MockEvent, MockProtocol | |
10 | 10 | |
11 | 11 | @pytest.mark.xfail |
12 | 12 | def test_99_StartSieve(T_Protocol): |
13 | - out = T_Protocol.render( | |
14 | - protocol=MockProtocol("StartSieve"), | |
15 | - events=[ | |
16 | - MockEvent("runTo", indexNo=7, typedParameters=[TypedParameter(name='max', type=int)]), | |
17 | - MockEvent("newMax", indexNo=8, typedParameters=[TypedParameter(name='max', type=int)]), | |
18 | - ]) | |
13 | + out = T_Protocol.render(protocols=[StartSieve,]) | |
19 | 14 | logger.info("\n---------- out:: ------------------------\n%s\n--------------------------------", out) |
20 | 15 | assert False |