ChimeraTK-ApplicationCore 04.06.00
Loading...
Searching...
No Matches
testPythonDataConsistencyGroup.py
Go to the documentation of this file.
1import sys
2import os
3import os.path
4import traceback
5import threading
6
7# fmt: off
8# Hack to insert the python path for the locally compiled module in the
9# test script
10sys.path.insert(0, os.path.abspath(os.path.join(os.curdir, "..")))
11import PyApplicationCore as ac # NOQA
12# fmt: on
13
14class Sender(ac.ApplicationModule):
15
16 def __init__(self, owner, name, description):
17 super().__init__(owner, name, description)
18
19 self.out1 = ac.ScalarOutput(ac.DataType.int32, self, "in1", "", "")
20 self.out2 = ac.ScalarOutput(ac.DataType.int32, self, "in2", "", "")
21 self.out3 = ac.ScalarOutput(ac.DataType.int32, self, "in3", "", "")
22
23 self.letsStart = ac.ScalarPushInput(ac.DataType.int32, self, "letsStart", "", "")
24
25 def prepare(self):
26 self.out1.write()
27 self.out2.write()
28 self.out3.write()
29
30 def mainLoop(self):
31 sys.stdout.flush()
32
33 self.setCurrentVersionNumber(ac.VersionNumber())
34 self.out1.write()
35 self.out3.write()
36 self.out2.write()
37
38 self.setCurrentVersionNumber(ac.VersionNumber())
39 self.out1.write()
40 self.out3.write()
41 self.setCurrentVersionNumber(ac.VersionNumber())
42 self.out2.write()
43
44 # for last part of test, with MatchingMode.historized
45 self.out2.write()
46 self.out1.write()
47
48
49class Receiver(ac.ApplicationModule):
50
51 def __init__(self, owner, name, description):
52 super().__init__(owner, name, description)
53
54 self.in1 = ac.ScalarPushInput(ac.DataType.int32, self, "in1", "", "")
55 self.in2 = ac.ScalarPushInput(ac.DataType.int32, self, "in2", "", "")
56 self.in3 = ac.ScalarPushInput(ac.DataType.int32, self, "in3", "", "")
57
58 self.letsStart = ac.ScalarOutput(ac.DataType.int32, self, "letsStart", "", "")
59
60 self.testError = ac.ScalarOutput(ac.DataType.string, self, "testError", "", "")
61
62
63 def mainLoop(self):
64
65 try:
66 sys.stdout.flush()
67 rag = self.readAnyGroup()
68
69 dg = ac.DataConsistencyGroup(self.in1, self.in2)
70 dg.add(self.in3)
71
72 sys.stdout.flush()
73 self.letsStart.write()
74
75 change = rag.readAny()
76 isValid = dg.update(change)
77 assert not isValid
78 change = rag.readAny()
79 isValid = dg.update(change)
80 assert not isValid
81 change = rag.readAny()
82 isValid = dg.update(change)
83 assert isValid
84
85
86 change = rag.readAny()
87 isValid = dg.update(change)
88 assert not isValid
89 change = rag.readAny()
90 isValid = dg.update(change)
91 assert not isValid
92 change = rag.readAny()
93 isValid = dg.update(change)
94 assert not isValid
95
96 # Note, it is fine to create a DataConsistencyGroup with MatchingMode.historized after MatchingMode.exact,
97 # but the other way round would not be valid.
98 dgh = ac.DataConsistencyGroup(self.in1, self.in2, mode=ac.MatchingMode.historized, histLen = 1)
99 change = rag.readAny()
100 isValid = dgh.update(change)
101 assert isValid
102
103 self.testError.setAndWrite("ok")
104
105
106 except AssertionError as e:
107 print("Exception: "+"\n".join(traceback.format_exception(e)))
108 sys.stdout.flush()
109 self.testError.setAndWrite("\n".join(traceback.format_exception(e)))
110
111
112
113ac.app.sender = Sender(ac.app, "UserModule", "")
114ac.app.receiver = Receiver(ac.app, "UserModule", "")
void mainLoop() override