ChimeraTK-ApplicationCore 04.06.00
Loading...
Searching...
No Matches
testPythonVariableGroup.py
Go to the documentation of this file.
1#!/usr/bin/python3
2
3import sys
4import os
5import os.path
6import traceback
7
8# fmt: off
9# Hack to insert the python path for the locally compiled module in the
10# test script
11sys.path.insert(0, os.path.abspath(os.path.join(os.curdir, "..")))
12import PyApplicationCore as ac # NOQA
13# fmt: on
14
15
16class MyMod(ac.ApplicationModule):
17
18 class VG2(ac.VariableGroup):
19 def __init__(self, owner, name, description):
20 super().__init__(owner, name, description)
21 self.out2 = ac.ArrayOutput(ac.DataType.int32, self, "out2", "unit", 2,"")
22
23 self.vg3 = ac.VariableGroup(self, "VG3", "inner VG")
24 self.vg3.out3 = ac.ArrayOutput(ac.DataType.int32, self.vg3, "out3", "unit", 2,"")
25
26 def __init__(self, owner, name, description):
27 super().__init__(owner, name, description)
28
29 self.vg = ac.VariableGroup(self, "VG", "VG using dynamic attributes")
30 self.vg.in1 = ac.ArrayPushInput(ac.DataType.int32, self.vg, "in1", "unit", 2, "description")
31 self.vg.out1 = ac.ScalarOutput(ac.DataType.int32, self.vg, "out1", "", "")
32
33 self.vg2 = MyMod.VG2(self, "VG2", "VG subclassed by user")
34
35 self.testError = ac.ScalarOutput(ac.DataType.string, self, "testError", "", "")
36
37 def mainLoop(self):
38 rag = self.vg.readAnyGroup() # just to test that ReadAnyGroup of VariableGroup is available
39
40 self.vg.out1.setAndWrite(1)
41
42 while True:
43 rag.readUntil(self.vg.in1)
44 in1val = self.vg.in1.get()
45 self.vg2.out2.set(in1val)
46 self.vg2.out2.write()
47 self.vg2.vg3.out3.set(in1val)
48 self.vg2.vg3.out3.write()
49
50 try:
51 ok = (in1val[0] != 0)
52 assert ok, "check input value"
53
54 # just check that readAll/writeAll functions exist, check with/without default args
55 # using writeAll as example, also check that these functions are available on the ApplicationModule (derives from VariableGroup)
56 self.writeAll(True)
57 self.writeAllDestructively()
58 # note, vg2.readAll ist allowed while vg.readAll is not since we already access vg's element via ReadyAnyGroup
59 # actually vg2 has no inputs but we don't care here
60 self.vg2.readAllNonBlocking()
61 self.vg2.readAllLatest()
62 self.vg2.readAll(True)
63
64 except AssertionError as e:
65 self.testError.setAndWrite("\n".join(traceback.format_exception(e)))
66
67
68ac.app.userModule = MyMod(ac.app, "UserModule", "module for testing of VariableGroup bindings")
69ac.app.someGroup = ac.ModuleGroup(ac.app, "SomeGroup", "Need to test ModuleGroups as well")
70ac.app.someGroup.userModule = MyMod(ac.app.someGroup, "UserModuleInGroup", "Inside ModuleGroup")
__init__(self, owner, name, description)
__init__(self, owner, name, description)
void mainLoop() override