import unittest import os import inspect import utils.config_tool import utils.conn_tool import test.constants import test.testtools import utils.path_const as P import basic.constants as B HOME_PATH = test.constants.HOME_PATH TEST_FUNCTIONS = ["test_getConfig", "test_mergeAttributes"] VERIFY = False class MyTestCase(unittest.TestCase): mymsg = "--------------------------------------------------------------" def test_getConfig(self): global mymsg actfunction = str(inspect.currentframe().f_code.co_name) cnttest = 0 if actfunction not in TEST_FUNCTIONS: return job = test.testtools.getJob() x = "path" r = utils.config_tool.getConfigPath(P.KEY_TOOL, x) self.assertIn(os.path.join(HOME_PATH, P.VAL_UTIL, P.VAL_CONFIG), r) cnttest += 1 x = "conn" r = utils.config_tool.getConfigPath(P.KEY_TOOL, x) self.assertIn(os.path.join(job.conf.getPath(P.ATTR_PATH_ENV)), r) cnttest += 1 self.assertRaises(Exception, utils.config_tool.getConfigPath, (P.KEY_COMP, "TestX2")) # self.assertEqual(r, None) cnttest += 1 r = utils.config_tool.getConfigPath(P.KEY_COMP, "testA2") self.assertIn(os.path.join(job.conf.getPath(P.ATTR_PATH_PROGRAM), P.VAL_COMPS, "testa2", "CONFIG"), r) r = utils.config_tool.getConfig(P.KEY_TOOL, "path") if VERIFY: print("pattern " + r["pattern"]["log"]) if VERIFY: print("pattern " + r["pattern"]["precond"]) MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest) def test_mergeAttributes(self): global mymsg actfunction = str(inspect.currentframe().f_code.co_name) cnttest = 0 if actfunction not in TEST_FUNCTIONS: return job = test.testtools.getJob() componentName = "testa" confs = utils.config_tool.getConfig("comp", componentName) conns = utils.conn_tool.getConnections(componentName) self.assertEqual(confs["conf"][B.SUBJECT_INST][B.ATTR_INST_CNT], 1) self.assertEqual(conns[0][B.SUBJECT_INST][B.ATTR_INST_CNT], 2) self.assertNotIn(B.ATTR_INST_SGL, conns[0][B.SUBJECT_INST]) confs["conf"] = utils.config_tool.mergeConn(job.m, confs["conf"], conns[0]) self.assertEqual(confs["conf"][B.SUBJECT_INST][B.ATTR_INST_CNT], 2) cnttest += 1 # it overwrites self.assertEqual(confs["conf"][B.SUBJECT_INST][B.ATTR_INST_SGL], "n") cnttest += 1 # it keep componentName = "testa1" confs = utils.config_tool.getConfig("comp", componentName) conns = utils.conn_tool.getConnections(componentName) self.assertNotIn(B.ATTR_DB_TYPE, confs["conf"][B.SUBJECT_ARTS][B.TOPIC_NODE_DB]) confs["conf"] = utils.config_tool.mergeConn(job.m, confs["conf"], conns[0]) self.assertIn(B.ATTR_DB_TYPE, confs["conf"][B.SUBJECT_ARTS][B.TOPIC_NODE_DB]) cnttest += 1 # new attribute MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest) def test_getAttributes(self): global mymsg actfunction = str(inspect.currentframe().f_code.co_name) cnttest = 0 if actfunction not in TEST_FUNCTIONS: return job = test.testtools.getJob() MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest) def test_zzz(self): print(MyTestCase.mymsg) if __name__ == '__main__': VERIFY = True unittest.main()