ChimeraTK-ApplicationCore 04.08.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
14
15class Sender(ac.ApplicationModule):
16
17 def __init__(self, owner, name, description):
18 super().__init__(owner, name, description)
19
20 self.out1 = ac.ScalarOutput(ac.DataType.int32, self, "in1", "", "")
21 self.out2 = ac.ScalarOutput(ac.DataType.int32, self, "in2", "", "")
22 self.out3 = ac.ScalarOutput(ac.DataType.int32, self, "in3", "", "")
23
24 self.letsStart = ac.ScalarPushInput(ac.DataType.int32, self, "letsStart", "", "")
25
26 def prepare(self):
27 self.out1.write()
28 self.out2.write()
29 self.out3.write()
30
31 def mainLoop(self):
32 sys.stdout.flush()
33
34 self.setCurrentVersionNumber(ac.VersionNumber())
35 self.out1.write()
36 self.out3.write()
37 self.out2.write()
38
39 self.setCurrentVersionNumber(ac.VersionNumber())
40 self.out1.write()
41 self.out3.write()
42 self.setCurrentVersionNumber(ac.VersionNumber())
43 self.out2.write()
44
45 # for last part of test, with MatchingMode.historized
46 self.out2.write()
47 self.out1.write()
48
49
50class Receiver(ac.ApplicationModule):
51
52 def __init__(self, owner, name, description):
53 super().__init__(owner, name, description)
54
55 self.in1 = ac.ScalarPushInput(ac.DataType.int32, self, "in1", "", "")
56 self.in2 = ac.ScalarPushInput(ac.DataType.int32, self, "in2", "", "")
57 self.in3 = ac.ScalarPushInput(ac.DataType.int32, self, "in3", "", "")
58
59 self.letsStart = ac.ScalarOutput(ac.DataType.int32, self, "letsStart", "", "")
60
61 self.testError = ac.ScalarOutput(ac.DataType.string, self, "testError", "", "")
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 change = rag.readAny()
86 isValid = dg.update(change)
87 assert not isValid
88 change = rag.readAny()
89 isValid = dg.update(change)
90 assert not isValid
91 change = rag.readAny()
92 isValid = dg.update(change)
93 assert not isValid
94
95 # Note, it is fine to create a DataConsistencyGroup with MatchingMode.historized after MatchingMode.exact,
96 # but the other way round would not be valid.
97 dgh = ac.DataConsistencyGroup(self.in1, self.in2, mode=ac.MatchingMode.historized, histLen=1)
98 change = rag.readAny()
99 isValid = dgh.update(change)
100 assert isValid
101
102 self.testError.setAndWrite("ok")
103
104 except AssertionError as e:
105 print("Exception: " + "\n".join(traceback.format_exception(e)))
106 sys.stdout.flush()
107 self.testError.setAndWrite("\n".join(traceback.format_exception(e)))
108
109
110ac.app.sender = Sender(ac.app, "UserModule", "")
111ac.app.receiver = Receiver(ac.app, "UserModule", "")
void mainLoop() override