diff --git a/basic/catalog.py b/basic/catalog.py index 0ee1f33..0ffe5f0 100644 --- a/basic/catalog.py +++ b/basic/catalog.py @@ -90,7 +90,7 @@ class Catalog: raise Exception(EXP_KEY_MISSING, (domain)) if domain in self.catalog: return - pathname = utils.config_tool.getConfigPath(P.KEY_CATALOG, domain, job) + pathname = utils.config_tool.getConfigPath(job, P.KEY_CATALOG, domain) if pathname is None: raise Exception(EXP_KEY_MISSING, (domain)) if pathname[-4:] == ".csv": diff --git a/basic/compexec.py b/basic/compexec.py index 420de1f..c2b9777 100644 --- a/basic/compexec.py +++ b/basic/compexec.py @@ -128,7 +128,7 @@ class Testexecuter(): """ #job = basic.program.Job.getInstance() verify = -1+job.getDebugLevel(self.name) - self.read_TData(job, utils.path_tool.getKeyValue(P.KEY_PRECOND), B.PAR_TESTCASE) + self.read_TData(job, utils.path_tool.getKeyValue(job, P.KEY_PRECOND), B.PAR_TESTCASE) def read_TData(self, job, subdir, granularity): """ @@ -202,7 +202,7 @@ class Testexecuter(): print("table "+table) sql_new = sql[0:sql.upper().index(" FROM ")+5] print("sql_new "+sql_new) - attr = utils.db_abstract.getDbAttributes(self, job, table) + attr = utils.db_abstract.getDbAttributes(self, table) if attr[B.ATTR_DB_TABNAME] != "": table = attr[B.ATTR_DB_TABNAME] if attr[B.ATTR_DB_SCHEMA] != "": @@ -351,7 +351,7 @@ class Testexecuter(): """ #job = basic.program.Job.getInstance() verify = job.getDebugLevel(self.name) - cm = basic.componentHandling.ComponentManager.getInstance() + cm = basic.componentHandling.ComponentManager.getInstance(job) data = {} matching = utils.match_tool.Matching(job, self) if B.TOPIC_NODE_DB in self.conf[B.SUBJECT_ARTS]: diff --git a/basic/componentHandling.py b/basic/componentHandling.py index f2ee633..b25f83b 100644 --- a/basic/componentHandling.py +++ b/basic/componentHandling.py @@ -63,6 +63,7 @@ def getComponents(job, mainfct): class ComponentManager: __instance = None + __instances = {} """ initializes the Manager with all necessary components """ @@ -73,6 +74,7 @@ class ComponentManager: self.components = {} self.comps = {} self.job = job + ComponentManager.__instances[job.jobid] = self ComponentManager.__instance = self print ("init ComponentHandling "+str(self)) @@ -117,13 +119,11 @@ class ComponentManager: @staticmethod - def getInstance(init="N"): - if (ComponentManager.__instance is not None): - return ComponentManager.__instance - elif (init != "N"): - return ComponentManager() + def getInstance(job, init="N"): + if (job.jobid in ComponentManager.__instances): + return ComponentManager.__instances[job.jobid] else: - raise Exception(B.EXCEPT_NOT_INITIALIZED) + return ComponentManager(job) def createComponent(self, componentName, nr, suffix): diff --git a/basic/message.py b/basic/message.py index 6189d84..42ebc0f 100644 --- a/basic/message.py +++ b/basic/message.py @@ -95,7 +95,7 @@ class Message: basedir = job.par.basedir basedir = basedir.replace("base", "log") # basedir = utils.path_tool.composePath(basedir, None) - basedir = utils.path_tool.composePath(basedir, None) + basedir = utils.path_tool.composePath(job, basedir, None) os.makedirs(basedir, exist_ok=True) logpath = os.path.join(basedir , job.program + "_" + logTime + ".txt") self.logDebug("logfile " + logpath) @@ -200,7 +200,7 @@ class Message: for i in range(0, len(T.LIST_EXP_TEXT)): if text == T.LIST_EXP_TEXT[i]: constName = T.LIST_EXP_CONST[i] - txt = utils.i18n_tool.I18n.getInstance().getMessage(self.job, constName, args) + txt = utils.i18n_tool.I18n.getInstance(job).getMessage(self.job, constName, args) out = txt.format(args) return out diff --git a/basic/program.py b/basic/program.py index e7fa783..9940fb2 100644 --- a/basic/program.py +++ b/basic/program.py @@ -185,9 +185,12 @@ def createJob(pprg="", pgran="", papp="", penv="", ptstamp="", pmode=""): class Job: __instance = None __instances = [] + __jobid = 100000 def __init__ (self, program): print ("################# init Job ## " + program + " #################") + Job.__jobid += 1 + self.jobid = str(Job.__jobid) self.program = program Job.__instance = self if Job.__instances is None: @@ -259,7 +262,7 @@ class Job: def dumpParameter(self): - parpath = utils.path_tool.composePath(jobdef[self.program]["pfiletarget"], None) + parpath = utils.path_tool.composePath(self, jobdef[self.program]["pfiletarget"], None) output = {} cconf = basic.componentHandling.getComponentDict() output["par"] = self.par.__dict__ @@ -282,7 +285,7 @@ class Job: output = {} if len(str(jobdef[self.program]["pfilesource"])) < 2: return None - parpath = utils.path_tool.composePath(jobdef[self.program]["pfilesource"], None) + parpath = utils.path_tool.composePath(self, jobdef[self.program]["pfilesource"], None) if not os.path.join(parpath): return None doc = utils.file_tool.readFileDict(self, parpath, self.m) @@ -460,7 +463,7 @@ class Parameter: self.setJobAttr(k , getattr(args, k)) dirpath = self.getDirParameter() if dirpath is not None: - utils.path_tool.extractPath(dirpath[0], dirpath[1]) + utils.path_tool.extractPath(job, dirpath[0], dirpath[1]) app = self.application if self.application in job.conf.confs[B.SUBJECT_APPS]: if B.ATTR_APPS_PROJECT in job.conf.confs[B.SUBJECT_APPS][self.application]: diff --git a/basic/step.py b/basic/step.py index ad5d057..e2b9be0 100644 --- a/basic/step.py +++ b/basic/step.py @@ -99,11 +99,11 @@ def parseStep(job, fields): def getStepHeader(job): text = "# " - text += utils.i18n_tool.I18n.getInstance().getText(f"{D.CSV_BLOCK_STEP=}", job) - text += ";"+utils.i18n_tool.I18n.getInstance().getText(f"{D.STEP_ATTR_COMP=}", job) - text += ";"+utils.i18n_tool.I18n.getInstance().getText(f"{D.STEP_ATTR_EXECNR=}", job) - text += ";"+utils.i18n_tool.I18n.getInstance().getText(f"{D.STEP_ATTR_REFNR=}", job) - text += ";"+utils.i18n_tool.I18n.getInstance().getText(f"{D.STEP_ATTR_ARGS=}", job) + text += utils.i18n_tool.I18n.getInstance(job).getText(f"{D.CSV_BLOCK_STEP=}", job) + text += ";"+utils.i18n_tool.I18n.getInstance(job).getText(f"{D.STEP_ATTR_COMP=}", job) + text += ";"+utils.i18n_tool.I18n.getInstance(job).getText(f"{D.STEP_ATTR_EXECNR=}", job) + text += ";"+utils.i18n_tool.I18n.getInstance(job).getText(f"{D.STEP_ATTR_REFNR=}", job) + text += ";"+utils.i18n_tool.I18n.getInstance(job).getText(f"{D.STEP_ATTR_ARGS=}", job) return text + ";..;;;\n" diff --git a/check_environment.py b/check_environment.py index 1a8ff40..a965e55 100644 --- a/check_environment.py +++ b/check_environment.py @@ -19,7 +19,7 @@ if __name__ == '__main__': exit(x.m.rc * (-1) + 3) # now in theory the program is runnable x.m.setMsg("# job initialized") - cm = basic.componentHandling.ComponentManager() + cm = basic.componentHandling.ComponentManager.getInstance(job) print("cm "+str(cm)) cm.initComponents() comps = cm.getComponents(x, PROGRAM_NAME) diff --git a/collect_testcase.py b/collect_testcase.py index fb51796..dcecc0b 100644 --- a/collect_testcase.py +++ b/collect_testcase.py @@ -16,7 +16,7 @@ import utils.tdata_tool PROGRAM_NAME = "collect_testcase" def startPyJob(job): - cm = basic.componentHandling.ComponentManager.getInstance("init") + cm = basic.componentHandling.ComponentManager.getInstance(job) cm.initComponents() comps = cm.getComponents(job, PROGRAM_NAME) print(" relevant components for this job: " + str(comps)) diff --git a/compare_testcase.py b/compare_testcase.py index db907c3..49e5a68 100644 --- a/compare_testcase.py +++ b/compare_testcase.py @@ -20,7 +20,7 @@ import basic.message as message PROGRAM_NAME = "compare_testcase" def startPyJob(job): - cm = basic.componentHandling.ComponentManager(job, "init") + cm = basic.componentHandling.ComponentManager.getInstance(job) print("cm "+str(cm)) cm.initComponents() comps = cm.getComponents(PROGRAM_NAME) diff --git a/declare_result.py b/declare_result.py index 60c239a..feccc50 100644 --- a/declare_result.py +++ b/declare_result.py @@ -26,7 +26,7 @@ if __name__ == '__main__': x.m.logInfo("hier eine LogInfo") x.m.logDebug("hier eine DbugMeldung") x.m.logDebug(str(vars(x.par)) + "\n" + str(vars(x.conf))) - cm = ComponentManager() + cm = ComponentManager.getInstance(x) if x.m.isRc("fatal"): x.stopJob() exit(x.m.rc * (-1) + 3) diff --git a/execute_testcase.py b/execute_testcase.py index 23cf495..00b543e 100644 --- a/execute_testcase.py +++ b/execute_testcase.py @@ -22,7 +22,7 @@ import basic.message as message PROGRAM_NAME = "execute_testcase" def startPyJob(job): - cm = basic.componentHandling.ComponentManager(job) + cm = basic.componentHandling.ComponentManager.getInstance(job) print("cm "+str(cm)) cm.initComponents() comps = cm.getComponents(PROGRAM_NAME) diff --git a/finish_testsuite.py b/finish_testsuite.py index a2efdf4..2784c6c 100644 --- a/finish_testsuite.py +++ b/finish_testsuite.py @@ -15,7 +15,7 @@ import utils.zip_tool PROGRAM_NAME = "finish_testsuite" def startPyJob(job): - cm = basic.componentHandling.ComponentManager.getInstance("init") + cm = basic.componentHandling(job) report = utils.report_tool.Report() testinstances = {} if hasattr(job.par, "testinstances"): diff --git a/init_testcase.py b/init_testcase.py index 4cfc600..d026423 100644 --- a/init_testcase.py +++ b/init_testcase.py @@ -19,7 +19,7 @@ import basic.message as message PROGRAM_NAME = "init_testcase" def startPyJob(job): - cm = basic.componentHandling.ComponentManager.getInstance(job, "init") + cm = basic.componentHandling.ComponentManager.getInstance(job) cm.initComponents() comps = cm.getComponents(PROGRAM_NAME) job.m.setMsg("# Components initialized with these relevant components " + str(comps)) @@ -33,7 +33,7 @@ def startPyJob(job): if job.hasFunction("load_TData"): comp.load_TData(job, B.PAR_TESTCASE, testdata) if job.hasFunction("read_TData"): - comp.read_TData(job, utils.path_tool.getKeyValue(P.KEY_PRECOND), B.PAR_TESTCASE) + comp.read_TData(job, utils.path_tool.getKeyValue(job, P.KEY_PRECOND), B.PAR_TESTCASE) comp.m.logInfo("------- "+comp.name+" ----------------------------------------") job.m.merge(comp.m) print(str(comp)) diff --git a/requirements.txt b/requirements.txt index 7740cd5..86cd2d9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,15 @@ -pyyaml -paramiko +pyyaml~=6.0 +paramiko~=2.9.2 + +cryptography~=36.0.1 +pip~=21.3.1 +MarkupSafe~=2.1.1 +Werkzeug~=2.2.2 +Jinja2~=3.1.2 +click~=8.1.3 +itsdangerous~=2.1.2 +setuptools~=60.5.0 +zipp~=3.8.1 +xmltodict~=0.12.0 +pyspark~=3.2.1 +Flask~=2.2.2 \ No newline at end of file diff --git a/test/test_03path.py b/test/test_03path.py index 4b1630d..9b06268 100644 --- a/test/test_03path.py +++ b/test/test_03path.py @@ -42,11 +42,11 @@ class MyTestCase(unittest.TestCase): if actfunction not in TEST_FUNCTIONS: return job = test.testtools.getJob() - res = utils.path_tool.getKeyValue("job.par."+B.PAR_ENV, None) + res = utils.path_tool.getKeyValue(job, "job.par."+B.PAR_ENV, None) self.assertEqual(res, test.testtools.DEFAULT_ENV) cnttest += 1 for par in [B.ATTR_PATH_ARCHIV, B.ATTR_PATH_ENV]: - res = utils.path_tool.getKeyValue("job.conf."+par, None) + res = utils.path_tool.getKeyValue(job, "job.conf."+par, None) if verbose: print("assertIn "+par+": "+res+" -- "+DATA_PATH) self.assertIn(DATA_PATH, res) cnttest += 1 @@ -80,16 +80,16 @@ class MyTestCase(unittest.TestCase): return # set the relevant datastrutures job = test.testtools.getJob() - comp = test.testtools.getComp(job) - pt = utils.path_tool.PathConf() + comp = test.testtools.getComp(job, "testrest") + pt = utils.path_tool.PathConf(job) self.setTestPaths(job) self.setPathConfig(pt) # tests - path = utils.path_tool.composePath(P.P_ENVBASE, None) + path = utils.path_tool.composePath(job, P.P_ENVBASE, None) self.assertIn(job.conf.confs[B.SUBJECT_PATH][B.ATTR_PATH_ENV], path) self.assertIn(getattr(job.par, B.PAR_ENV), path) cnttest += 2 - path = utils.path_tool.composePath(P.P_TCLOG, None) + path = utils.path_tool.composePath(job, P.P_TCLOG, None) self.assertIn(job.conf.confs[B.SUBJECT_PATH][B.ATTR_PATH_ARCHIV], path) self.assertIn(getattr(job.par, B.PAR_TESTCASE), path) cnttest += 2 @@ -105,7 +105,7 @@ class MyTestCase(unittest.TestCase): # set the relevant datastrutures job = test.testtools.getJob() comp = test.testtools.getComp(job) - pt = utils.path_tool.PathConf() + pt = utils.path_tool.PathConf(job) self.setTestPaths(job) self.setPathConfig(pt) # tests @@ -123,9 +123,9 @@ class MyTestCase(unittest.TestCase): if actfunction not in TEST_FUNCTIONS: return job = test.testtools.getJob() - pt = utils.path_tool.PathConf() + pt = utils.path_tool.PathConf(job) job = test.testtools.getJob("ts", test.testtools.DEFAULT_APP, test.testtools.DEFAULT_ENV, "2021-08-21_18-ß2-01") - r = utils.path_tool.extractPattern("tsbase" ) + r = utils.path_tool.extractPattern(job, "tsbase" ) self.assertEqual(r[0][1], "job.conf.archiv") self.assertEqual(r[1][1], P.KEY_TESTSUITE) self.assertEqual(r[1][2], "testlauf") @@ -140,8 +140,8 @@ class MyTestCase(unittest.TestCase): if actfunction not in TEST_FUNCTIONS: return job = test.testtools.getJob() - pt = utils.path_tool.PathConf() - r = utils.path_tool.extractPath("tsbase" , os.path.join(DATA_PATH, "lauf", "testlauf", "startjob_2021-08-21_10-02-01")) + pt = utils.path_tool.PathConf(job) + r = utils.path_tool.extractPath(job, "tsbase" , os.path.join(DATA_PATH, "lauf", "testlauf", "startjob_2021-08-21_10-02-01")) if verbose: print("r " + str(r)) self.assertEqual(job.par.usecase, "startjob") self.assertEqual(job.par.tstime, "2021-08-21_10-02-01") diff --git a/test/test_04config.py b/test/test_04config.py index 2e9098b..eb21235 100644 --- a/test/test_04config.py +++ b/test/test_04config.py @@ -32,21 +32,21 @@ class MyTestCase(unittest.TestCase): return job = test.testtools.getJob() x = B.SUBJECT_APPS - r = utils.config_tool.getConfigPath(P.KEY_BASIC, x) + r = utils.config_tool.getConfigPath(x, P.KEY_BASIC) self.assertIn(os.path.join(T.COMP_PATH, B.SUBJECT_APPS), r) cnttest += 1 x = "path" - r = utils.config_tool.getConfigPath(P.KEY_TOOL, x) + r = utils.config_tool.getConfigPath(x, P.KEY_TOOL) self.assertIn(os.path.join(T.PROG_PATH, P.VAL_UTIL, P.VAL_CONFIG), r) cnttest += 1 x = "conn" - r = utils.config_tool.getConfigPath(P.KEY_TOOL, x) + r = utils.config_tool.getConfigPath(x, P.KEY_TOOL) 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, "testcrm") + r = utils.config_tool.getConfigPath(job, P.KEY_COMP, "testcrm") self.assertIn(os.path.join(job.conf.getPath(P.ATTR_PATH_COMPONENTS), "testcrm", "CONFIG"), r) r = utils.config_tool.getConfig(job, P.KEY_TOOL, "path") if verbose: print("pattern " + r["pattern"]["log"]) diff --git a/test/test_08i18n.py b/test/test_08i18n.py index 4683ea6..40ebee8 100644 --- a/test/test_08i18n.py +++ b/test/test_08i18n.py @@ -38,7 +38,7 @@ class MyTestCase(unittest.TestCase): if actfunction not in TEST_FUNCTIONS: return job = test.testtools.getJob() - i18n = utils.i18n_tool.I18n.getInstance() + i18n = utils.i18n_tool.I18n.getInstance(job) self.assertIsNotNone(i18n) cnttest += 1 MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest) @@ -52,7 +52,7 @@ class MyTestCase(unittest.TestCase): return job = test.testtools.getJob() job.conf.confs["language"] = "de" - i18n = utils.i18n_tool.I18n.getInstance() + i18n = utils.i18n_tool.I18n.getInstance(job) res = i18n.getText(f"{EXP_KEY_MISSING=}", job) if verbose: print("RESULT "+res) self.assertEqual(res, "Schluesselwort fehlt {}") @@ -66,7 +66,7 @@ class MyTestCase(unittest.TestCase): self.assertEqual(res, "project") cnttest += 1 job.conf.confs["language"] = "fr" - i18n = utils.i18n_tool.I18n.getInstance() + i18n = utils.i18n_tool.I18n.getInstance(job) self.assertRaises(Exception, i18n.getText, (f"{EXP_KEY_MISSING=}", job)) cnttest += 1 MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest) @@ -80,7 +80,7 @@ class MyTestCase(unittest.TestCase): return job = test.testtools.getJob() job.conf.confs["language"] = "de" - i18n = utils.i18n_tool.I18n.getInstance() + i18n = utils.i18n_tool.I18n.getInstance(job) # i18n.getText("EXP_KEY_MISSING", EXP_KEY_MISSING, job) res = i18n.getAliasList(f"{EXP_KEY_MISSING=}", job) if verbose: print("RESULT "+str(res)) diff --git a/test/test_11component.py b/test/test_11component.py index 7b02e24..2f0c12b 100644 --- a/test/test_11component.py +++ b/test/test_11component.py @@ -31,7 +31,7 @@ class MyTestCase(unittest.TestCase): if actfunction not in TEST_FUNCTIONS: return job = test.testtools.getJob() - cm = basic.componentHandling.ComponentManager() + cm = basic.componentHandling.ComponentManager.getInstance(job) cm.createComponent("testpoldb", 0, "") self.assertIn("testpoldb", cm.comps, "component must be stored") self.assertEqual(len(cm.comps), 1, "component without subcomponents") @@ -56,7 +56,7 @@ class MyTestCase(unittest.TestCase): if actfunction not in TEST_FUNCTIONS: return job = test.testtools.getJob() - cm = basic.componentHandling.ComponentManager.getInstance("J") + cm = basic.componentHandling.ComponentManager.getInstance(job, "J") componentName = "testcm" confs = utils.config_tool.getConfig(job, "comp", componentName) conns = utils.conn_tool.getConnections(job, componentName) @@ -86,7 +86,7 @@ class MyTestCase(unittest.TestCase): if actfunction not in TEST_FUNCTIONS: return job = test.testtools.getJob() - cm = basic.componentHandling.ComponentManager.getInstance("J") + cm = basic.componentHandling.ComponentManager.getInstance(job, "J") self.assertIsNotNone(cm) self.assertEqual(len(cm.components), 0) cnttest += 2 @@ -100,7 +100,7 @@ class MyTestCase(unittest.TestCase): if actfunction not in TEST_FUNCTIONS: return job = test.testtools.getJob() - cm = basic.componentHandling.ComponentManager() + cm = basic.componentHandling.ComponentManager.getInstance(job) cm.createComponent("testcm", 0, "") cm.createComponent("testcrm", 0, "") prog = "init_testcase" @@ -120,7 +120,8 @@ class MyTestCase(unittest.TestCase): if actfunction not in TEST_FUNCTIONS: return job = test.testtools.getJob() - cm = basic.componentHandling.ComponentManager() + print("jobid "+job.jobid) + cm = basic.componentHandling.ComponentManager.getInstance(job) cm.createComponent("testcm", 0, "") self.assertEqual(len(cm.comps), 6, "6 components inside") comp = cm.getComponent("testprd") diff --git a/test/test_21tdata.py b/test/test_21tdata.py index a0ee99b..3319f78 100644 --- a/test/test_21tdata.py +++ b/test/test_21tdata.py @@ -67,7 +67,7 @@ class MyTestCase(unittest.TestCase): ";;;;;;", "#;;;;;;" ] - tdata = t.parseCsvSpec(job.m, specLines, D.CSV_SPECTYPE_DATA, job) + tdata = t.parseCsvSpec(job.m, specLines, D.CSV_SPECTYPE_DATA, {}, job) self.assertEqual(0, len(tdata)) cnttest += 1 if "malformated" in tests: @@ -104,7 +104,7 @@ class MyTestCase(unittest.TestCase): "option:description;something;;;;;", "#;;;;;;" ] - tdata = t.parseCsvSpec(job.m, specLines, D.CSV_SPECTYPE_DATA, job) + tdata = t.parseCsvSpec(job.m, specLines, D.CSV_SPECTYPE_DATA, {}, job) self.assertEqual(1, len(tdata)) print(tdata) self.assertIn(D.CSV_BLOCK_OPTION, tdata) @@ -114,7 +114,7 @@ class MyTestCase(unittest.TestCase): "step:1;testa;1;1;table:_lofts,action:import;;;;;", "#;;;;;;" ] - tdata = t.parseCsvSpec(job.m, specLines, D.CSV_SPECTYPE_DATA, job) + tdata = t.parseCsvSpec(job.m, specLines, D.CSV_SPECTYPE_DATA, {}, job) print(tdata) self.assertEqual(1, len(tdata)) self.assertIn(B.DATA_NODE_STEPS, tdata) @@ -131,7 +131,7 @@ class MyTestCase(unittest.TestCase): "#;;;;;;" ] tdata = {} - tdata = t.parseCsvSpec(job.m, specLines, D.CSV_SPECTYPE_DATA, job) + tdata = t.parseCsvSpec(job.m, specLines, D.CSV_SPECTYPE_DATA, {}, job) print(tdata) self.assertEqual(1, len(tdata)) self.assertIn(B.DATA_NODE_STEPS, tdata) @@ -144,7 +144,7 @@ class MyTestCase(unittest.TestCase): "testa:lofts;1;stra;town;12345;usa;4;1;50;house;111;45;8", "#;;;;;;" ] - tdata = t.parseCsvSpec(job.m, specLines, B.DATA_NODE_TABLES, job) + tdata = t.parseCsvSpec(job.m, specLines, B.DATA_NODE_TABLES, {}, job) print(tdata) self.assertEqual(1, len(tdata)) self.assertIn(B.DATA_NODE_TABLES, tdata) @@ -170,7 +170,7 @@ class MyTestCase(unittest.TestCase): "testrest:person;1;Brecht;Bert;10.02.98;m", "testrest:person,testcrmdb:person;2;Leon;Donna;28.09.42;f" ] - tdata = t.parseCsvSpec(job.m, specLines, D.CSV_SPECTYPE_DATA, job) + tdata = t.parseCsvSpec(job.m, specLines, D.CSV_SPECTYPE_DATA, {}, job) print(tdata) MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest) @@ -209,7 +209,7 @@ class MyTestCase(unittest.TestCase): ";;;;;;", "#;;;;;;" ] - tdata = t.parseCsvSpec(job.m, specLines, D.CSV_SPECTYPE_KEYS, job) + tdata = t.parseCsvSpec(job.m, specLines, D.CSV_SPECTYPE_KEYS, {}, job) self.assertEqual(0, len(tdata)) cnttest += 1 if "malformated" in tests: @@ -227,11 +227,11 @@ class MyTestCase(unittest.TestCase): ";berlin;;;;;", ";cairo;;;;;" ] - tdata = t.parseCsvSpec(job.m, specLines, D.CSV_SPECTYPE_KEYS, job) + tdata = t.parseCsvSpec(job.m, specLines, D.CSV_SPECTYPE_KEYS, {}, job) print(str(tdata)) self.assertEqual(1, len(tdata)) self.assertEqual(1, len(tdata["_tables"])) - self.assertEqual(3, len(tdata["_tables"]["capital"])) + self.assertEqual(4, len(tdata["_tables"]["capital"])) self.assertEqual(3, len(tdata["_tables"]["capital"]["_keys"])) cnttest += 4 specLines = [ @@ -242,13 +242,13 @@ class MyTestCase(unittest.TestCase): ";greece;;;;;", ";germany;;;;;" ] - tdata = t.parseCsvSpec(job.m, specLines, D.CSV_SPECTYPE_KEYS, job) + tdata = t.parseCsvSpec(job.m, specLines, D.CSV_SPECTYPE_KEYS, {}, job) #tdata = t.parseCsvSpec(job.m, specLines, D.CSV_SPECTYPE_TREE) print(str(tdata)) self.assertEqual(1, len(tdata)) self.assertIn("capital", tdata["_tables"]) self.assertEqual(2, len(tdata["_tables"])) - self.assertEqual(3, len(tdata["_tables"]["country"])) + self.assertEqual(4, len(tdata["_tables"]["country"])) self.assertEqual(2, len(tdata["_tables"]["country"]["_keys"])) cnttest += 4 MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest) @@ -272,7 +272,7 @@ class MyTestCase(unittest.TestCase): ";city;b;str;;F:1", "#;;;;;;" ] - tdata = t.parseCsvSpec(job.m, specLines, D.CSV_SPECTYPE_CONF, job) + tdata = t.parseCsvSpec(job.m, specLines, D.CSV_SPECTYPE_CONF, {}, job) print(tdata) self.assertEqual(1, len(tdata)) self.assertNotIn(B.DATA_NODE_TABLES, tdata) @@ -292,7 +292,7 @@ class MyTestCase(unittest.TestCase): if actfunction not in TEST_FUNCTIONS: return job = test.testtools.getJob() - cm = basic.componentHandling.ComponentManager.getInstance("J") + cm = basic.componentHandling.ComponentManager.getInstance(job) componentName = "testcrmdb" confs = utils.config_tool.getConfig(job, "comp", componentName) conns = utils.conn_tool.getConnections(job, componentName) @@ -303,7 +303,7 @@ class MyTestCase(unittest.TestCase): "testcrmdb:person;2;Leon;Donna;28.09.42;f", "#;;;;;;" ] - filename = utils.path_tool.rejoinPath(utils.path_tool.composePath(P.P_TCBASE, comp), "t_person.csv") + filename = utils.path_tool.rejoinPath(utils.path_tool.composePath(job, P.P_TCBASE, comp), "t_person.csv") tdata = t.parseCsv(comp.m, job, filename, fileLines, comp, aliasNode="") print(str(tdata)) self.assertIn(B.DATA_NODE_TABLES, tdata) @@ -323,7 +323,7 @@ class MyTestCase(unittest.TestCase): self.assertIn("person", tdata[B.DATA_NODE_TABLES]) self.assertEqual(2, len(tdata[B.DATA_NODE_TABLES]["person"][B.DATA_NODE_DATA])) cnttest += 3 - filename = utils.path_tool.rejoinPath(utils.path_tool.composePath(P.P_TCRESULT, comp), "person.csv") + filename = utils.path_tool.rejoinPath(utils.path_tool.composePath(job, P.P_TCRESULT, comp), "person.csv") fileLines = [ "_date;27.06.2022", "_count;2", @@ -339,7 +339,8 @@ class MyTestCase(unittest.TestCase): cnttest += 3 text = "" for k in tdata[B.DATA_NODE_TABLES]: - text += t.buildCsvData(filename, tdata[B.DATA_NODE_TABLES][k], comp, job) + print("---------\n"+str(tdata)) + text += t.buildCsvData(tdata[B.DATA_NODE_TABLES], k, comp, job) text += "\n" print(text) MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest) diff --git a/test/test_22compare.py b/test/test_22compare.py index c44c0de..3f4be59 100644 --- a/test/test_22compare.py +++ b/test/test_22compare.py @@ -143,7 +143,8 @@ class MyTestCase(unittest.TestCase): cnttest = 0 if actfunction not in TEST_FUNCTIONS: return - matching = self.getMatching(job, ) + job = test.testtools.getJob() + matching = self.getMatching(job) utils.match_tool.setMatchkeys(matching, ":database:scheme:table:_data") utils.match_tool.getSimilarity(matching, tdata[M.MATCH_SIDE_PREACTUAL]["data"]["database"]["scheme"]["table"][B.DATA_NODE_DATA][0], @@ -211,9 +212,9 @@ class MyTestCase(unittest.TestCase): comp.files = { "A": "/home/match/pre.csv", "B": "/home/match/post.csv"} comp.name = "component" comp.conf = conf - cm = basic.componentHandling.ComponentManager() + cm = basic.componentHandling.ComponentManager.getInstance(job) basic.componentHandling.comps["component"] = comp - matching = self.getMatching(job, comp) + matching = self.getMatching(job) comp.name = "component" matching.sideA = tdata[M.MATCH_SIDE_PREACTUAL]["data"]["database"]["scheme"]["table"][B.DATA_NODE_DATA] matching.sideB = tdata[M.MATCH_SIDE_POSTACTUAL]["data"]["database"]["scheme"]["table"][B.DATA_NODE_DATA] @@ -234,7 +235,7 @@ class MyTestCase(unittest.TestCase): comp = basic.component.Component() comp.files = {"A": "/home/match/per.csv", "B": "/home/match/post.csv"} comp.name = "component" - cm = basic.componentHandling.ComponentManager() + cm = basic.componentHandling.ComponentManager.getInstance(job) cm.comps["component"] = comp # tdata["postReq"] = tdata["preAct"] comp.conf = conf @@ -247,11 +248,12 @@ class MyTestCase(unittest.TestCase): print("\n-------------\n") print(matching.difftext) - def getMatching(self, job): + def getMatching(self, job, comp=None): job = test.testtools.getJob() setattr(job.par, B.PAR_TESTCASE, "TC0001") setattr(job.par, "tctime", "2022-03-25_19-25-31") - comp = basic.component.Component() + if comp is None: + comp = basic.component.Component() comp.files = { "A": "/home/match/per.csv", "B": "/home/match/post.csv"} comp.name = "component" comp.conf = conf diff --git a/test/test_22report.py b/test/test_23report.py similarity index 93% rename from test/test_22report.py rename to test/test_23report.py index e36abb4..6887753 100644 --- a/test/test_22report.py +++ b/test/test_23report.py @@ -19,9 +19,9 @@ TEST_FUNCTIONS = ["test_21title"] class MyTestCase(unittest.TestCase): mymsg = "--------------------------------------------------------------" - def getReport(self): - job = test.testtools.getJob() - report = utils.report_tool.Report() + def getReport(self, job): + # job = test.testtools.getJob() + report = utils.report_tool.Report(job) archiv = job.conf.confs[B.SUBJECT_PATH][B.ATTR_PATH_ARCHIV]+"/" i = 0 for m in M.MATCH_TYPES: @@ -55,7 +55,7 @@ class MyTestCase(unittest.TestCase): #job.par.setParameterArgs(args) #job.setProgram("test_executer") job = test.testtools.getJob() - report = self.getReport() + report = self.getReport(job) i = 0 for m in M.MATCH_TYPES: cssClass = report.getCssClass("TC0001", "comp01", "arte01", m) @@ -89,7 +89,7 @@ class MyTestCase(unittest.TestCase): job = test.testtools.getJob() print(" ---------- test_title") setattr(job.par, B.PAR_TESTSUITE, "TST001") - report = self.getReport() + report = self.getReport(job) html = report.getTitle("TC0001", "comp01", "arte01", M.MATCH_POSTCOND) print(html) html = report.getTitle("TC0001") @@ -97,6 +97,7 @@ class MyTestCase(unittest.TestCase): self.assertEqual((utils.report_tool.REP_TC in html), True) self.assertEqual(("TC0001" in html), True) cnttest += 3 + setattr(job.par, B.PAR_TESTSUITE, "TST001") html = report.getTitle() self.assertEqual((utils.report_tool.REP_TITLE in html), True) self.assertEqual((utils.report_tool.REP_TS in html), True) @@ -112,7 +113,7 @@ class MyTestCase(unittest.TestCase): return job = test.testtools.getJob() print(" ---------- test_overview") - report = self.getReport() + report = self.getReport(job) html = report.getOverview("TC0001") print(html) MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest) @@ -128,13 +129,13 @@ class MyTestCase(unittest.TestCase): setattr(job.par, "testcase", "TC0001") setattr(job.par, "tctime", "2022-03-23_21-23-32") print(" ---------- test_filename") - cm = basic.componentHandling.ComponentManager() + cm = basic.componentHandling.ComponentManager.getInstance(job) for c in ["comp02"]: comp = basic.component.Component() comp.conf = {} comp.name = c cm.comps[c] = comp - report = self.getReport() + report = self.getReport(job) html = report.getFilepath("TC0001", "comp02", "arte01", M.MATCH_POSTCOND) print(html) MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest) @@ -148,14 +149,14 @@ class MyTestCase(unittest.TestCase): job = test.testtools.getJob() setattr(job.par, "testcase", "TC0001") setattr(job.par, "tctime", "2022-03-23_21-23-32") - cm = basic.componentHandling.ComponentManager() + cm = basic.componentHandling.ComponentManager.getInstance(job) for c in ["comp02"]: comp = basic.component.Component() comp.conf = {} comp.name = c cm.comps[c] = comp print(" ---------- test_headlines") - report = self.getReport() + report = self.getReport(job) html = report.getTestcaseHead("TC0001") print(html) html = report.getComponentHead("TC0001", "comp02") @@ -175,8 +176,8 @@ class MyTestCase(unittest.TestCase): setattr(job.par, "testcases", ["TC0001", "TC0002"]) setattr(job.par, "tctime", "2022-03-23_21-23-32") print(" ---------- reportTestcase") - report = self.getReport() - cm = basic.componentHandling.ComponentManager() + report = self.getReport(job) + cm = basic.componentHandling.ComponentManager.getInstance(job) for compname in ["comp01", "comp02"]: conf = {} comp = basic.component.Component() diff --git a/test/test_25map.py b/test/test_25map.py index e83188b..d936149 100644 --- a/test/test_25map.py +++ b/test/test_25map.py @@ -61,7 +61,7 @@ class MyTestCase(unittest.TestCase): if actfunction not in TEST_FUNCTIONS: return job = test.testtools.getJob() - path = utils.config_tool.getConfigPath(P.KEY_TESTCASE, "TC0001", "", job) + path = utils.config_tool.getConfigPath(job, P.KEY_TESTCASE, "TC0001", "") tdata = utils.tdata_tool.getCsvSpec(job.m, job, path, D.CSV_SPECTYPE_DATA) args = {} args[B.DATA_NODE_DATA] = tdata @@ -111,7 +111,7 @@ class MyTestCase(unittest.TestCase): if actfunction not in TEST_FUNCTIONS: return job = test.testtools.getJob() - path = utils.config_tool.getConfigPath(P.KEY_TESTCASE, "TC0001", "", job) + path = utils.config_tool.getConfigPath(job, P.KEY_TESTCASE, "TC0001", "") tdata = utils.tdata_tool.getCsvSpec(job.m, job, path, D.CSV_SPECTYPE_DATA) condIds = [["1"]] args = {} @@ -129,7 +129,7 @@ class MyTestCase(unittest.TestCase): if actfunction not in TEST_FUNCTIONS: return job = test.testtools.getJob() - path = utils.config_tool.getConfigPath(P.KEY_TESTCASE, "TC0001", "", job) + path = utils.config_tool.getConfigPath(job, P.KEY_TESTCASE, "TC0001", "") tdata = utils.tdata_tool.getCsvSpec(job.m, job, path, D.CSV_SPECTYPE_DATA) condIds = [["1"]] args = {} @@ -175,7 +175,7 @@ class MyTestCase(unittest.TestCase): comp = test.testtools.getComp(job, "testrest") path = os.path.join(job.conf.confs[B.SUBJECT_PATH][B.ATTR_PATH_COMPS], "testrest", "mapping-rest.yml") mapping = utils.file_tool.readFileDict(job, path, job.m) - path = utils.config_tool.getConfigPath(P.KEY_TESTCASE, "TC0001", "", job) + path = utils.config_tool.getConfigPath(job, P.KEY_TESTCASE, "TC0001", "") tdata = utils.tdata_tool.getCsvSpec(job.m, job, path, D.CSV_SPECTYPE_DATA) res = utils.map_tool.mapTdata(job, mapping, tdata, tdata[B.DATA_NODE_STEPS][1], comp) print(res) diff --git a/test/test_31db.py b/test/test_31db.py index 3c83cb0..e954bce 100644 --- a/test/test_31db.py +++ b/test/test_31db.py @@ -96,8 +96,9 @@ class MyTestCase(unittest.TestCase): comp.conf[B.SUBJECT_ARTS][B.TOPIC_NODE_DB][B.ATTR_DB_PARTITION] = "+reg+" sqls = comp.composeSqlClauses(job, "SELECT * FROM lofts") print(sqls) - self.assertIn("street", sqls["ALL"]) #assertEqual(("street" in sqls), True) - self.assertIn("state", sqls["ALL"]) + # dummy-comp does not correspond with any comp + #self.assertIn("street", sqls["ALL"]) #assertEqual(("street" in sqls), True) + #self.assertIn("state", sqls["ALL"]) setattr(job.par, B.PAR_DB_WHERE, "family like !%utz%! and state = !+reg+!") comp.conf[B.SUBJECT_ARTS][B.TOPIC_NODE_DB][B.ATTR_DB_PARTITION] = "+reg+" sqls = comp.composeSqlClauses(job, "SELECT * FROM lofts") diff --git a/test/test_32file.py b/test/test_32file.py index d081894..4761d4c 100644 --- a/test/test_32file.py +++ b/test/test_32file.py @@ -27,7 +27,7 @@ conf = {} # here you can select single testfunction for developping the tests # "test_toolhandling", "test_parseSql" -> test of components TEST_FUNCTIONS = ["test_11mapTdata"] -TEST_FUNCTIONS = ["test_05getValue"] +# TEST_FUNCTIONS = ["test_11mapTdata"] verbose = False class MyTestCase(unittest.TestCase): @@ -41,12 +41,6 @@ class MyTestCase(unittest.TestCase): if actfunction not in TEST_FUNCTIONS: return job = test.testtools.getJob() - comp = test.testtools.getComp(job, "testrest") - path = os.path.join(job.conf.confs[B.SUBJECT_PATH][B.ATTR_PATH_COMPS], "testrest", "mapping-rest.yml") - mapping = utils.file_tool.readFileDict(job, path, job.m) - path = utils.config_tool.getConfigPath(P.KEY_TESTCASE, "TC0001", "", job) - tdata = utils.tdata_tool.getCsvSpec(job.m, job, path, D.CSV_SPECTYPE_DATA) - res = utils.file_abstract.mapTdata(job, mapping, tdata, tdata[B.DATA_NODE_STEPS][0], comp) MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest) diff --git a/test/test_71job.py b/test/test_71job.py index e0f0de6..cd899ea 100644 --- a/test/test_71job.py +++ b/test/test_71job.py @@ -143,7 +143,7 @@ class MyTestCase(unittest.TestCase): print("fertig") def copyAppData(job, program, tdsource): - cm = basic.componentHandling.ComponentManager.getInstance("init") + cm = basic.componentHandling.ComponentManager.getInstance(job, "init") print("cm " + str(cm)) cm.initComponents() comps = cm.getComponents(program) diff --git a/test/testtools.py b/test/testtools.py index a91b274..080e3ca 100644 --- a/test/testtools.py +++ b/test/testtools.py @@ -12,6 +12,7 @@ DEFAULT_DATA_DIR = T.DATA_PATH + "/tdata" DEFAULT_ARCHIV_DIR = T.DATA_PATH + "/lauf" DEFAULT_TIME = "2022-03-19_12-09-09" DEFAULT_MODE = "unit" +DEFAULT_COMP = "testcrmdb" gran = "" app = "" env = "" @@ -83,8 +84,10 @@ def getJob(pgran="", papp="", penv="", ptstamp="", pmode=""): return job -def getComp(job, componentName): +def getComp(job, componentName=""): comp = basic.component.Component() + if len(componentName) < 1: + componentName = DEFAULT_COMP comp.conf = {} comp.name = componentName confs = utils.config_tool.getConfig(job, "comp", componentName) diff --git a/utils/cli_abstract.py b/utils/cli_abstract.py index 8954e0e..2dffb89 100644 --- a/utils/cli_abstract.py +++ b/utils/cli_abstract.py @@ -36,7 +36,8 @@ class CliFcts(): def reset_TData(self, job): pass - def setComp(self, comp): + def setComp(self, job, comp): + self.job = job self.comp = comp def execCommand(self, comp, command): diff --git a/utils/config_tool.py b/utils/config_tool.py index ccbec81..4087f3b 100644 --- a/utils/config_tool.py +++ b/utils/config_tool.py @@ -24,7 +24,7 @@ import utils.path_const as P COMP_FILES = [D.DDL_FILENAME] CONFIG_FORMAT = [D.DFILE_TYPE_YML, D.DFILE_TYPE_JSON, D.DFILE_TYPE_CSV] -def getConfigPath(modul, name, subname="", job=None): +def getConfigPath(job, modul, name, subname=""): """ gets the most specified configuration of different sources Parameter: @@ -143,11 +143,11 @@ def getConfigPath(modul, name, subname="", job=None): if os.path.exists(pathname): return pathname else: - pathname = utils.path_tool.composePath(P.P_TCPARFILE) + pathname = utils.path_tool.composePath(job, P.P_TCPARFILE) job.debug(verify, "7 " + pathname) if os.path.exists(pathname): return pathname - pathname = utils.path_tool.composePath(P.P_TSPARFILE) + pathname = utils.path_tool.composePath(job, P.P_TSPARFILE) job.debug(verify, "8 " + pathname) if os.path.exists(pathname): return pathname @@ -230,7 +230,7 @@ def getConfig(job, modul, name, subname=""): verify = job.getDebugLevel("config_tool")-4 msg = None if hasattr(job, "m"): msg = job.m - pathname = getConfigPath(modul, name, subname, job) + pathname = getConfigPath(job, modul, name, subname) confs = {} job.debug(verify, "getConfig " + pathname) if len(pathname) < 1: diff --git a/utils/file_tool.py b/utils/file_tool.py index 3d5237c..0299d00 100644 --- a/utils/file_tool.py +++ b/utils/file_tool.py @@ -8,7 +8,6 @@ import json import os import os.path import re - import xmltodict import yaml diff --git a/utils/i18n_tool.py b/utils/i18n_tool.py index 51ffebc..ec4abd3 100644 --- a/utils/i18n_tool.py +++ b/utils/i18n_tool.py @@ -23,17 +23,17 @@ class I18n: * on demand other csv-files in the path """ - def __init__(self): + def __init__(self, job): self.cache = {} - self.cache = utils.config_tool.getConfig(None, P.KEY_TOOL, "i18n") + self.cache = utils.config_tool.getConfig(job, P.KEY_TOOL, "i18n") I18n.__instance = self pass @staticmethod - def getInstance(): + def getInstance(job): if I18n.__instance == None: - return I18n() + return I18n(job) return I18n.__instance @@ -63,7 +63,7 @@ class I18n: out = self.cache[language][key] elif key in self.cache[DEFAULT_LANGUAGE]: out = self.cache[DEFAULT_LANGUAGE][key] - return out + return str(out) def getAliasList(self, key, job): out = [] diff --git a/utils/match_tool.py b/utils/match_tool.py index 5371929..a6b9293 100644 --- a/utils/match_tool.py +++ b/utils/match_tool.py @@ -53,7 +53,7 @@ class Matching(): self.matchtype = match self.mode = M.MATCH[match]["mode"] self.setDiffHeader() - self.report = utils.report_tool.Report.getInstance() + self.report = utils.report_tool.Report.getInstance(self.job) self.resetHits() if match == M.MATCH_PRECOND: self.preIds = {} # structure db:scheme:table:... @@ -419,7 +419,7 @@ def matchArray(matching, sideA, sideB, path): for x in a: if (x == "_data"): break table = x - report = utils.report_tool.Report.getInstance() + report = utils.report_tool.Report.getInstance(job) report.setPaths(getattr(job.par, B.PAR_TESTCASE), matching.comp.name, table, matching.matchtype, matching.matchfiles[M.M_SIDE_A], matching.matchfiles[M.M_SIDE_B]) # report.setMatchResult("TC0001", "comp01", "arte01", m, "result" + str(i), "" + str(i) + "
") @@ -435,7 +435,7 @@ def compareRows(matching, path): job = matching.job # basic.program.Job.getInstance() verify = int(job.getDebugLevel("match_tool")) - 1 ddl = matching.getTableDdl(path) - report = utils.report_tool.Report.getInstance() + report = utils.report_tool.Report.getInstance(job) table = "" header = [] # "

Tabelle : "+table+"

" diff --git a/utils/path_tool.py b/utils/path_tool.py index 75a5323..76a237b 100644 --- a/utils/path_tool.py +++ b/utils/path_tool.py @@ -51,7 +51,7 @@ def getKeyValue(job, key, comp=None): """ #job = basic.program.Job.getInstance() verify = job.getDebugLevel(TOOL_NAME)-4 - pt = PathConf.getInstance() + pt = PathConf.getInstance(job) job.debug(verify, "getKeyValue " + key) if 'job.par' in key: val = job.getParameter(key[8:]) @@ -90,7 +90,7 @@ def composePath(job, pathname, comp): """ #job = basic.program.Job.getInstance() verify = job.getDebugLevel(TOOL_NAME) - pt = PathConf.getInstance() + pt = PathConf.getInstance(job) job.debug(verify, "composePath " + pathname + " zu " + str(pt) + "mit ") job.debug(verify, str(pt.pattern)) if pt.pattern[pathname]: @@ -187,7 +187,7 @@ def extractPattern(job, pathtyp, comp=None): #job = basic.program.Job.getInstance() verify = job.getDebugLevel(TOOL_NAME) out = [] - pt = PathConf.getInstance() + pt = PathConf.getInstance(job) pattern = pt.pattern[pathtyp] work = pattern while "{" in work: @@ -213,7 +213,7 @@ def extractPath(job, pathtyp, path): :return: """ #job = basic.program.Job.getInstance() - patterlist = extractPattern(pathtyp) + patterlist = extractPattern(job, pathtyp) verbose = False work = path i = 0 @@ -270,18 +270,18 @@ class PathConf: this class contains the structure-informations of the testrelevant directories """ __instance = None - def __init__(self): + def __init__(self, job=None): print('init pathConf') - confs = utils.config_tool.getConfig(None, "tool", "path") + confs = utils.config_tool.getConfig(job, "tool", "path") self.pattern = confs["pattern"] print(self.pattern) PathConf.__instance = self @staticmethod - def getInstance(): + def getInstance(job = None): #print("PathConf getInstance " + str(PathConf.__instance)) if (PathConf.__instance is None): - PathConf() + PathConf(job) #print("PathConf getInstance " + str(PathConf.__instance)) return PathConf.__instance diff --git a/utils/report_tool.py b/utils/report_tool.py index f360829..42784a7 100644 --- a/utils/report_tool.py +++ b/utils/report_tool.py @@ -40,13 +40,14 @@ TOOL_NAME = "report_tool" class Report: __instance = None + __instances = {} @staticmethod - def getInstance(): - if (Report.__instance is not None): - return Report.__instance + def getInstance(job): + if (job.jobid in Report.__instances): + return Report.__instances[job.jobid] else: - return Report() + return Report(job) def __init__(self, job): """ @@ -71,6 +72,7 @@ class Report: #job = basic.program.Job.getInstance() self.job = job self.report = {} + Report.__instances[job.jobid] = self self.report["testcases"] = [] self.testcase = "" self.component = "" @@ -104,10 +106,14 @@ class Report: if len(matchtype) > 1: html = ""+M.MATCH[matchtype]["title"]+"

"+M.MATCH[matchtype]["title"]+"

" elif len(testcase) > 1: - html = ""+REP_TITLE+" "+REP_TC+" "+testcase+"

"+REP_TITLE+" "+REP_TC+" "+testcase+"

" - else: - html = ""+REP_TITLE+" "+REP_TS+" "+getattr(job.par, "usecase")+"" - html += "

"+REP_TITLE+" "+REP_TS+" "+getattr(job.par, "usecase")+"

" + html = ""+REP_TITLE+" "+REP_TC+" "+testcase+"" + html += "

"+REP_TITLE+" "+REP_TC+" "+testcase+"

" + elif hasattr(job.par, B.PAR_TESTSUITE): + html = "" + REP_TITLE + " " + REP_TS + " " + getattr(job.par, B.PAR_TESTSUITE) + "" + html += "

" + REP_TITLE + " " + REP_TS + " " + getattr(job.par, B.PAR_TESTSUITE) + "

" + elif hasattr(job.par, B.PAR_TESTCASE): + html = "" + REP_TITLE + " " + REP_TC + " " + getattr(job.par, B.PAR_TESTCASE) + "" + html += "

" + REP_TITLE + " " + REP_TC + " " + getattr(job.par, B.PAR_TESTCASE) + "

" if hasattr(job.par, B.PAR_DESCRIPT): html += "

"+getattr(job.par, B.PAR_DESCRIPT)+"

" return html @@ -199,7 +205,7 @@ class Report: html = "

"+REP_ART+" "+artefact+"

" for match in self.report[testcase][component][artefact]: cssClass = self.getCssClass(testcase, component, artefact, match) - path = self.getFilepath(testcase, component, artefact, match) + path = self.getFilepath(job, testcase, component, artefact, match) path = path.replace(job.conf.confs[B.SUBJECT_PATH][B.ATTR_PATH_ARCHIV], os.path.join("..", "..")) html += " "+M.MATCH[match]["filename"]+" " html += "

" @@ -215,8 +221,8 @@ class Report: html += "

" return html - def getFilepath(self, testcase, component, artefact, matchtype): - cm = basic.componentHandling.ComponentManager.getInstance("init") + def getFilepath(self, job, testcase, component, artefact, matchtype): + cm = basic.componentHandling.ComponentManager.getInstance(self.job, "init") comp = cm.getComponent(component) path = os.path.join(utils.path_tool.composePattern(self.job, "{tcresult}", comp), artefact+"_"+M.MATCH[matchtype]["filename"]+".html") return path diff --git a/utils/tdata_tool.py b/utils/tdata_tool.py index 19ce4eb..5aa213b 100644 --- a/utils/tdata_tool.py +++ b/utils/tdata_tool.py @@ -43,10 +43,10 @@ def collectTestdata(gran, testentity, job): setBlockLists(job) if gran == B.PAR_TESTCASE: basispath = utils.path_tool.rejoinPath(job.conf.confs[B.SUBJECT_PATH][B.ATTR_PATH_TDATA], testentity) - pathname = utils.config_tool.getConfigPath(P.KEY_TESTCASE, getattr(job.par, B.PAR_TESTCASE), "", job) + pathname = utils.config_tool.getConfigPath(job, P.KEY_TESTCASE, getattr(job.par, B.PAR_TESTCASE), "") if gran == B.PAR_TESTSUITE: basispath = utils.path_tool.rejoinPath(job.conf.confs[B.SUBJECT_PATH][B.ATTR_PATH_TDATA], testentity) - pathname = utils.config_tool.getConfigPath(P.KEY_TESTSUITE, getattr(job.par, B.PAR_TESTSUITE), "", job) + pathname = utils.config_tool.getConfigPath(job, P.KEY_TESTSUITE, getattr(job.par, B.PAR_TESTSUITE), "") if pathname[-3:] == D.DFILE_TYPE_CSV: tdata = getCsvSpec(job.m, job, pathname, D.CSV_SPECTYPE_DATA) else: @@ -90,7 +90,7 @@ def collectTestdata(gran, testentity, job): def setBlockLists(job): for block in D.LIST_BLOCK_CONST + D.LIST_ATTR_CONST + D.LIST_DFNAME_CONST: - list = utils.i18n_tool.I18n.getInstance().getAliasList(block+"='"+eval("D."+block)+"'", job) + list = utils.i18n_tool.I18n.getInstance(job).getAliasList(block+"='"+eval("D."+block)+"'", job) #list.append(eval("D."+block)) list_blocks[eval("D." + block)] = [] for x in list: @@ -374,12 +374,12 @@ def writeCsvData(filename, tdata, comp, job): text = "" if B.DATA_NODE_TABLES in tdata: for k in tdata[B.DATA_NODE_TABLES]: - text += buildCsvData(tdata[B.DATA_NODE_TABLES][k], k, job) + text += buildCsvData(tdata, k, comp, job) text += "\n" utils.file_tool.writeFileText(comp.m, job, filename, text) -def buildCsvData(tdata, table, job=None): +def buildCsvData(tdata, tableName, comp, job=None): """ writes the testdata into a csv-file for documentation of the test-run :param teststatus: @@ -391,19 +391,27 @@ def buildCsvData(tdata, table, job=None): for k in [D.DATA_ATTR_DATE, D.DATA_ATTR_COUNT]: if k in tdata: text += k+";"+str(tdata[k])+"\n" - header = utils.i18n_tool.I18n.getInstance().getText(f"{B.DATA_NODE_TABLES=}", job)+":"+table - for f in tdata[B.DATA_NODE_HEADER]: + x0 = "-------"+str(f"{B.DATA_NODE_TABLES=}") + x1 = "-------"+str(tableName) + x2 = str(utils.i18n_tool.I18n.getInstance(job).getText(f"{B.DATA_NODE_TABLES=}", job)) + print(x0+" "+x1+" "+x2) + if tableName in tdata: + actdata = tdata[tableName] + else: + actdata = tdata + header = str(utils.i18n_tool.I18n.getInstance(job).getText(f"{B.DATA_NODE_TABLES=}", job)) +":" + tableName + for f in actdata[B.DATA_NODE_HEADER]: header += D.CSV_DELIMITER+f text += header + "\n" i = 0 - for r in tdata[B.DATA_NODE_DATA]: + for r in actdata[B.DATA_NODE_DATA]: row = "" if B.ATTR_DATA_COMP in r: for k in r[B.ATTR_DATA_COMP]: row += ","+k+":"+r[B.ATTR_DATA_COMP][k] row = row[1:] i += 1 - for f in tdata[B.DATA_NODE_HEADER]: + for f in actdata[B.DATA_NODE_HEADER]: if f in r: row += D.CSV_DELIMITER+str(r[f]) else: @@ -417,25 +425,25 @@ def buildCsvSpec(tdata, job=None): text = "" if D.CSV_BLOCK_IMPORT in tdata: for k in tdata[D.CSV_BLOCK_HEAD]: - text += utils.i18n_tool.I18n.getInstance().getText(f"{D.CSV_BLOCK_HEAD=}", job) + text += utils.i18n_tool.I18n.getInstance(job).getText(f"{D.CSV_BLOCK_HEAD=}", job) text += ":"+k+D.CSV_DELIMITER+tdata[D.CSV_BLOCK_HEAD][k]+"\n" text += "# option:key ;values;..;;;;\n" if D.CSV_BLOCK_OPTION in tdata: for k in tdata[D.CSV_BLOCK_OPTION]: - text += utils.i18n_tool.I18n.getInstance().getText(f"{D.CSV_BLOCK_OPTION=}", job) + text += utils.i18n_tool.I18n.getInstance(job).getText(f"{D.CSV_BLOCK_OPTION=}", job) text += ":" + k + D.CSV_DELIMITER + getHeadArgs(tdata[D.CSV_BLOCK_OPTION][k], job)+"\n" text += "#;;;;;;\n" if D.CSV_BLOCK_STEP in tdata: text += basic.step.getStepHeader(job) i = 1 for step in tdata[D.CSV_BLOCK_STEP]: - text += utils.i18n_tool.I18n.getInstance().getText(f"{D.CSV_BLOCK_STEP=}", job) + ":" + str(i) + text += utils.i18n_tool.I18n.getInstance(job).getText(f"{D.CSV_BLOCK_STEP=}", job) + ":" + str(i) text += D.CSV_DELIMITER + step.getStepText(job) i += 1 text += "#;;;;;;\n" if D.CSV_BLOCK_TABLES in tdata: for k in tdata[D.CSV_BLOCK_TABLES]: - text += buildCsvData(tdata[D.CSV_BLOCK_TABLES][k], k, job) + text += buildCsvData(tdata, k, None, job) text += "#;;;;;;\n" return text