ChimeraTK-ApplicationCore 04.06.00
Loading...
Searching...
No Matches
testPythonAppConfig.py
Go to the documentation of this file.
1#!/usr/bin/python3
2
3import sys
4import os
5import os.path
6import traceback
7from numpy import testing as t
8
9# fmt: off
10# Hack to insert the python path for the locally compiled module in the
11# test script
12sys.path.insert(0, os.path.abspath(os.path.join(os.curdir, "..")))
13import PyApplicationCore as ac # NOQA
14# fmt: on
15
16
17class MyMod(ac.ApplicationModule):
18
19 def __init__(self, owner, name, description):
20 super().__init__(owner, name, description)
21
22 self.testError = ac.ScalarOutput(ac.DataType.string, self, "testError", "", "")
23
24 def mainLoop(self):
25 try:
26 config = self.appConfig()
27
28 # Getting scalars and arrays with default
29 assert (config.get(ac.DataType.string, "stringScalar") == "a string scalar")
30 assert (config.get(ac.DataType.string, "thisDoesNotExist", "a default") == "a default")
31
32 assert (config.getArray(ac.DataType.string, "stringArray") == ["a", "string", "array"])
33 assert (config.getArray(ac.DataType.string, "thisDoesNotExists", ["a", "default"]) == ["a", "default"])
34
35 # Some smoketest for type conversions
36
37 t.assert_allclose(config.get(ac.DataType.float32, "floatScalar"), 815.4711)
38 t.assert_allclose(config.get(
39 ac.DataType.float32, "thisDoesNotExist", 47.11), 47.11)
40
41 t.assert_allclose(config.getArray(ac.DataType.float32, "floatArray"),
42 [0.5, 0.6, 1.5, 1.6, 1.7, 1.8])
43 t.assert_allclose(config.getArray(ac.DataType.float32, "thisDoesNotExist",
44 [4.5, 4.6, 5.0]), [4.5, 4.6, 5.0])
45 except ac.LogicError as e:
46 self.testError.setAndWrite("\n".join(traceback.format_exception(e)))
47 except AssertionError as e:
48 self.testError.setAndWrite("\n".join(traceback.format_exception(e)))
49
50
51ac.app.userModule = MyMod(ac.app, "UserModule", "module for testing of appConfig bindings")
__init__(self, owner, name, description)
void mainLoop() override