Castle: The best Real-Time/Embedded/HighTech language EVER. Attempt 2
Revision | 0631b1df53f4594dc96c49ec0d3ea3fcc04c3145 (tree) |
---|---|
Time | 2023-10-06 22:47:43 |
Author | Albert Mietus < albert AT mietus DOT nl > |
Commiter | Albert Mietus < albert AT mietus DOT nl > |
Refacored RPy/Jinja-templates: split-off _header castle/writers/RPy/
@@ -17,11 +17,11 @@ | ||
17 | 17 | pytst/writers/RPy/test_0_templating.py \ |
18 | 18 | pytst/writers/RPy/test_1_EventIndexes.py \ |
19 | 19 | pytst/writers/RPy/test_2_ProtocolDataStructures.py \ |
20 | + pytst/aigr/test_2c_GenericProtocols.py \ | |
21 | + pytst/aigr/test_0_aid.py \ | |
20 | 22 | # |
21 | 23 | rPY_CURRENT = \ |
22 | 24 | pytst/writers/RPy/test_99_SieveMoats.py \ |
23 | - pytst/aigr/test_2c_GenericProtocols.py \ | |
24 | - pytst/aigr/test_0_aid.py \ | |
25 | 25 | # |
26 | 26 | CC2CPy_TODO = \ |
27 | 27 | pytst/writers/RPy/test_999.py \ |
@@ -3,7 +3,6 @@ | ||
3 | 3 | from castle.aigr.aid import TypedParameter |
4 | 4 | from castle.aigr import EventProtocol, Event |
5 | 5 | |
6 | -import pytest | |
7 | 6 | |
8 | 7 | StartSieve = EventProtocol('StartSieve', |
9 | 8 | events=[ |
@@ -0,0 +1,5 @@ | ||
1 | +# -*- python -*- | |
2 | +# Generated (R)Python file | |
3 | +# (C) Albert Mietus, 2023. Part of Castle/CCastle project | |
4 | + | |
5 | + |
@@ -0,0 +1,1 @@ | ||
1 | + |
@@ -1,19 +1,15 @@ | ||
1 | -# -*- python -*- | |
2 | -# Generated (R)Python file | |
3 | -# (C) Albert Mietus, 2023. Part of Castle/CCastle project | |
4 | - | |
5 | -# {#- Hi-lock: (( "{{\\(.*\\)}}" (1 'font-lock-constant-face prepend))) -#} | |
6 | -# {#- Hi-lock: (( "{%\\(.*\\)%}" (1 'font-lock-function-name-face prepend))) -#} | |
7 | -# {#- Hi-lock: (( "{#\\(.*\\)\\(#\\)}" (1 'font-lock-preprocessor-face prepend))) -#} {# regexp: '(#)}' to escape for rendering | |
8 | -# {#- Hi-lock: (( "{[{%#]\\|[}%#]}" (0 'markdown-language-keyword-face prepend))) -#} | |
9 | -# {#- Hi-lock: end -- highlight jinja2 #} | |
10 | - | |
11 | -{% import "CastleMacros.jinja2" as m1 %} | |
1 | +{% include '_header.jinja2' %} | |
2 | +{#--------------------------#} | |
3 | +{% import 'CastleMacros.jinja2' as m1 %} | |
12 | 4 | {#------------------------------------#} |
13 | 5 | |
6 | + | |
14 | 7 | {# These imports are static #} |
8 | +{% block static_imports %} | |
9 | +#### | |
15 | 10 | from CC import buildin |
16 | 11 | from CC import base |
12 | +{% endblock %} | |
17 | 13 | |
18 | 14 | {% block imports %} |
19 | 15 | #Put the Castle/generated imports here |
@@ -14,6 +14,10 @@ | ||
14 | 14 | return RPy.Template("protocol.jinja2") |
15 | 15 | |
16 | 16 | @pytest.fixture |
17 | +def T_Moat(): | |
18 | + return RPy.Template("moat.jinja2") | |
19 | + | |
20 | +@pytest.fixture | |
17 | 21 | def T_EventIndexes(): |
18 | 22 | return RPy.Template("EventIndexes.jinja2") |
19 | 23 |
@@ -69,9 +73,7 @@ | ||
69 | 73 | |
70 | 74 | def _gen_matcher(aigr_mock, td, save_file, out): |
71 | 75 | logger.debug("---------- out: (%s)----------\n%s", aigr_mock, out) |
72 | - if save_file: | |
73 | - td.write_gen(out) | |
74 | - | |
76 | + if save_file: td.write_gen(out) | |
75 | 77 | ref = td.read_ref() |
76 | 78 | try: |
77 | 79 | #assert line by line: gives better feedback when they do not match |
@@ -85,7 +87,14 @@ | ||
85 | 87 | @pytest.fixture |
86 | 88 | def generatedProtocol_verifier(T_Protocol): |
87 | 89 | def protocol_matcher(aigr_mock, td, save_file=False): |
88 | - out = T_Protocol.render(protocols=(aigr_mock,)) | |
90 | + out = T_Protocol.render(protocols=(aigr_mock,)) | |
91 | + return _gen_matcher(aigr_mock, td, save_file, out) | |
92 | + return protocol_matcher | |
93 | + | |
94 | +@pytest.fixture | |
95 | +def generatedMoat_verifier(T_Moat): | |
96 | + def protocol_matcher(aigr_mock, td, save_file=False): | |
97 | + out = T_Moat.render(XXXX=aigr_mock) | |
89 | 98 | return _gen_matcher(aigr_mock, td, save_file, out) |
90 | 99 | return protocol_matcher |
91 | 100 |
@@ -3,9 +3,9 @@ | ||
3 | 3 | |
4 | 4 | import pytest |
5 | 5 | from TestDoubles.AIGR.protocols import Sieve |
6 | -from . import TstDoubles, generatedProtocol_verifier, T_Protocol | |
7 | -##Note: T_Protocol is used in generatedProtocol_verifier; but need to be in this scope | |
8 | - | |
6 | +from . import TstDoubles, generatedProtocol_verifier, generatedMoat_verifier | |
7 | +##Note: T_* are used in **_verifier; but need to be in this scope (or pytest can't find it) | |
8 | +from . import T_Protocol, T_Moat | |
9 | 9 | |
10 | 10 | SAVE_FILE=True |
11 | 11 |
@@ -18,4 +18,7 @@ | ||
18 | 18 | def test_03_SimpleSieve(generatedProtocol_verifier): |
19 | 19 | generatedProtocol_verifier(aigr_mock=Sieve.SimpleSieve, td=TstDoubles('protocols/SimpleSieve'), save_file=SAVE_FILE) |
20 | 20 | |
21 | +@pytest.mark.fail | |
22 | +def test_04_SieveMoat(generatedMoat_verifier): | |
23 | + assert False | |
21 | 24 |