Browse Source

app for unit-testing initialized

master
Ulrich Carmesin 2 years ago
parent
commit
342520aa91
  1. 23
      basic/catalog.py
  2. 19
      basic/componentHandling.py
  3. 2
      basic/constants.py
  4. 8
      basic/program.py
  5. 1
      test/constants.py
  6. 45
      test/test_component.py
  7. 6
      test/test_config.py
  8. 6
      test/testtools.py
  9. 0
      utils/file_abstract.py
  10. 2
      utils/path_const.py
  11. 0
      utils/xml1_tool.py

23
basic/catalog.py

@ -8,6 +8,9 @@ import os
import basic.program import basic.program
import basic.constants as B import basic.constants as B
import utils.path_const as P import utils.path_const as P
import utils.data_const as D
import utils.path_tool
import utils.tdata_tool
EXP_KEY_MISSING = "key is missing {}" EXP_KEY_MISSING = "key is missing {}"
EXP_KEY_DOESNT_EXIST = "key doesnt exist in domain {}" EXP_KEY_DOESNT_EXIST = "key doesnt exist in domain {}"
@ -20,21 +23,23 @@ class Catalog:
* initially the csv-file catalog.csv * initially the csv-file catalog.csv
* on demand other csv-files in the path * on demand other csv-files in the path
""" """
def __init__(self): def __init__(self):
self.catalog = {} self.catalog = {}
Catalog.__instance = self Catalog.__instance = self
pass pass
@staticmethod @staticmethod
def getInstance(): def getInstance():
if Catalog.__instance == None: if Catalog.__instance == None:
return Catalog() return Catalog()
return Catalog.__instance return Catalog.__instance
def getValue(self, domain, key): def getValue(self, domain, key):
""" """
this function gets the value of the domain an key this function gets the value of the domain an key
:param domain: :param domain:
:param key: :param key:
:return: :return:
@ -51,12 +56,26 @@ class Catalog:
raise Exception(EXP_KEY_DOESNT_EXIST, (domain, key)) raise Exception(EXP_KEY_DOESNT_EXIST, (domain, key))
return self.catalog[domain][key] return self.catalog[domain][key]
def readDomain(self, domain): def readDomain(self, domain):
""" """
this function reads the domain-entries
:param domain: :param domain:
:return: :return:
""" """
job = basic.program.Job.getInstance() job = basic.program.Job.getInstance()
if not (isinstance(domain, str) and len(domain)): if not (isinstance(domain, str) and len(domain)):
raise Exception(EXP_KEY_MISSING, (domain)) raise Exception(EXP_KEY_MISSING, (domain))
if domain in self.catalog:
return
filename = utils.path_tool.rejoinPath(job.conf.getPath(P.ATTR_PATH_TDATA), "catalog", domain+".csv")
data = utils.tdata_tool.getCsvSpec(job.m, filename, D.CSV_SPECTYPE_KEYS)
self.catalog[domain] = data[B.DATA_NODE_TABLES][domain][B.DATA_NODE_KEYS]
def exportXSD(self, domain):
"""
this function exports the domain into xsd-declaration of simple types
:return:
"""
pass

19
basic/componentHandling.py

@ -81,10 +81,10 @@ class ComponentManager:
job = basic.program.Job.getInstance() job = basic.program.Job.getInstance()
anw = job.par.application anw = job.par.application
job.m.logDebug("applicationscomponente -- " + str(type(job.par))) job.m.logDebug("applicationscomponente -- " + str(type(job.par)))
if not job.conf.confs["applicationen"].get(anw): if not job.conf.confs[B.SUBJECT_APPS].get(anw):
job.m.setFatal("application " + job.par.application + " is not configured") job.m.setFatal("application " + job.par.application + " is not configured")
return return
for k in job.conf.confs["applicationen"].get(anw): for k in job.conf.confs[B.SUBJECT_APPS].get(anw):
job.m.logDebug("applicationscomponente -- " + k + ":") job.m.logDebug("applicationscomponente -- " + k + ":")
self.createComponent(k, 0, "") self.createComponent(k, 0, "")
@ -205,6 +205,8 @@ class ComponentManager:
conf = utils.config_tool.getConfig("DATASTRUCTURE", c.name, table) conf = utils.config_tool.getConfig("DATASTRUCTURE", c.name, table)
if B.DATA_NODE_TABLES in conf and table in conf[B.DATA_NODE_TABLES]: if B.DATA_NODE_TABLES in conf and table in conf[B.DATA_NODE_TABLES]:
c.conf[B.DATA_NODE_DDL][table] = conf[B.DATA_NODE_TABLES][table] c.conf[B.DATA_NODE_DDL][table] = conf[B.DATA_NODE_TABLES][table]
elif table in conf:
c.conf[B.DATA_NODE_DDL][table] = conf[table]
else: else:
c.conf[B.DATA_NODE_DDL][table] = conf c.conf[B.DATA_NODE_DDL][table] = conf
comps[name] = c comps[name] = c
@ -222,6 +224,19 @@ class ComponentManager:
self.createComponent(c, nr, suffix) self.createComponent(c, nr, suffix)
def getComponentDict(self):
job = basic.program.Job.getInstance()
verify = -2 + job.getDebugLevel("job_tool")
job.debug(verify, "getComponents ")
out = {}
for c in self.comps:
out[self.comps[c].name] = {}
for k in self.comps[c].conf.keys():
if isParameterSubnode(k): # B.SUBJECT_ARTS in k or "components" in k or "instance" in k:
out[self.comps[c].name][k] = copy.deepcopy(self.comps[c].conf[k])
return out
def getComponentFolder(comp): def getComponentFolder(comp):
return comp.lower() return comp.lower()

2
basic/constants.py

@ -165,7 +165,7 @@ ATTR_PATH_TDATA = "testdata"
ATTR_PATH_PATTN = "pattern" ATTR_PATH_PATTN = "pattern"
""" This constant defines the debug-folder in testing-filesystem """ """ This constant defines the debug-folder in testing-filesystem """
#SUBJECT_APPS = "applications" # | x | | | | CompHandling SUBJECT_APPS = "applications" # | x | | | | CompHandling
SUBJECT_INST = "instance" # | | | | x | CompHanlding SUBJECT_INST = "instance" # | | | | x | CompHanlding
ATTR_INST_CNT = "count" # | | | | x | CompHanlding ATTR_INST_CNT = "count" # | | | | x | CompHanlding

8
basic/program.py

@ -368,11 +368,11 @@ class Parameter:
# args = str(sys.argv) # args = str(sys.argv)
# print ("Job-Programm %s : " % args) # print ("Job-Programm %s : " % args)
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument('-a', '--application', required=True, action='store') parser.add_argument('-a', '--'+B.SUBJECT_APPS, required=True, action='store')
parser.add_argument('-e', '--environment', required=True, action='store') parser.add_argument('-e', '--'+B.PAR_ENV, required=True, action='store')
parser.add_argument('-r', '--release', action='store') parser.add_argument('-r', '--release', action='store')
parser.add_argument('-ts', '--tsdir', action='store') parser.add_argument('-ts', '--'+B.PAR_TSDIR, action='store')
parser.add_argument('-tc', '--tcdir', action='store') parser.add_argument('-tc', '--'+B.PAR_TCDIR, action='store')
parser.add_argument('-rs', '--rsdir', action='store') parser.add_argument('-rs', '--rsdir', action='store')
parser.add_argument('-dt', '--tdtyp', action='store') # PAR_TDTYP parser.add_argument('-dt', '--tdtyp', action='store') # PAR_TDTYP
parser.add_argument('-ds', '--tdsrc', action='store') # PAR_TDSRC parser.add_argument('-ds', '--tdsrc', action='store') # PAR_TDSRC

1
test/constants.py

@ -1,3 +1,4 @@
HOME_PATH = "/home/ulrich/6_Projekte/Programme/datest" HOME_PATH = "/home/ulrich/6_Projekte/Programme/datest"
DATA_PATH = "/home/ulrich/6_Projekte/Programme/data" DATA_PATH = "/home/ulrich/6_Projekte/Programme/data"
COMP_PATH = "/home/ulrich/6_Projekte/Programme/data/components"
OS_SYSTEM = "linux" OS_SYSTEM = "linux"

45
test/test_component.py

@ -18,7 +18,7 @@ conf = {}
# here you can select single testfunction for developping the tests # here you can select single testfunction for developping the tests
TEST_FUNCTIONS = ["test_10actHandler", "test_21createInstance", "test_22createComponent", TEST_FUNCTIONS = ["test_10actHandler", "test_21createInstance", "test_22createComponent",
"test_23getComponents", "test_24getComponent"] "test_23getComponents", "test_24getComponent"]
#TEST_FUNCTIONS = ["test_formatDbRows"] TEST_FUNCTIONS = ["test_24getComponent"]
class MyTestCase(unittest.TestCase): class MyTestCase(unittest.TestCase):
mymsg = "--------------------------------------------------------------" mymsg = "--------------------------------------------------------------"
@ -32,18 +32,18 @@ class MyTestCase(unittest.TestCase):
return return
job = test.testtools.getJob() job = test.testtools.getJob()
cm = basic.componentHandling.ComponentManager() cm = basic.componentHandling.ComponentManager()
cm.createComponent("testa21", 0, "") cm.createComponent("testpoldb", 0, "")
self.assertIn("testa21", cm.comps, "component must be stored") self.assertIn("testpoldb", cm.comps, "component must be stored")
self.assertEqual(len(cm.comps), 1, "component without subcomponents") self.assertEqual(len(cm.comps), 1, "component without subcomponents")
cnttest += 2 cnttest += 2
cm.createComponent("testa1", 0, "") cm.createComponent("testprd", 0, "")
self.assertIn("testa1", cm.comps, "component must be stored") self.assertIn("testprd", cm.comps, "component must be stored")
self.assertIn("testa11", cm.comps, "subcomponent must be stored") self.assertIn("testprddb", cm.comps, "subcomponent must be stored")
self.assertEqual(len(cm.comps), 3, "2 component with 1 subcomponents") self.assertEqual(len(cm.comps), 3, "2 component with 1 subcomponents")
cnttest += 2 cnttest += 2
cm.createComponent("testa", 0, "") cm.createComponent("testcm", 0, "")
self.assertIn("testa_01", cm.comps, "multiple component must be stored") self.assertIn("testcm_01", cm.comps, "multiple component must be stored")
self.assertIn("testa_02", cm.comps, "multiple component must be stored") self.assertIn("testcm_02", cm.comps, "multiple component must be stored")
self.assertEqual(len(cm.comps), 6, "2 component with 2 subcomponents and 2 sub-subcomponents") self.assertEqual(len(cm.comps), 6, "2 component with 2 subcomponents and 2 sub-subcomponents")
cnttest += 2 cnttest += 2
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest) MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)
@ -57,23 +57,23 @@ class MyTestCase(unittest.TestCase):
return return
job = test.testtools.getJob() job = test.testtools.getJob()
cm = basic.componentHandling.ComponentManager.getInstance("J") cm = basic.componentHandling.ComponentManager.getInstance("J")
componentName = "testa" componentName = "testcm"
confs = utils.config_tool.getConfig("comp", componentName) confs = utils.config_tool.getConfig("comp", componentName)
conns = utils.conn_tool.getConnections(componentName) conns = utils.conn_tool.getConnections(componentName)
c = cm.createInstance(componentName, None, confs, conns, 1) c = cm.createInstance(componentName, None, confs, conns, 1)
self.assertEqual(hasattr(c, "conf"), True, "cinfig-dict must be") self.assertEqual(hasattr(c, "conf"), True, "cinfig-dict must be")
self.assertEqual(hasattr(c, "m"), True, "message-object must be") self.assertEqual(hasattr(c, "m"), True, "message-object must be")
self.assertEqual(c.name, "testa_01", "classname with number") # classname with number self.assertEqual(c.name, "testcm_01", "classname with number") # classname with number
cnttest += 3 cnttest += 3
self.assertEqual(c.conf[B.SUBJECT_INST][B.ATTR_INST_CNT], 2, "conn-attribute overwrites config-attribute") self.assertEqual(c.conf[B.SUBJECT_INST][B.ATTR_INST_CNT], 2, "conn-attribute overwrites config-attribute")
cnttest += 1 # it overwrites cnttest += 1 # it overwrites
self.assertEqual(c.conf[B.SUBJECT_INST][B.ATTR_INST_SGL], "n", "without conn-attribute the config-attribute keeps") self.assertEqual(c.conf[B.SUBJECT_INST][B.ATTR_INST_SGL], "n", "without conn-attribute the config-attribute keeps")
cnttest += 1 # it keep cnttest += 1 # it keep
componentName = "testa1" componentName = "testprddb"
confs = utils.config_tool.getConfig("comp", componentName) confs = utils.config_tool.getConfig("comp", componentName)
conns = utils.conn_tool.getConnections(componentName) conns = utils.conn_tool.getConnections(componentName)
c = cm.createInstance(componentName, None, confs, conns, 0) c = cm.createInstance(componentName, None, confs, conns, 0)
self.assertEqual(c.name, "testa1") self.assertEqual(c.name, "testprddb")
self.assertIn(B.ATTR_DB_TYPE, c.conf[B.SUBJECT_ARTS][B.TOPIC_NODE_DB], "conn-attribute creates missing config-attribute") 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 cnttest += 2 # new attributes
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest) MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)
@ -101,13 +101,14 @@ class MyTestCase(unittest.TestCase):
return return
job = test.testtools.getJob() job = test.testtools.getJob()
cm = basic.componentHandling.ComponentManager() cm = basic.componentHandling.ComponentManager()
cm.createComponent("testa", 0, "") cm.createComponent("testcm", 0, "")
cm.createComponent("testcrm", 0, "")
prog = "init_testcase" prog = "init_testcase"
comps = cm.getComponents(prog) comps = cm.getComponents(prog)
self.assertEqual(len(comps), 5, "not all created comps for program "+prog) self.assertEqual(len(comps), 7, "not all created comps for program "+prog)
prog = "finish_testcase" prog = "check_environment"
comps = cm.getComponents(prog) comps = cm.getComponents(prog)
self.assertEqual(len(comps), 6, "all created comps for program "+prog) self.assertEqual(len(comps), 8, "all created comps for program "+prog)
cnttest += 2 cnttest += 2
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest) MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)
@ -120,15 +121,15 @@ class MyTestCase(unittest.TestCase):
return return
job = test.testtools.getJob() job = test.testtools.getJob()
cm = basic.componentHandling.ComponentManager() cm = basic.componentHandling.ComponentManager()
cm.createComponent("testa", 0, "") cm.createComponent("testcm", 0, "")
self.assertEqual(len(cm.comps), 6, "6 components inside") self.assertEqual(len(cm.comps), 6, "6 components inside")
comp = cm.getComponent("testa1") comp = cm.getComponent("testprd")
self.assertEqual(len(cm.comps), 6, "6 components inside") self.assertEqual(len(cm.comps), 6, "6 components inside")
self.assertEqual(comp.name, "testa1", "component found") self.assertEqual(comp.name, "testprd", "component found")
cnttest += 2 cnttest += 2
comp = cm.getComponent("testb1") comp = cm.getComponent("testcrm")
self.assertEqual(len(cm.comps), 6, "6 components inside and nothing added") self.assertEqual(len(cm.comps), 6, "6 components inside and nothing added")
self.assertIsNotNone("terstb1") self.assertIsNotNone("terstcrm")
cnttest += 2 cnttest += 2
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest) MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)

6
test/test_config.py

@ -33,8 +33,8 @@ class MyTestCase(unittest.TestCase):
self.assertRaises(Exception, utils.config_tool.getConfigPath, (P.KEY_COMP, "TestX2")) self.assertRaises(Exception, utils.config_tool.getConfigPath, (P.KEY_COMP, "TestX2"))
# self.assertEqual(r, None) # self.assertEqual(r, None)
cnttest += 1 cnttest += 1
r = utils.config_tool.getConfigPath(P.KEY_COMP, "testA2") r = utils.config_tool.getConfigPath(P.KEY_COMP, "testcrm")
self.assertIn(os.path.join(job.conf.getPath(P.ATTR_PATH_PROGRAM), P.VAL_COMPS, "testa2", "CONFIG"), r) self.assertIn(os.path.join(job.conf.getPath(P.ATTR_PATH_COMPONENTS), "testcrm", "CONFIG"), r)
r = utils.config_tool.getConfig(P.KEY_TOOL, "path") r = utils.config_tool.getConfig(P.KEY_TOOL, "path")
if VERIFY: print("pattern " + r["pattern"]["log"]) if VERIFY: print("pattern " + r["pattern"]["log"])
if VERIFY: print("pattern " + r["pattern"]["precond"]) if VERIFY: print("pattern " + r["pattern"]["precond"])
@ -45,7 +45,7 @@ class MyTestCase(unittest.TestCase):
global mymsg global mymsg
actfunction = str(inspect.currentframe().f_code.co_name) actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0 cnttest = 0
if actfunction not in TEST_FUNCTIONS: if actfunction not in TEST_FUNCTIONS or True:
return return
job = test.testtools.getJob() job = test.testtools.getJob()
componentName = "testa" componentName = "testa"

6
test/testtools.py

@ -2,11 +2,12 @@ import basic.program
import basic.constants as B import basic.constants as B
import basic.component import basic.component
import utils.data_const as D import utils.data_const as D
import test.constants as T
DEFAULT_GRAN = "tc" DEFAULT_GRAN = "tc"
DEFAULT_APP = "TEST" DEFAULT_APP = "TESTAPP"
DEFAULT_ENV = "ENV01" DEFAULT_ENV = "ENV01"
DEFAULT_DIR = "/home/ulrich/6_Projekte/Programme/datest/test/conf/lauf" DEFAULT_DIR = T.DATA_PATH + "/tdata"
DEFAULT_TIME = "2022-03-19_12-09-09" DEFAULT_TIME = "2022-03-19_12-09-09"
DEFAULT_MODE = "unit" DEFAULT_MODE = "unit"
gran = "" gran = ""
@ -71,6 +72,7 @@ def getJob(pgran="", papp="", penv="", ptstamp="", pmode=""):
elif gran == "ts": elif gran == "ts":
path = DEFAULT_DIR + "/testlauf/TST001_" + tstamp path = DEFAULT_DIR + "/testlauf/TST001_" + tstamp
job = basic.program.Job("unit") job = basic.program.Job("unit")
job.conf.confs[B.SUBJECT_PATH]["components"] = T.COMP_PATH
args = {"application": app, "environment": env, "modus": mode, gran+"time": tstamp, args = {"application": app, "environment": env, "modus": mode, gran+"time": tstamp,
gran+"dir": path, gran+"dir": path,
"step": 2} "step": 2}

0
utils/file_abstract.py

2
utils/path_const.py

@ -62,6 +62,8 @@ ATTR_PATH_ARCHIV = "archiv"
""" This constant defines the folder in testing-filesystem for results and log of execution """ """ This constant defines the folder in testing-filesystem for results and log of execution """
ATTR_PATH_PROGRAM = "program" ATTR_PATH_PROGRAM = "program"
""" This constant defines the program-folder in the workspace """ """ This constant defines the program-folder in the workspace """
ATTR_PATH_COMPONENTS = "components"
""" This constant defines the program-folder in the workspace """
ATTR_PATH_ENV = "environment" ATTR_PATH_ENV = "environment"
""" This constant defines the folder in testing-filesystem, used for configs related to environments """ """ This constant defines the folder in testing-filesystem, used for configs related to environments """
ATTR_PATH_RELEASE = "release" ATTR_PATH_RELEASE = "release"

0
utils/xml_tool.py → utils/xml1_tool.py

Loading…
Cancel
Save