Ulrich Carmesin
2 years ago
3 changed files with 166 additions and 11 deletions
@ -0,0 +1,141 @@ |
|||
import unittest |
|||
import inspect |
|||
import basic.program |
|||
import utils.path_tool |
|||
import basic.componentHandling |
|||
import test.constants |
|||
import basic.component |
|||
import basic.constants as B |
|||
import utils.db_abstract |
|||
import test.testtools |
|||
import utils.config_tool |
|||
import utils.conn_tool |
|||
|
|||
HOME_PATH = test.constants.HOME_PATH |
|||
DATA_PATH = test.constants.DATA_PATH |
|||
|
|||
conf = {} |
|||
# here you can select single testfunction for developping the tests |
|||
TEST_FUNCTIONS = ["test_10actHandler", "test_21createInstance", "test_22createComponent", |
|||
"test_23getComponents", "test_24getComponent"] |
|||
#TEST_FUNCTIONS = ["test_formatDbRows"] |
|||
|
|||
class MyTestCase(unittest.TestCase): |
|||
mymsg = "--------------------------------------------------------------" |
|||
|
|||
|
|||
def test_22createComponent(self): |
|||
global mymsg |
|||
actfunction = str(inspect.currentframe().f_code.co_name) |
|||
cnttest = 0 |
|||
if actfunction not in TEST_FUNCTIONS: |
|||
return |
|||
job = test.testtools.getJob() |
|||
cm = basic.componentHandling.ComponentManager() |
|||
cm.createComponent("testa21", 0, "") |
|||
self.assertIn("testa21", cm.comps, "component must be stored") |
|||
self.assertEqual(len(cm.comps), 1, "component without subcomponents") |
|||
cnttest += 2 |
|||
cm.createComponent("testa1", 0, "") |
|||
self.assertIn("testa1", cm.comps, "component must be stored") |
|||
self.assertIn("testa11", cm.comps, "subcomponent must be stored") |
|||
self.assertEqual(len(cm.comps), 3, "2 component with 1 subcomponents") |
|||
cnttest += 2 |
|||
cm.createComponent("testa", 0, "") |
|||
self.assertIn("testa_01", cm.comps, "multiple component must be stored") |
|||
self.assertIn("testa_02", cm.comps, "multiple component must be stored") |
|||
self.assertEqual(len(cm.comps), 6, "2 component with 2 subcomponents and 2 sub-subcomponents") |
|||
cnttest += 2 |
|||
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest) |
|||
|
|||
|
|||
def test_21createInstance(self): |
|||
global mymsg |
|||
actfunction = str(inspect.currentframe().f_code.co_name) |
|||
cnttest = 0 |
|||
if actfunction not in TEST_FUNCTIONS: |
|||
return |
|||
job = test.testtools.getJob() |
|||
cm = basic.componentHandling.ComponentManager.getInstance("J") |
|||
componentName = "testa" |
|||
confs = utils.config_tool.getConfig("comp", componentName) |
|||
conns = utils.conn_tool.getConnections(componentName) |
|||
c = cm.createInstance(componentName, None, confs, conns, 1) |
|||
self.assertEqual(hasattr(c, "conf"), True, "cinfig-dict must be") |
|||
self.assertEqual(hasattr(c, "m"), True, "message-object must be") |
|||
self.assertEqual(c.name, "testa_01", "classname with number") # classname with number |
|||
cnttest += 3 |
|||
self.assertEqual(c.conf[B.SUBJECT_INST][B.ATTR_INST_CNT], 2, "conn-attribute overwrites config-attribute") |
|||
cnttest += 1 # it overwrites |
|||
self.assertEqual(c.conf[B.SUBJECT_INST][B.ATTR_INST_SGL], "n", "without conn-attribute the config-attribute keeps") |
|||
cnttest += 1 # it keep |
|||
componentName = "testa1" |
|||
confs = utils.config_tool.getConfig("comp", componentName) |
|||
conns = utils.conn_tool.getConnections(componentName) |
|||
c = cm.createInstance(componentName, None, confs, conns, 0) |
|||
self.assertEqual(c.name, "testa1") |
|||
self.assertIn(B.ATTR_DB_TYPE, c.conf[B.SUBJECT_ARTS][B.TOPIC_NODE_DB], "conn-attribute creates missing config-attribute") |
|||
cnttest += 2 # new attributes |
|||
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest) |
|||
|
|||
|
|||
def test_10actHandler(self): |
|||
global mymsg |
|||
actfunction = str(inspect.currentframe().f_code.co_name) |
|||
cnttest = 0 |
|||
if actfunction not in TEST_FUNCTIONS: |
|||
return |
|||
job = test.testtools.getJob() |
|||
cm = basic.componentHandling.ComponentManager.getInstance("J") |
|||
self.assertIsNotNone(cm) |
|||
self.assertEqual(len(cm.components), 0) |
|||
cnttest += 2 |
|||
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest) |
|||
|
|||
|
|||
def test_23getComponents(self): |
|||
global mymsg |
|||
actfunction = str(inspect.currentframe().f_code.co_name) |
|||
cnttest = 0 |
|||
if actfunction not in TEST_FUNCTIONS: |
|||
return |
|||
job = test.testtools.getJob() |
|||
cm = basic.componentHandling.ComponentManager() |
|||
cm.createComponent("testa", 0, "") |
|||
prog = "init_testcase" |
|||
comps = cm.getComponents(prog) |
|||
self.assertEqual(len(comps), 5, "not all created comps for program "+prog) |
|||
prog = "finish_testcase" |
|||
comps = cm.getComponents(prog) |
|||
self.assertEqual(len(comps), 6, "all created comps for program "+prog) |
|||
cnttest += 2 |
|||
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest) |
|||
|
|||
|
|||
def test_24getComponent(self): |
|||
global mymsg |
|||
actfunction = str(inspect.currentframe().f_code.co_name) |
|||
cnttest = 0 |
|||
if actfunction not in TEST_FUNCTIONS: |
|||
return |
|||
job = test.testtools.getJob() |
|||
cm = basic.componentHandling.ComponentManager() |
|||
cm.createComponent("testa", 0, "") |
|||
self.assertEqual(len(cm.comps), 6, "6 components inside") |
|||
comp = cm.getComponent("testa1") |
|||
self.assertEqual(len(cm.comps), 6, "6 components inside") |
|||
self.assertEqual(comp.name, "testa1", "component found") |
|||
cnttest += 2 |
|||
comp = cm.getComponent("testb1") |
|||
self.assertEqual(len(cm.comps), 6, "6 components inside and nothing added") |
|||
self.assertIsNotNone("terstb1") |
|||
cnttest += 2 |
|||
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest) |
|||
|
|||
|
|||
def test_zzz(self): |
|||
print(MyTestCase.mymsg) |
|||
|
|||
|
|||
if __name__ == '__main__': |
|||
unittest.main() |
Loading…
Reference in new issue