From e3bd4adac592fedd671924917750c267b1b06434 Mon Sep 17 00:00:00 2001 From: Ulrich Carmesin Date: Mon, 2 May 2022 19:44:09 +0200 Subject: [PATCH] some more constants --- basic/componentHandling.py | 4 +- basic/constants.py | 14 ++-- collect_testcase.py | 2 +- compare_testcase.py | 2 +- components/component.py | 2 +- components/testexec.py | 105 +++++++++++++++----------- generate_testcases.py | 151 +++++++++++++++++++++++++++++++++++++ init_testcase.py | 7 +- test/test_compare.py | 10 +-- test_executer.py | 36 +++++---- utils/data_const.py | 12 +++ utils/db_abstract.py | 12 +-- utils/match_const.py | 42 ++++++----- utils/match_tool.py | 97 ++++++++++++++---------- utils/report_tool.py | 20 +++-- utils/tdata_tool.py | 16 ++-- utils/xml_tool.py | 10 +-- 17 files changed, 379 insertions(+), 163 deletions(-) create mode 100644 generate_testcases.py diff --git a/basic/componentHandling.py b/basic/componentHandling.py index b08eb4a..3b831e1 100644 --- a/basic/componentHandling.py +++ b/basic/componentHandling.py @@ -25,7 +25,7 @@ import copy import basic.constants as B comps = {} -PARAM_NOSUBNODE = ["artifact", "components", "instance"] +PARAM_NOSUBNODE = [B.SUBJECT_ARTS, "components", "instance"] DEFAULT_INST_CNT = 1 DEFAULT_INST_SGL = "y" @@ -234,7 +234,7 @@ def getComponentDict(): for c in comps: out[comps[c].name] = {} for k in comps[c].conf.keys(): - if isParameterSubnode(k): # "artifact" in k or "components" in k or "instance" in k: + if isParameterSubnode(k): # B.SUBJECT_ARTS in k or "components" in k or "instance" in k: out[comps[c].name][k] = copy.deepcopy(comps[c].conf[k]) return out diff --git a/basic/constants.py b/basic/constants.py index 9abf469..90bf505 100644 --- a/basic/constants.py +++ b/basic/constants.py @@ -49,6 +49,8 @@ PAR_DESCRIPT = 'desription' """ """ PAR_TESTCASE = "testcase" PAR_TESTSUITE = "usecase" +PAR_TCTIME = "tctime" +PAR_TSTIME = "tstime" """ name of testcase extracted from PAR_TCDIR """ @@ -69,19 +71,12 @@ DATA_NODE_STEPS = "_steps" DATA_NODE_OPTION = "_option" """ This constant defines main node in the testdata for testcase specific parameters """ DATA_NODE_DDL = "ddl" -""" This constant defines """ +""" This constant defines the node for data scheme (DataDefinitionLanguage) +The fields are defined in data_const (D) """ DATA_NODE_COMP = "comp" """ This constant defines """ DATA_NODE_PAR = "par" -DATA_NODE_TYPE = "type" -TYPE_STRING = "string" -TYPE_INT = "int" -TYPE_FLOAT = "float" -TYPE_DOUBLE = "double" -TYPE_DATE = "date" -TYPE_TIME = "time" - SVAL_YES = "y" SVAL_NO = "n" SVAL_NULL = "null" @@ -160,6 +155,7 @@ in this subject-node are each kind of result of any component with the structure ATTR_ARTS_DB = "db" ATTR_ARTS_LOG = "log" ATTR_ARTS_LOB = "lob" +ATTR_ARTS_FILE = "file" SUBJECT_DB = "databases" # | | | | # | db*_tools, match_tool SUBJECT_CONN = "conn" # | | x | | | conn_tool, db*_tools, cli*_toold diff --git a/collect_testcase.py b/collect_testcase.py index 70f646d..8052be3 100644 --- a/collect_testcase.py +++ b/collect_testcase.py @@ -18,7 +18,7 @@ def startPyJob(job): job.m.setMsg("# components initialized with "+str(comps)) for c in comps: comp = cm.getComponent(c) - comp.collect_Artifacts("testcase") + comp.collect_Artifacts(B.PAR_TESTCASE) job.m.merge(comp.m) if __name__ == '__main__': diff --git a/compare_testcase.py b/compare_testcase.py index b78da2d..0bdd43a 100644 --- a/compare_testcase.py +++ b/compare_testcase.py @@ -25,7 +25,7 @@ def startPyJob(job): for c in comps: comp = cm.getComponent(c) comp.m.logInfo("------- "+comp.name+" ----------------------------------------") - comp.compare_TcResults(report) + comp.compare_results(report) comp.m.logInfo("------- "+comp.name+" ----------------------------------------") job.m.merge(comp.m) print(str(comp)) diff --git a/components/component.py b/components/component.py index 03b1449..b228e21 100644 --- a/components/component.py +++ b/components/component.py @@ -57,7 +57,7 @@ class Component(components.testexec.Testexecuter): elif job.program == "init_testset": self.prepare_system("testset") elif job.program == "init_testcase": - self.prepare_system("testcase") + self.prepare_system(B.PAR_TESTCASE) elif job.program == "test_system": self.test_System("test") elif job.program == "test_system": diff --git a/components/testexec.py b/components/testexec.py index 00d4c8a..ae56299 100644 --- a/components/testexec.py +++ b/components/testexec.py @@ -36,10 +36,10 @@ import utils.db_abstract import basic.toolHandling import components.component import basic.componentHandling -import utils.db_abstract import utils.path_tool import utils.file_tool import utils.match_tool +import utils.match_const as M import utils.tdata_tool import basic.constants as B @@ -72,15 +72,15 @@ class Testexecuter(): verify = -1+job.getDebugLevel(self.name) self.m.debug(verify, "--- "+str(inspect.currentframe().f_code.co_name)+"() started at " + datetime.now().strftime("%Y%m%d_%H%M%S")+" for " + str(self.name).upper()) - if "log" in self.conf["artifact"]: + if B.ATTR_ARTS_LOG in self.conf[B.SUBJECT_ARTS]: self.m.logInfo("log rotate in "+ self.name) - if "db" in self.conf["artifact"]: + if "db" in self.conf[B.SUBJECT_ARTS]: self.m.logInfo("delete content "+ self.name) dbi = basic.toolHandling.getDbTool(self) dbi.deleteTables() - if "lob" in self.conf["artifact"]: + if B.ATTR_ARTS_LOB in self.conf[B.SUBJECT_ARTS]: self.m.logInfo("lob is deleted with flaskdb "+ self.name) - if "file" in self.conf["artifact"]: + if B.ATTR_ARTS_FILE in self.conf[B.SUBJECT_ARTS]: self.m.logInfo("rm files in "+ self.name) self.m.setMsg("resetInstance for " + self.name + " is OK") self.m.debug(verify, "--- " + str(inspect.currentframe().f_code.co_name) + "() finished at " + datetime.now().strftime("%Y%m%d_%H%M%S") + " for " + str(self.name).upper()) @@ -99,7 +99,7 @@ class Testexecuter(): plainname = basic.componentHandling.getPlainCompname(self.name) if plainname in testdata: print("plainname in testdata "+plainname) - if "db" in self.conf["artifact"]: + if "db" in self.conf[B.SUBJECT_ARTS]: self.m.logInfo("delete content "+ self.name) dbi = basic.toolHandling.getDbTool(self) dbi.insertTables(testdata) @@ -114,7 +114,7 @@ class Testexecuter(): """ job = basic.program.Job.getInstance() verify = -1+job.getDebugLevel(self.name) - self.read_TData("nachher", "testcase") + self.read_TData("nachher", B.PAR_TESTCASE) def read_TData(self, subdir, granularity): """ @@ -125,11 +125,11 @@ class Testexecuter(): job = basic.program.Job.getInstance() verify = -1+job.getDebugLevel(self.name) self.m.debug(verify, "--- " + str(inspect.currentframe().f_code.co_name) + "() started at " + datetime.now().strftime("%Y%m%d_%H%M%S") + " for " + str(self.name).upper()) - if "db" in self.conf["artifact"]: + if "db" in self.conf[B.SUBJECT_ARTS]: self.m.logInfo("select db-content "+ self.name) dbi = basic.toolHandling.getDbTool(self) dbi.selectTables() - if "lob" in self.conf["artifact"]: + if B.ATTR_ARTS_LOB in self.conf[B.SUBJECT_ARTS]: self.m.logInfo("check lob if is deleted with flaskdb "+ self.name) self.m.setMsg("readInstance for " + self.name + " is OK") self.m.debug(verify, "--- " + str(inspect.currentframe().f_code.co_name) + "() finished at " + datetime.now().strftime("%Y%m%d_%H%M%S") + " for " + str(self.name).upper()) @@ -154,26 +154,47 @@ class Testexecuter(): out["ALL"] = pattern return out + @staticmethod + def getStringIndex(text, intern): + if intern in text: + return text.index(intern) + return 999 + + @staticmethod + def parseCondition(condition): + out = [] + for operator in [">=", "<=", ">", "<", "=", " like ", " in "]: + if operator in condition: + i = condition.lower().index(operator) + field = condition[0:i] + attr = condition[i+len(operator):] + out = [operator, field, attr] + return out + return out + def composeSqlClauses(self, sql): job = basic.program.Job.getInstance() out = {} - print("composeSqlClauses "+sql) + print("-------- composeSqlClauses "+sql) table = sql[sql.upper().index(" FROM ")+6:].strip() - print(table) + print("table "+table) sql_new = sql[0:sql.upper().index(" FROM ")+5] - print(sql_new) + print("sql_new "+sql_new) 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] != "": table = attr[B.ATTR_DB_SCHEMA]+"."+table sql_new += " "+attr[B.ATTR_DB_DATABASE]+"."+table - print(sql_new) + print("sql_new "+sql_new) if (hasattr(job.par, B.PAR_DB_WHERE)): + parts = utils.db_abstract.parseSQLwhere(getattr(job.par, B.PAR_DB_WHERE), self.conf[B.DATA_NODE_DDL][table]) + # Felder und Operationen + # print(dbwhere) sql_new += " WHERE "+getattr(job.par, B.PAR_DB_WHERE) if sql_new[0:6] == "SELECT": sql_new += " ORDER BY id" - print(sql_new) + print("sql_new "+sql_new) sql_new = sql_new.replace('!', "\'") if (hasattr(job.par, B.PAR_DB_PARTITION)) and (attr[B.ATTR_DB_PARTITION] != "n"): parts = getattr(job.par, B.PAR_DB_PARTITION) @@ -184,6 +205,7 @@ class Testexecuter(): out[p] = sql_part else: out["ALL"] = sql_new + print("---> out "+str(out)) return out def test_System(self, granularity): @@ -229,14 +251,14 @@ class Testexecuter(): """ job = basic.program.Job.getInstance() verify = job.getDebugLevel(self.name) - if "log" in self.conf["artifact"]: - self.m.logInfo("get files in for "+ self.name + " in " + self.conf["artifact"]["log"]["path"]) - if "flaskdb" in self.conf["artifact"]: + if B.ATTR_ARTS_LOG in self.conf[B.SUBJECT_ARTS]: + self.m.logInfo("get files in for "+ self.name + " in " + self.conf[B.SUBJECT_ARTS][B.ATTR_ARTS_LOG]["path"]) + if "flaskdb" in self.conf[B.SUBJECT_ARTS]: self.m.logInfo("select flaskdb-content "+ self.name) - if "lob" in self.conf["artifact"]: + if B.ATTR_ARTS_LOB in self.conf[B.SUBJECT_ARTS]: pass # after selection get file from flaskdb - if "file" in self.conf["artifact"]: - self.m.logInfo("get files in for "+ self.name + " in " + self.conf["artifact"]["file"]["path"]) + if B.ATTR_ARTS_FILE in self.conf[B.SUBJECT_ARTS]: + self.m.logInfo("get files in for "+ self.name + " in " + self.conf[B.SUBJECT_ARTS][B.ATTR_ARTS_FILE]["path"]) self.m.debug(verify, "--- " + str(inspect.currentframe().f_code.co_name) + "() " + str(self.name)) @@ -248,16 +270,15 @@ class Testexecuter(): """ job = basic.program.Job.getInstance() verify = job.getDebugLevel(self.name) - self.m.debug(verify, "--- " + str(inspect.currentframe().f_code.co_name) + "() " + str(self.name)) - if "log" in self.conf["artifact"]: + self.m.debug(verify, "--- "+str(inspect.currentframe().f_code.co_name)+"() "+str(self.name)) + if B.ATTR_ARTS_LOG in self.conf[B.SUBJECT_ARTS]: pass # - if "flaskdb" in self.conf["artifact"]: + if "flaskdb" in self.conf[B.SUBJECT_ARTS]: pass # stored in table - if "lob" in self.conf["artifact"]: - self.m.logInfo("move file from flaskdb "+ self.name) - self.m.logInfo("tidy files in for " + self.name + " in " + self.conf["artifact"]["lob"]["format"]) - if "file" in self.conf["artifact"]: - self.m.logInfo("tidy files in for "+ self.name + " in " + self.conf["artifact"]["file"]["format"]) + if B.ATTR_ARTS_LOB in self.conf[B.SUBJECT_ARTS]: + self.m.logInfo("tidy files in for "+self.name+" in "+self.conf[B.SUBJECT_ARTS][B.ATTR_ARTS_LOB]["format"]) + if B.ATTR_ARTS_FILE in self.conf[B.SUBJECT_ARTS]: + self.m.logInfo("tidy files in for "+self.name+" in "+self.conf[B.SUBJECT_ARTS][B.ATTR_ARTS_FILE]["format"]) def fix_TcResult(self, granularity): """ @@ -283,41 +304,41 @@ class Testexecuter(): cm = basic.componentHandling.ComponentManager.getInstance() data = {} matching = utils.match_tool.Matching() - if "db" in self.conf["artifact"]: - for t in self.conf["artifact"]["db"]: + if "db" in self.conf[B.SUBJECT_ARTS]: + for t in self.conf[B.SUBJECT_ARTS]["db"]: if t in ["type"]: continue # fill each data into matching-object - for side in utils.match_tool.MATCH_SIDES: - if side == utils.match_tool.MATCH_SIDE_PRESTEP: - if "prestep" in self.conf["artifact"]["db"][t]: - a = self.conf["artifact"]["db"][t]["prestep"].split(":") + for side in M.MATCH_SIDES: + if side == M.MATCH_SIDE_PRESTEP: + if "prestep" in self.conf[B.SUBJECT_ARTS]["db"][t]: + a = self.conf[B.SUBJECT_ARTS]["db"][t]["prestep"].split(":") if a[0] != self.name: comp = cm.getComponent(a[0]) else: comp = self path = os.path.join(utils.path_tool.composePattern( - "{"+utils.match_tool.MATCH[utils.match_tool.MATCH_SIDE_POSTACTUAL]["filepattern"]+"}", comp), a[1]+".csv") + "{"+M.MATCH[M.MATCH_SIDE_POSTACTUAL][M.M_FILEPATTERN]+"}", comp), a[1]+".csv") pass - elif side == utils.match_tool.MATCH_SIDE_TESTCASE: + elif side == M.MATCH_SIDE_TESTCASE: if hasattr(job.par, "testcase_example"): path = os.path.join(utils.path_tool.composePattern( - "{"+utils.match_tool.MATCH[utils.match_tool.MATCH_SIDE_POSTEXPECT]["filepattern"]+"}", self), t+".csv") - path.replace(getattr(job.par, "testcase"), getattr(job.par, "testcase_example")) + "{"+M.MATCH[M.MATCH_SIDE_POSTEXPECT][M.M_FILEPATTERN]+"}", self), t+".csv") + path.replace(getattr(job.par, B.PAR_TESTCASE), getattr(job.par, "testcase_example")) else: - path = os.path.join(utils.path_tool.composePattern("{" + utils.match_tool.MATCH[side]["filepattern"] + "}", self), t + ".csv") + path = os.path.join(utils.path_tool.composePattern("{" + M.MATCH[side][M.M_FILEPATTERN] + "}", self), t + ".csv") filedata = utils.tdata_tool.readCsv(self.m, path, self) - data[side] = utils.match_tool.MATCH[side] + data[side] = M.MATCH[side] data[side]["path"] = path data[side]["data"] = filedata # execute the matches - for type in utils.match_tool.MATCH_TYPES: + for type in M.MATCH_TYPES: matching.setData(data, type) report.setPaths(job.par.testcase, self.name, t, type, matching.matchfiles["A"], matching.matchfiles["B"]) text = utils.match_tool.matchTree(matching) report.setMatchResult(job.par.testcase, self.name, t, type, matching.cssClass, matching.diffText) path = os.path.join(utils.path_tool.composePattern("{tcresult}", self), - t+"_"+utils.match_tool.MATCH[type]["filename"]+".html") + t+"_"+M.MATCH[type]["filename"]+".html") utils.file_tool.writeFileText(self.m, path, text) # write text pass diff --git a/generate_testcases.py b/generate_testcases.py new file mode 100644 index 0000000..8b44276 --- /dev/null +++ b/generate_testcases.py @@ -0,0 +1,151 @@ +import random +#from flask import +# +class Koeln(): + # Konfig + KOELN = { + "00" : "AI,AY,AU,EI,EY,EU,OI,Ä,Ö,Ü", # vokale + "40" : "CA,CO,CU", + "80" : "CE,CI,CY", + "88" : "SCH,ZC,DC,DS,DZ,TC,TS,TZ", + "48" : "X", + "0" : "AA,A,EE,IE,E,I,J,OU,OO,O,U,Y", # vokale + "1" : "B,P", # labiale + "2" : "D,T", + "3" : "PH,F,V,W", # labiale + "4" : "G,K,Q", + "5" : "L", + "6" : "M,N", + "7" : "R", + "8" : "S,Z" + } + def __init__(self): + self.init = "ja" + def getPhonWertMitVokal(self, wort): + out = "" + txt = wort.upper() + while (len(txt) > 0): + print("while "+txt) + a = self.getFirstPhonem(txt) + if (a[0] == "99"): + txt = txt[1:] + else: + out = out+a[0] + txt = txt[len(a[1]):] + print("while - " + txt + " "+out) + print("-------- RETURN - " + txt + " " + out) + return out + + def getPhonWert(self, wort): + out = self.getPhonWertMitVokal(wort) + for x in ["11", "22", "33", "44", "55", "66", "77", "88"]: + out = out.replace(x, x[0:1]) + out = out.replace("0", "") + print("-------- RETURN - " + wort + " " + out) + return out + + def getAehnlicherPhon(self, wort): + out = [wort] + gen = [""] + txt = self.getPhonWertMitVokal(wort) + while (len(txt) > 0): + for k in ["00", "40", "80", "88"]: + print ("+++ Umlaute +++") + if (txt[0:2]==k): + neu = [] + chc = [] + for y in gen: + c = "XXX" + for i in range(0, len(self.KOELN[k])/2): + c = random.choice(self.KOELN[k]) + while not c in chc: + print (" choice "+k+" = "+c+" :: "+self.KOELN[k]) + neu.append(y+c) + c = random.choice(self.KOELN[k]) + break + + for x in ["11", "22", "33", "44", "55", "66", "77"]: + if (txt[0:2] == x): + pass + def getAehnlicherPhonem(self, txt): + gen = [""] + phonems = { + "umlaut" : ["00", "40", "80", "88"], + "doppelk" : ["11", "22", "33", "44", "55", "66", "77"], + "literal" : ["0","1","2","3","4","5","6","7","8"] + } + while (len(txt) > 0): + for p in phonems: + for k in phonems[p]: + # print ("+++ Umlaute +++"+txt+"--"+k) + if (txt[0:len(k)]==k): + print("+++ Umlaute +++" + txt + "--" + k) + neu = [] + chc = [] + #print("+++ Umlaute +++" + txt + "--" + k) + c = "XXX" + for i in range(0, int(len(self.KOELN[k].split(","))/3 +1)): + status = 1 + c = random.choice(self.KOELN[k].split(",")) + while ((status==1) and (not c in chc)): + #print (str(i)+" choice "+k+" = "+c) + for y in gen: + neu.append(y+c) + chc.append(c) + c = random.choice(self.KOELN[k].split(",")) + status=2 + gen = neu + print(neu) + txt=txt[len(k):] + # txt="" + print(gen) + + def getFirstPhonem(self, txt): + for k in self.KOELN: + print(k + " wert " + self.KOELN[k]) + vv = self.KOELN[k].split(",") + for x in vv: + if (txt.find(x) == 0): + return (k, x); + return ("99", "H") + +# Funktionen +def generiereAehnlicheWerte(feld, basis): + print ("generiereAehnlicheWerte("+feld+", "+basis) + if (k == "FAMNAM"): + koeln.getPhonWert(basis) +# Parameter +koeln = Koeln() +job = {} +job["option"] = {} +job["option"]["regression"] = "g" # kreuz | orthogonal +job["option"]["clusteranz"] = 2 # +content = {} +content["Tabelle"] = {} +content["Tabelle"]["Person"] = {} +content["Tabelle"]["Person"]["FAMNAM"] = {} +content["Tabelle"]["Person"]["FAMNAM"]["option"] = "aehnlich" +content["Tabelle"]["Person"]["FAMNAM"]["gruppe"] = 1 +content["Tabelle"]["Person"]["FAMNAM"]["basis"] = ["Müller", "Schmidt"] +content["Tabelle"]["Person"]["GESCHLECHT"] = {} +content["Tabelle"]["Person"]["GESCHLECHT"]["option"] = "diff" +content["Tabelle"]["Person"]["GESCHLECHT"]["gruppe"] = 1 +content["Tabelle"]["Person"]["VORNAM"] = {} +content["Tabelle"]["Person"]["VORNAM"]["option"] = "beliebig" +content["Tabelle"]["Person"]["GEBDAT"] = {} +content["Tabelle"]["Person"]["GEBDAT"]["option"] = "identisch" +content["Tabelle"]["Person"]["GEBDAT"]["basis"] = ["19920123", "20210908"] + +gruppen = [] +for i in range(0, job["option"]["clusteranz"]): + print("index "+str(i)) + for k in content["Tabelle"]["Person"]: + print("key "+ k) + if content["Tabelle"]["Person"][k]["option"] == "aehnlich": + if (content["Tabelle"]["Person"][k]["basis"]): + werte = generiereAehnlicheWerte(k, content["Tabelle"]["Person"][k]["basis"][i]) + +koeln.getAehnlicherPhonem(("00")) +koeln.getAehnlicherPhonem(("3")) +koeln.getAehnlicherPhonem(("8")) +koeln.getAehnlicherPhonem(("886022")) diff --git a/init_testcase.py b/init_testcase.py index 685a70b..de0b073 100644 --- a/init_testcase.py +++ b/init_testcase.py @@ -5,6 +5,7 @@ import yaml # pip install pyyaml import basic.program as program import utils.tdata_tool import basic.componentHandling +import basic.constants as B import basic.message as message # Press Umschalt+F10 to execute it or replace it with your code. # Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings. @@ -22,9 +23,9 @@ def startPyJob(job): for c in comps: comp = cm.getComponent(c) comp.m.logInfo("------- "+comp.name+" ----------------------------------------") - comp.reset_TData("testcase") - comp.load_TData("testcase", testdata) - comp.read_TData("vorher", "testcase") + comp.reset_TData(B.PAR_TESTCASE) + comp.load_TData(B.PAR_TESTCASE, testdata) + comp.read_TData("vorher", B.PAR_TESTCASE) comp.m.logInfo("------- "+comp.name+" ----------------------------------------") job.m.merge(comp.m) print(str(comp)) diff --git a/test/test_compare.py b/test/test_compare.py index 8db645e..a616e35 100644 --- a/test/test_compare.py +++ b/test/test_compare.py @@ -84,7 +84,7 @@ class MyTestCase(unittest.TestCase): def test_matchstart(self): job = Job("unit") - setattr(job.par, "testcase", "TC0001") + setattr(job.par, B.PAR_TESTCASE, "TC0001") comp = components.component.Component() comp.files = { "A": "/home/match/per.csv", "B": "/home/match/post.csv"} comp.conf = conf @@ -118,7 +118,7 @@ class MyTestCase(unittest.TestCase): def test_bestfit(self): job = Job("unit") - setattr(job.par, "testcase", "TC0001") + setattr(job.par, B.PAR_TESTCASE, "TC0001") comp = components.component.Component() comp.name = "component" comp.files = { "A": "/home/match/per.csv", "B": "/home/match/post.csv"} @@ -137,7 +137,7 @@ class MyTestCase(unittest.TestCase): def test_compareRow(self): job = Job("unit") - setattr(job.par, "testcase", "TC0001") + setattr(job.par, B.PAR_TESTCASE, "TC0001") comp = components.component.Component() comp.files = { "A": "/home/match/per.csv", "B": "/home/match/post.csv"} comp.name = "component" @@ -174,7 +174,7 @@ class MyTestCase(unittest.TestCase): def test_match(self): job = Job("unit") - setattr(job.par, "testcase", "TC0001") + setattr(job.par, B.PAR_TESTCASE, "TC0001") setattr(job.par, "tctime", "2022-03-25_19-25-31") comp = components.component.Component() comp.files = {"A": "/home/match/per.csv", "B": "/home/match/post.csv"} @@ -194,7 +194,7 @@ class MyTestCase(unittest.TestCase): def getMatching(self): job = Job("unit") - setattr(job.par, "testcase", "TC0001") + setattr(job.par, B.PAR_TESTCASE, "TC0001") setattr(job.par, "tctime", "2022-03-25_19-25-31") comp = components.component.Component() comp.files = { "A": "/home/match/per.csv", "B": "/home/match/post.csv"} diff --git a/test_executer.py b/test_executer.py index 4e41631..fda1c0f 100644 --- a/test_executer.py +++ b/test_executer.py @@ -1,6 +1,6 @@ from datetime import datetime import basic.program -import basic.program as program +import basic.constants as B import utils.tdata_tool import init_testcase import init_testsuite @@ -20,43 +20,43 @@ def start(myjob): myjob.m.setMsg("# # # # # start executer # # # # # ") tdata = utils.tdata_tool.getTestdata() job = basic.program.Job("unit") - testcases = getattr(myjob.par, "testcases") + testcases = getattr(myjob.par, B.PAR_TESTCASE) if not hasattr(myjob.par, "step"): raise Exception("Parameter step is missing") - for step in tdata["_steps"]: + for step in tdata[B.DATA_NODE_STEPS]: if int(step["_nr"]) != int(getattr(myjob.par, "step")): continue for arg in step["args"]: if arg == "start": if "testsuite" in step["args"][arg]: - jobargs = {"application": myjob.par.application, "environment": myjob.par.environment, - "usecase": myjob.par.usecase, "tstime": utils.date_tool.getActdate(utils.date_tool.F_DIR)} + jobargs = {B.PAR_APP: myjob.par.application, B.PAR_ENV: myjob.par.environment, + B.PAR_TESTSUITE: myjob.par.usecase, B.PAR_TSTIME: utils.date_tool.getActdate(utils.date_tool.F_DIR)} job.popInstance() job = basic.program.Job("unit") job.par.setParameterArgs(jobargs) job.setProgram(step["args"][arg]) - print("Job initialisiert "+job.program+" in Verzeichnis "+getattr(job.par, "tsdir")) - myjob.m.logInfo("Job initialisiert "+job.program+" in Verzeichnis "+getattr(job.par, "tsdir")) - dirname = getattr(job.par, "tsdir") + print("Job initialisiert "+job.program+" in Verzeichnis "+getattr(job.par, B.PAR_TSDIR)) + myjob.m.logInfo("Job initialisiert "+job.program+" in Verzeichnis "+getattr(job.par, B.PAR_TSDIR)) + dirname = getattr(job.par, B.PAR_TSDIR) job.stopJob(1) job.popInstance() basic.program.Job.pushInstance(myjob) print("ende") job = myjob - if "testcase" in step["args"][arg]: + if B.PAR_TESTCASE in step["args"][arg]: if step["comp"] in testcases: - jobargs = {"application": myjob.par.application, "environment": myjob.par.environment, - "tcdir": testcases[step["comp"]] } + jobargs = {B.PAR_APP: myjob.par.application, B.PAR_ENV: myjob.par.environment, + B.PAR_TCDIR: testcases[step["comp"]] } else: - jobargs = {"application": myjob.par.application, "environment": myjob.par.environment, - "testcase": step["comp"], "tctime": utils.date_tool.getActdate(utils.date_tool.F_DIR)} + jobargs = {B.PAR_APP: myjob.par.application, B.PAR_ENV: myjob.par.environment, + B.PAR_TESTCASE: step["comp"], B.PAR_TCTIME: utils.date_tool.getActdate(utils.date_tool.F_DIR)} job.popInstance() job = basic.program.Job("unit") job.par.setParameterArgs(jobargs) job.setProgram(step["args"][arg]) - print("Job initialisiert "+job.program+" in Verzeichnis "+getattr(job.par, "tcdir")) - myjob.m.logInfo("Job initialisiert "+job.program+" in Verzeichnis "+getattr(job.par, "tcdir")) - dirname = getattr(job.par, "tcdir") + print("Job initialisiert "+job.program+" in Verzeichnis "+getattr(job.par, B.PAR_TCDIR)) + myjob.m.logInfo("Job initialisiert "+job.program+" in Verzeichnis "+getattr(job.par, B.PAR_TCDIR)) + dirname = getattr(job.par, B.PAR_TCDIR) testcases[step["comp"]] = dirname job.stopJob(1) job.popInstance() @@ -74,12 +74,10 @@ def start(myjob): if __name__ == '__main__': print(PROGRAM_NAME) - x = program.Job(PROGRAM_NAME) + x = basic.program.Job(PROGRAM_NAME) #m = message.Message(3) #m.closeMessage() x.startJob() - x.m.logInfo("hier eine LogInfo") - x.m.logDebug("hier eine DbugMeldung") x.m.logDebug(str(vars(x.par)) + "\n" + str(vars(x.conf))) if x.m.isRc("fatal"): x.stopJob() diff --git a/utils/data_const.py b/utils/data_const.py index b5350f6..7751d0d 100644 --- a/utils/data_const.py +++ b/utils/data_const.py @@ -5,7 +5,19 @@ constants for used for api-functions DDL_FILENAME = "DATASTRUCTURE" +DATA_NODE_TYPE = "type" +TYPE_STRING = "string" +TYPE_INT = "int" +TYPE_FLOAT = "float" +TYPE_DOUBLE = "double" +TYPE_DATE = "date" +TYPE_TIME = "time" +# fields in DDL DDL_FNULLABLE = "nullable" +DDL_FNAME = "field" +DDL_ACCEPTANCE = "acceptance" +DDL_KEY = "key" +DDL_TYPE = "type" DFILE_TYPE_YML = "yml" DFILE_TYPE_JSON = "json" diff --git a/utils/db_abstract.py b/utils/db_abstract.py index 8ba32c7..6e21f8c 100644 --- a/utils/db_abstract.py +++ b/utils/db_abstract.py @@ -281,17 +281,17 @@ class DbFcts(): def getDbValue(self, fo, value): if len(value.strip()) == 0 and fo[D.DDL_FNULLABLE] == B.SVAL_YES: return self.getDbNull() - if fo[B.DATA_NODE_TYPE] == B.TYPE_STRING: + if fo[D.DATA_NODE_TYPE] == D.TYPE_STRING: return "'"+value.strip()+"'" - elif fo[B.DATA_NODE_TYPE] == B.TYPE_INT: + elif fo[D.DATA_NODE_TYPE] == D.TYPE_INT: return value.strip() - elif fo[B.DATA_NODE_TYPE] == B.TYPE_DOUBLE: + elif fo[D.DATA_NODE_TYPE] == D.TYPE_DOUBLE: return self.getDbDouble(value) - elif fo[B.DATA_NODE_TYPE] == B.TYPE_FLOAT: + elif fo[D.DATA_NODE_TYPE] == D.TYPE_FLOAT: return self.getDbFloat(value) - elif fo[B.DATA_NODE_TYPE] == B.TYPE_DATE: + elif fo[D.DATA_NODE_TYPE] == D.TYPE_DATE: return self.getDbDate(value) - elif fo[B.DATA_NODE_TYPE] == B.TYPE_TIME: + elif fo[D.DATA_NODE_TYPE] == D.TYPE_TIME: return self.getDbTime(value) def getDbDouble(self, value): diff --git a/utils/match_const.py b/utils/match_const.py index 67a55c4..075477d 100644 --- a/utils/match_const.py +++ b/utils/match_const.py @@ -7,47 +7,53 @@ SIM_BUSINESS = "B" SIM_TECHNICAL = "T" SIM_DEFAULT = "BT" +M_FILEPATTERN = "filepattern" +M_SIDE_LONG = "long" +M_SIDE_SHORT = "short" +M_SIDE_A = "A" +M_SIDE_B = "B" + MATCH_SIDE_PREEXPECT = "preexpect" """ it implies the precondition of the expectation """ MATCH_DICT_PREEXPECT = { - "short": "SV", - "long": "Soll-Vorher", - "filepattern": "rsprecond" + M_SIDE_SHORT: "SV", + M_SIDE_LONG: "Soll-Vorher", + M_FILEPATTERN: "rsprecond" } MATCH_SIDE_POSTEXPECT = "postexpect" """ it implies the postcondition of the expectation - it is the expectation""" MATCH_DICT_POSTEXPECT = { - "short": "SN", - "long": "Soll-Nachher", - "filepattern": "rsprecond" + M_SIDE_SHORT: "SN", + M_SIDE_LONG: "Soll-Nachher", + M_FILEPATTERN: "rsprecond" } MATCH_SIDE_PREACTUAL = "preactual" """ it implies the precondition of the actual execution """ MATCH_DICT_PREACTUAL = { - "short": "IV", - "long": "Ist-Vorher", - "filepattern": "rsprecond" + M_SIDE_SHORT: "IV", + M_SIDE_LONG: "Ist-Vorher", + M_FILEPATTERN: "rsprecond" } MATCH_SIDE_POSTACTUAL = "postactual" """ it implies the postondition of the actual execution - it is the result """ MATCH_DICT_POSTACTUAL = { - "short": "IN", - "long": "Ist-Nachher", - "filepattern": "rsprecond" + M_SIDE_SHORT: "IN", + M_SIDE_LONG: "Ist-Nachher", + M_FILEPATTERN: "rsprecond" } MATCH_SIDE_PRESTEP = "prestep" """ it implies the postcondition of a preceding step of the actual execution - the preceding step must be configured in the component""" MATCH_DICT_PRESTEP = { - "short": "VS", - "long": "Vorhergehender Schritt (Nachher)", - "filepattern": "rsprecond" + M_SIDE_SHORT: "VS", + M_SIDE_LONG: "Vorhergehender Schritt (Nachher)", + M_FILEPATTERN: "rsprecond" } MATCH_SIDE_TESTCASE = "testexample" """ it implies the postcondition of an exemplary testcase - the exemplary testcase must be parametrized """ MATCH_DICT_TESTCASE = { - "short": "VT", - "long": "Vergleichstestfall (Nachher)", - "filepattern": "rsprecond" + M_SIDE_SHORT: "VT", + M_SIDE_LONG: "Vergleichstestfall (Nachher)", + M_FILEPATTERN: "rsprecond" } MATCH_SIDES = [MATCH_SIDE_PREEXPECT, MATCH_SIDE_POSTEXPECT, MATCH_SIDE_PREACTUAL, MATCH_SIDE_POSTACTUAL, MATCH_SIDE_PRESTEP, MATCH_SIDE_TESTCASE] diff --git a/utils/match_tool.py b/utils/match_tool.py index 3cbfc36..c883a26 100644 --- a/utils/match_tool.py +++ b/utils/match_tool.py @@ -10,6 +10,7 @@ import utils.report_tool import basic.program import basic.constants as B import utils.match_const as M +import utils.data_const as D # ------------------------------------------------------------ """ @@ -33,6 +34,7 @@ class Matching(): self.mode = "" self.matchtype = "" self.cssClass = "result0" + self.preIds = {} def setData(self, tdata, match): """ @@ -41,17 +43,21 @@ class Matching(): :param match: kind of actual match :return: """ - sideA = M.MATCH[match]["A"] - sideB = M.MATCH[match]["B"] + sideA = M.MATCH[match][M.M_SIDE_A] + sideB = M.MATCH[match][M.M_SIDE_B] self.sideA = tdata[sideA]["data"] self.sideB = tdata[sideB]["data"] - self.matchfiles["A"] = tdata[sideA]["path"] - self.matchfiles["B"] = tdata[sideB]["path"] + self.matchfiles[M.M_SIDE_A] = tdata[sideA]["path"] + self.matchfiles[M.M_SIDE_B] = tdata[sideB]["path"] self.matchtype = match self.mode = M.MATCH[match]["mode"] self.setDiffHeader() self.report = utils.report_tool.Report.getInstance() self.resetHits() + if match == M.MATCH_PRECOND: + self.preIds = {} # structure db:scheme:table:... + # get ddl + # for _data: for ddl._header: if SIM_TECHNICAL in ddl[h][key]: preIds.append(_data[h]) def resetHits(self): self.linksA = {} @@ -105,10 +111,10 @@ class Matching(): htmltxt += "" htmltxt += "" htmltxt += "

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

" - htmltxt += "

" + M.MATCH[M.MATCH[matching.matchtype]["A"]]["long"] + ": " + matching.matchfiles[ - "A"] + "

" - htmltxt += "

" + M.MATCH[M.MATCH[matching.matchtype]["B"]]["long"] + ": " + matching.matchfiles[ - "B"] + "


" + htmltxt += "

" + M.MATCH[M.MATCH[matching.matchtype][M.M_SIDE_A]][M.M_SIDE_LONG] + ": " + matching.matchfiles[ + M.M_SIDE_A] + "

" + htmltxt += "

" + M.MATCH[M.MATCH[matching.matchtype][M.M_SIDE_B]][M.M_SIDE_LONG] + ": " + matching.matchfiles[ + M.M_SIDE_B] + "


" matching.htmltext = htmltxt def setDiffFooter(self): @@ -224,15 +230,15 @@ def setMatchkeys(matching, path): keys = {} for f in ddl: job.debug(verify, "ddl " + f) - if ("key" in ddl[f]) and (len(ddl[f]["key"]) > 0): - b = ddl[f]["key"].split(":") + if (D.DDL_KEY in ddl[f]) and (len(ddl[f][D.DDL_KEY]) > 0): + b = ddl[f][D.DDL_KEY].split(":") if (len(b) != 2): - raise Exception("falsch formatierter Schluessel " + ddl[f]["key"]) + raise Exception("falsch formatierter Schluessel " + ddl[f][D.DDL_KEY]) if (not b[1].isnumeric()): - raise Exception("falsch formatierter Schluessel " + ddl[f]["key"]) + raise Exception("falsch formatierter Schluessel " + ddl[f][D.DDL_KEY]) k = "k"+b[0]+""+b[1].zfill(2) job.debug(verify, "ddl " + f) - keys[k] = {"ktyp": b[0], "field": ddl[f]["feld"], "type": ddl[f]["type"], "rule": ddl[f]["acceptance"]} + keys[k] = {"ktyp": b[0], D.DDL_FNAME: ddl[f][D.DDL_FNAME], D.DDL_TYPE: ddl[f][D.DDL_TYPE], "rule": ddl[f][D.DDL_ACCEPTANCE]} matching.matchkeys = keys job.debug(verify, "ddl " + json.dumps(keys)) @@ -249,10 +255,10 @@ def getSimilarity(matching, rA, rB, i, simorder=M.SIM_DEFAULT): topTsim = "" for k in sorted(matching.matchkeys): if M.SIM_TECHNICAL in k: - mTsim += getStringSimilarity(str(rA[matching.matchkeys[k]["field"]]), str(rB[matching.matchkeys[k]["field"]])) + mTsim += getStringSimilarity(str(rA[matching.matchkeys[k][D.DDL_FNAME]]), str(rB[matching.matchkeys[k][D.DDL_FNAME]])) topTsim += "99" if M.SIM_BUSINESS in k: - mTsim += getStringSimilarity(str(rA[matching.matchkeys[k]["field"]]), str(rB[matching.matchkeys[k]["field"]])) + mTsim += getStringSimilarity(str(rA[matching.matchkeys[k][D.DDL_FNAME]]), str(rB[matching.matchkeys[k][D.DDL_FNAME]])) topTsim += "99" if mBsim == topBsim and mTsim == topTsim: @@ -378,12 +384,12 @@ def matchArray(matching, A, B, path): if (x == "_data"): break table = x report = utils.report_tool.Report.getInstance() - report.setPaths(getattr(job.par, "testcase"), matching.comp.name, table, matching.matchtype, - matching.matchfiles["A"], matching.matchfiles["B"]) + 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) + "
") - htmltext = report.getTitle(getattr(job.par, "testcase"), matching.comp.name, table, matching.matchtype) - htmltext += report.getComponentHead(getattr(job.par, "testcase"), matching.comp.name, table, matching.matchtype) - htmltext += report.getArtefactBlock(getattr(job.par, "testcase"), matching.comp.name, table, matching.matchtype) + htmltext = report.getTitle(getattr(job.par, B.PAR_TESTCASE), matching.comp.name, table, matching.matchtype) + htmltext += report.getComponentHead(getattr(job.par, B.PAR_TESTCASE), matching.comp.name, table, matching.matchtype) + htmltext += report.getArtefactBlock(getattr(job.par, B.PAR_TESTCASE), matching.comp.name, table, matching.matchtype) htmltext += compareRows(matching, path) matching.htmltext += htmltext @@ -400,7 +406,7 @@ def compareRows(matching, path): htmltext = "" for f in ddl[B.DATA_NODE_HEADER]: job.debug(verify, "ddl " + f + " ") - header.append({"field": f, "type": ddl[f]["type"], "acceptance": ddl[f]["acceptance"]}) + header.append({D.DDL_FNAME: f, D.DDL_TYPE: ddl[f][D.DDL_TYPE], D.DDL_ACCEPTANCE: ddl[f][D.DDL_ACCEPTANCE]}) htmltext += "" htmltext += "" matching.difftext = htmltext @@ -410,33 +416,48 @@ def compareRows(matching, path): htmltext += compareRow(matching, header, matching.sideA[int(extractKeyI(k))], matching.sideB[int(extractKeyI(matching.linksA[k]))]) else: - htmltext += markRow(matching, header, matching.sideA[int(extractKeyI(k))], "A") + htmltext += markRow(matching, header, matching.sideA[int(extractKeyI(k))], M.M_SIDE_A) matching.setCssClass("result3") for k in sorted(matching.linksB): if (not matching.isHitB(k)): - htmltext += markRow(matching, header, matching.sideB[int(extractKeyI(k))], "B") + if ignorePrecond(matching): + continue + htmltext += markRow(matching, header, matching.sideB[int(extractKeyI(k))], M.M_SIDE_B) matching.setCssClass("result2") htmltext += "
" + f + "
" matching.difftext += "" return htmltext +def ignorePrecond(matching): + job = basic.program.Job.getInstance() + verify = int(job.getDebugLevel("match_tool")) - 1 + if not matching.matchtype == M.MATCH_POSTCOND: + return False + if not hasattr(job.par, "matchdelta"): + return False + if len(matching.preIds) < 1: + return False + + return False + + def markRow(matching, header, row, side): job = basic.program.Job.getInstance() verify = int(job.getDebugLevel("match_tool")) - 4 text = "" cssClass = "" for f in header: - if not f["field"] in row: + if not f[D.DDL_FNAME] in row: val = "" cssClass = "novalue" - elif side == "A": - res = getEvaluation(matching, f["type"], f["acceptance"], row[f["field"]], "") - val = str(row[f["field"]]) + elif side == M.M_SIDE_A: + res = getEvaluation(matching, f[D.DDL_TYPE], f[D.DDL_ACCEPTANCE], row[f[D.DDL_FNAME]], "") + val = str(row[f[D.DDL_FNAME]]) cssClass = res[1] else: - res = getEvaluation(matching, f["type"], f["acceptance"], "", row[f["field"]]) - val = str(row[f["field"]]) + res = getEvaluation(matching, f[D.DDL_TYPE], f[D.DDL_ACCEPTANCE], "", row[f[D.DDL_FNAME]]) + val = str(row[f[D.DDL_FNAME]]) cssClass = res[2] text += "" + val + "" text = "" \ @@ -459,20 +480,20 @@ def compareRow(matching, header, rA, rB): classB = "novalue" for f in header: print(f) - if f["field"] in rA and f["field"] in rB: - res = getEvaluation(matching, f["type"], f["acceptance"], rA[f["field"]], rB[f["field"]]) + if f[D.DDL_FNAME] in rA and f[D.DDL_FNAME] in rB: + res = getEvaluation(matching, f[D.DDL_TYPE], f[D.DDL_ACCEPTANCE], rA[f[D.DDL_FNAME]], rB[f[D.DDL_FNAME]]) match = res[0] classA = res[1] classB = res[2] - valA = str(rA[f["field"]]) - valB = str(rB[f["field"]]) - elif f["field"] in rA: - valA = str(rA[f["field"]]) + valA = str(rA[f[D.DDL_FNAME]]) + valB = str(rB[f[D.DDL_FNAME]]) + elif f[D.DDL_FNAME] in rA: + valA = str(rA[f[D.DDL_FNAME]]) match = "ddl" classA = "acceptA" classB = "acceptB" - elif f["field"] in rB: - valB = str(rB[f["field"]]) + elif f[D.DDL_FNAME] in rB: + valB = str(rB[f[D.DDL_FNAME]]) match = "ddl" classA = "acceptA" classB = "acceptB" @@ -496,7 +517,7 @@ def compareRow(matching, header, rA, rB): matching.setCssClass("result1") if allident: return "" + textA + "" - text = "" + M.MATCH[M.MATCH[matching.matchtype]["A"]]["short"] + "" + textA + "" + text = "" + M.MATCH[M.MATCH[matching.matchtype][M.M_SIDE_A]]["short"] + "" + textA + "" text += "" + M.MATCH[matching.matchtype]["shortB"] + "" + textB + "" matching.difftext += text return text diff --git a/utils/report_tool.py b/utils/report_tool.py index 77ae002..ad3f5b3 100644 --- a/utils/report_tool.py +++ b/utils/report_tool.py @@ -35,7 +35,10 @@ REP_TS = "Testsuite" REP_COMP = "Komponente" REP_ART = "Artefakt" -class Report(): +TOOL_NAME = "report_tool" + + +class Report: __instance = None @staticmethod @@ -152,7 +155,7 @@ class Report(): def getHeader(self): job = basic.program.Job.getInstance() - verify = int(job.getDebugLevel("report_tool"))-1 + verify = int(job.getDebugLevel(TOOL_NAME))-1 htmltxt = "" htmltxt += "" htmltxt += utils.css_tool.getInternalStyle("diffFiles") @@ -175,7 +178,7 @@ class Report(): htmlBody = ""+testcase+"" for c in self.report[testcase]: cssClass = self.getCssClass(testcase, c, "") - htmlBody += "" + testcase + "" + htmlBody += ""+testcase+"" return htmlHead+""+htmlBody+"" def getTestcaseHead(self, testcase="", component="", artefact="", matchtype=""): @@ -187,7 +190,8 @@ class Report(): def getComponentHead(self, testcase="", component="", artefact="", matchtype=""): job = basic.program.Job.getInstance() - return "

"+REP_COMP+" "+component+"

" + html = "

"+REP_COMP+" "+component+"

" + return html def getArtefactBlock(self, testcase, component, artefact, matchtype=""): job = basic.program.Job.getInstance() @@ -222,7 +226,7 @@ class Report(): def reportTestcase(self, testcase): job = basic.program.Job.getInstance() - verify = int(job.getDebugLevel("report_tool")) - 1 + verify = int(job.getDebugLevel(TOOL_NAME)) - 1 html = self.getHeader() html += self.getTitle(testcase) html += self.getOverview(testcase) @@ -239,7 +243,7 @@ class Report(): def extractTestcase(self, testcase, html): job = basic.program.Job.getInstance() - verify = int(job.getDebugLevel("report_tool")) - 1 + verify = int(job.getDebugLevel(TOOL_NAME)) - 1 if not testcase in self.report: self.report = {} overview = re.findall("", html) @@ -253,7 +257,7 @@ class Report(): def reportTestsuite(self): job = basic.program.Job.getInstance() - verify = int(job.getDebugLevel("report_tool")) - 1 + verify = int(job.getDebugLevel(TOOL_NAME)) - 1 testinstances = getattr(job.par, "testinstances") html = self.getHeader() html += self.getTitle() @@ -276,6 +280,6 @@ def report_testsuite(tcpath): :return: html-code with result-codes of each component """ job = basic.program.Job.getInstance() - verify = -0+job.getDebugLevel("report_tool") + verify = -0+job.getDebugLevel(TOOL_NAME) job.debug(verify, "writeDataTable " + str(tcpath)) diff --git a/utils/tdata_tool.py b/utils/tdata_tool.py index 3db778c..f0979fd 100644 --- a/utils/tdata_tool.py +++ b/utils/tdata_tool.py @@ -217,7 +217,7 @@ def getTabContent(msg, data, path): elif len(path) == 4: return data[path[0]][path[1]][path[2]][path[3]] -def readCsv(msg, filename, comp): +def readCsv(msg, filename, comp, aliasNode=""): job = basic.program.Job.getInstance() verify = -1+job.getDebugLevel(TOOL_NAME) job.debug(verify, "readCsv " + filename) @@ -243,7 +243,7 @@ def readCsv(msg, filename, comp): cnt = len(fields) job.debug(verify, str(state) + " cnt " + str(cnt)) j = 0 - for i in range(1, cnt-1): + for i in range(1, cnt): if fields[0][0:1] == "_": startCols += 1 continue @@ -254,7 +254,13 @@ def readCsv(msg, filename, comp): cnt = j job.debug(verify, str(state) + " " + str(cnt) + " cols " + str(columns)) elif state >= 2 and len(testline) > 2: - if state == 2 and not fields[0].isspace(): + if state == 2 and not aliasNode.isspace(): + struct = aliasNode.split(":") + for x in struct: + if len(x) > 2: + nodes.append(x) + job.debug(verify, str(state) + " nodes " + str(nodes)) + elif state == 2 and not fields[0].isspace(): struct = fields[0].split(":") for x in struct: if len(x) > 2: @@ -262,7 +268,7 @@ def readCsv(msg, filename, comp): job.debug(verify, str(state) + " nodes " + str(nodes)) state = 3 row = {} - for i in range(startCols, cnt-1): + for i in range(startCols, cnt): row[columns[i-startCols]] = fields[i] job.debug(verify, str(state) + " row " + str(row)) data.append(row) @@ -280,7 +286,7 @@ def setSubnode(i, nodes, data, tree): print("setSubnode " + str(i) + ": " + ": " + str(tree)) if i >= len(nodes): print("setSubnode a " + str(i)) - tree["_data"] = data + tree[B.DATA_NODE_DATA] = data elif tree is not None and nodes[i] in tree.keys(): print("setSubnode b " + str(i)) tree[nodes[i]] = setSubnode(i+1, nodes, data, tree[nodes[i]]) diff --git a/utils/xml_tool.py b/utils/xml_tool.py index 20647c8..2433ac0 100644 --- a/utils/xml_tool.py +++ b/utils/xml_tool.py @@ -44,7 +44,7 @@ class register(): ausgabe = self.schreibeSegmentkopf(ausgabe, content) print("ausgabe vorher: "+str(ausgabe)) ausgabe["nachricht"]["datensegment"] = [] - for row in content["tabelle"]["person"]["_data"]: + for row in content["tabelle"]["person"][B.DATA_NODE_DATA]: print ("foreach row") print (row) satz = {} @@ -597,14 +597,14 @@ class fcts: return baum # Wert ermitteln aus Content if logdebug >= 3 : print (str(index) +" tabelle "+str(content)) - if (not content["tabelle"][tabelle]["_data"][int(index)-1]): + if (not content["tabelle"][tabelle][B.DATA_NODE_DATA][int(index)-1]): if logdebug >= 2 : print ("Zeile fehlt") return baum - if logdebug >= 3 : print (content["tabelle"][tabelle]["_data"][int(index)-1]) - if (not feld in content["tabelle"][tabelle]["_data"][int(index)-1].keys()): + if logdebug >= 3 : print (content["tabelle"][tabelle][B.DATA_NODE_DATA][int(index)-1]) + if (not feld in content["tabelle"][tabelle][B.DATA_NODE_DATA][int(index)-1].keys()): if logdebug >= 2 : print ("Feld fehlt") return baum - wert = content["tabelle"][tabelle]["_data"][int(index)-1][feld] + wert = content["tabelle"][tabelle][B.DATA_NODE_DATA][int(index)-1][feld] baum = fcts.setMerkmal(baum, npath, wert) #print("ausgabe "+str(baum)) return baum