• R/O
  • SSH

提交

標籤
無標籤

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Castle: The best Real-Time/Embedded/HighTech language EVER. Attempt 2


Commit MetaInfo

修訂216c1ade7641027175cf363c249aa1c8052150b1 (tree)
時間2023-10-06 20:38:08
作者Albert Mietus < albert AT mietus DOT nl >
CommiterAlbert Mietus < albert AT mietus DOT nl >

Log Message

refactor: made generatedProtocol_verifier more generic, so it can be reused for other generated<file>_verifier

Change Summary

差異

diff -r 6ad7c136b6f6 -r 216c1ade7641 Makefile
--- a/Makefile Fri Oct 06 13:01:39 2023 +0200
+++ b/Makefile Fri Oct 06 13:38:08 2023 +0200
@@ -17,9 +17,9 @@
1717 pytst/writers/RPy/test_0_templating.py \
1818 pytst/writers/RPy/test_1_EventIndexes.py \
1919 pytst/writers/RPy/test_2_ProtocolDataStructures.py \
20- pytst/writers/RPy/test_99_SieveMoats.py \
2120 #
2221 rPY_CURRENT = \
22+ pytst/writers/RPy/test_99_SieveMoats.py \
2323 pytst/aigr/test_2c_GenericProtocols.py \
2424 pytst/aigr/test_0_aid.py \
2525 #
diff -r 6ad7c136b6f6 -r 216c1ade7641 pytst/writers/RPy/__init__.py
--- a/pytst/writers/RPy/__init__.py Fri Oct 06 13:01:39 2023 +0200
+++ b/pytst/writers/RPy/__init__.py Fri Oct 06 13:38:08 2023 +0200
@@ -67,24 +67,26 @@
6767 logger.info("Saved rendered protocol in: %s", self.gen_file)
6868
6969
70+def _gen_matcher(aigr_mock, td, save_file, out):
71+ logger.debug("---------- out: (%s)----------\n%s", aigr_mock, out)
72+ if save_file:
73+ td.write_gen(out)
74+
75+ ref = td.read_ref()
76+ try:
77+ #assert line by line: gives better feedback when they do not match
78+ for n, (o,r) in enumerate(zip(out.splitlines(keepends=True), ref.splitlines(keepends=True), strict=True)):
79+ assert o == r, "line %s does not match: >>%s<< != <<%s>>" % (n, o.strip('\n'), r.strip('\n'))
80+ except ValueError as err:
81+ assert False, f"Note the same length: files {td.gen_file} and {td.ref_file}"
82+ assert out == ref #Shouldn't be needed
83+
84+
7085 @pytest.fixture
7186 def generatedProtocol_verifier(T_Protocol):
72- def matcher(aigr_mock, td, save_file=False):
73- out = T_Protocol.render(protocols=(aigr_mock,))
74- logger.debug("---------- out: (%s)----------\n%s", aigr_mock, out)
75-
76- if save_file:
77- td.write_gen(out)
78-
79- ref = td.read_ref()
80- try:
81- #assert line by line: gives better feedback when they do not match
82- for n, (o,r) in enumerate(zip(out.splitlines(keepends=True), ref.splitlines(keepends=True), strict=True)):
83- assert o == r, "line %s does not match: >>%s<< != <<%s>>" % (n, o.strip('\n'), r.strip('\n'))
84- except ValueError as err:
85- assert False, f"Note the same length: files {td.gen_file} and {td.ref_file}"
86-
87- assert out == ref #Should be needed
88- return matcher
87+ def protocol_matcher(aigr_mock, td, save_file=False):
88+ out = T_Protocol.render(protocols=(aigr_mock,))
89+ return _gen_matcher(aigr_mock, td, save_file, out)
90+ return protocol_matcher
8991
9092
diff -r 6ad7c136b6f6 -r 216c1ade7641 pytst/writers/RPy/test_99_SieveMoats.py
--- a/pytst/writers/RPy/test_99_SieveMoats.py Fri Oct 06 13:01:39 2023 +0200
+++ b/pytst/writers/RPy/test_99_SieveMoats.py Fri Oct 06 13:38:08 2023 +0200
@@ -18,3 +18,4 @@
1818 def test_03_SimpleSieve(generatedProtocol_verifier):
1919 generatedProtocol_verifier(aigr_mock=Sieve.SimpleSieve, td=TstDoubles('protocols/SimpleSieve'), save_file=SAVE_FILE)
2020
21+