diff --git a/basic/constants.py b/basic/constants.py index c388977..d4a5783 100644 --- a/basic/constants.py +++ b/basic/constants.py @@ -39,6 +39,9 @@ PAR_MODUS = 'modus' PAR_COMP = 'component' PAR_FCT = 'function' PAR_TOOL = 'tool' +PAR_STEP = 'step' +PAR_DESCRIPT = 'desription' +""" """ PAR_TESTCASE = "testcase" PAR_TESTSUITE = "usecase" """ name of testcase extracted from PAR_TCDIR """ diff --git a/basic/message.py b/basic/message.py index 6f5508b..c9b4397 100644 --- a/basic/message.py +++ b/basic/message.py @@ -219,7 +219,7 @@ class Message: def log(self, prio, text): """ eigentliche Schreibroutine: hierin wird debug-Level beruecksichtgigt""" - if (int(prio) <= int(self.level)) and (self.componente is None): + if (int(prio) <= int(self.level)) and (self.componente is None): # and self.logfile.closed == False: self.logfile.write(text + "\n") elif (int(prio) <= int(self.level)): self.messages.append(text) @@ -228,7 +228,7 @@ class Message: def debug(self, prio, text): """ eigentliche Schreibroutine: hierin wird debug-Level beruecksichtgigt""" - if (int(prio) < int(self.level)+1): + if (int(prio) < int(self.level)+1) : #and self.debugfile.closed == False: self.debugfile.write(text + "\n") def merge(self, submsg): diff --git a/basic/program.py b/basic/program.py index a409cd1..38c9d5f 100644 --- a/basic/program.py +++ b/basic/program.py @@ -12,7 +12,7 @@ import copy import yaml, os from datetime import datetime - +import basic.constants as B import basic.message import basic.message import basic.componentHandling @@ -36,7 +36,7 @@ jobdef = { "logdir": "{job.par.envdir}/{log}/log_{time}.txt" }, "test_executer": { "pardef": "", - "pfilesource" : "", + "pfilesource" : "tsparfile", "pfiletarget" : "tsparfile", "basedir": "tsbase", "dirname": "tsdir", @@ -55,6 +55,20 @@ jobdef = { "basedir": "tcbase", "dirname": "tcdir", "logdir": "{job.par.tcdir}/{log}/log_{tctime}.txt" }, + "collect_testcase": { + "pardef": "tcdir", # ",tdtyp,tdsrc,tdname", + "pfilesource" : "envparfile", + "pfiletarget" : "tcparfile", + "basedir": "tcbase", + "dirname": "tcdir", + "logdir": "{job.par.tcdir}/{log}/log_{tctime}.txt" }, + "compare_testcase": { + "pardef": "tcdir", # ",tdtyp,tdsrc,tdname", + "pfilesource" : "envparfile", + "pfiletarget" : "tcparfile", + "basedir": "tcbase", + "dirname": "tcdir", + "logdir": "{job.par.tcdir}/{log}/log_{tctime}.txt" }, "test_system": { "pardef": "tcdir,tdtyp,tdsrc,tdname", "pfilesource": "tsparfile", @@ -292,6 +306,7 @@ class Parameter: parser.add_argument('-c', '--component', action='store') # PAR_COMP parser.add_argument('-f', '--function', action='store') # PAR_FCT parser.add_argument('-t', '--tool', action='store') # PAR_TOOL + parser.add_argument('-s', '--'+B.PAR_STEP, action='store') # PAR_STEP # parser.add_argument('-t', '--typ', default='einzel', action='store') # parser.add_argument('-d', '--dir', action='store') args = parser.parse_args() @@ -321,6 +336,7 @@ class Parameter: job = Job.getInstance() print("setParLoaded " ) readedPar = job.loadParameter() + if readedPar is not None: for k in readedPar["par"].keys(): if not hasattr(self, k): @@ -328,7 +344,7 @@ class Parameter: def setJobAttr(self, key, val): setattr(self, key, val) - self.parstring = self.parstring + " --" + key + " " + val + self.parstring = self.parstring + " --" + key + " " + str(val) def getJobPar(self, key): a = key.split(":") diff --git a/test/test_date.py b/test/test_date.py new file mode 100644 index 0000000..e69de29 diff --git a/test/test_report.py b/test/test_report.py new file mode 100644 index 0000000..acce6d6 --- /dev/null +++ b/test/test_report.py @@ -0,0 +1,158 @@ +import unittest +import os + +import basic.program +import basic.program +import components.component +from basic.componentHandling import ComponentManager +import init_testcase +import test_executer +import test.constants +import utils.report_tool +import utils.match_tool as M +import basic.constants as B + +HOME_PATH = test.constants.HOME_PATH + +class MyTestCase(unittest.TestCase): + + def getReport(self): + job = basic.program.Job.getInstance() + report = utils.report_tool.Report() + archiv = job.conf.confs[B.SUBJECT_PATH][B.ATTR_PATH_ARCHIV]+"/" + i = 0 + for m in M.MATCH_TYPES: + report.setPaths("TC0001", "comp01", "arte01", m, archiv+"path0111"+str(i), archiv+"path0111"+str(i)+"02") + report.setPaths("TC0001", "comp01", "arte02", m, archiv+"path0112"+str(i)+"", archiv+"path0112"+str(i)+"02") + report.setPaths("TC0001", "comp02", "arte01", m, archiv+"path0121"+str(i)+"", archiv+"path0121"+str(i)+"02") + report.setPaths("TC0002", "comp01", "arte01", m, archiv+"path0211"+str(i)+"", archiv+"path0211"+str(i)+"02") + report.setPaths("TC0002", "comp02", "arte01", m, archiv+"path0221"+str(i)+"", archiv+"path0221"+str(i)+"02") + report.setMatchResult("TC0001", "comp01", "arte01", m, "result" + str(i), "" + str(i) + "
") + report.setMatchResult("TC0001", "comp01", "arte02", m, "result" + str(i), "" + str(i) + "
") + report.setMatchResult("TC0001", "comp02", "arte01", m, "result" + str(1), "" + str(i) + "
") + report.setMatchResult("TC0002", "comp01", "arte01", m, "result" + str(1), "" + str(i) + "
") + report.setMatchResult("TC0002", "comp02", "arte01", m, "result" + str(i), "" + str(i) + "
") + i += 1 + if i > 4: + i = 0 + return report + + def test_cssClass(self): + job = basic.program.Job("unit") + args = { "application": "TEST", "environment": "ENV01", "modus": "unit", "tstime": "2022-03-19_12-09-09", + "tsdir": '/home/ulrich/6_Projekte/Programme/datest/test/conf/lauf/testlauf/TST001_2022-03-19_12-09-09', + "step": 2 } + # "usecase": "TST001", "tstime": "2022-03-17_17-28"} + job.par.setParameterArgs(args) + job.setProgram("test_executer") + report = self.getReport() + i = 0 + for m in M.MATCH_TYPES: + cssClass = report.getCssClass("TC0001", "comp01", "arte01", m) + print(m + " test0111 " + cssClass) + self.assertEqual(cssClass, "result"+str(i)) + i += 1 + if i > 4: + i = 0 + cssClass = report.getCssClass("TC0002", "comp01", "arte01", m) + print(m + " test0121 " + cssClass) + cssClass = report.getCssClass("TC0001", "comp01", "arte02") + self.assertEqual(cssClass, "result4") + print("test0112 "+cssClass) + cssClass = report.getCssClass("TC0001", "comp02", "arte01") + print("test0121 "+cssClass) + self.assertEqual(cssClass, "result1") + cssClass = report.getCssClass("TC0002", "comp01") + self.assertEqual(cssClass, "result1") + cssClass = report.getCssClass("TC0002") + self.assertEqual(cssClass, "result4") + + def test_title(self): + job = basic.program.Job.getInstance() + print(" ---------- test_title") + setattr(job.par, "testsuite", "TST001") + report = self.getReport() + html = report.getTitle("TC0001", "comp01", "arte01", M.MATCH_POSTCOND) + print(html) + html = report.getTitle("TC0001") + self.assertEqual((utils.report_tool.REP_TITLE in html), True) + self.assertEqual((utils.report_tool.REP_TC in html), True) + self.assertEqual(("TC0001" in html), True) + html = report.getTitle() + self.assertEqual((utils.report_tool.REP_TITLE in html), True) + self.assertEqual((utils.report_tool.REP_TS in html), True) + self.assertEqual(("TST001" in html), True) + + def test_overview(self): + job = basic.program.Job.getInstance() + print(" ---------- test_overview") + report = self.getReport() + html = report.getOverview("TC0001") + print(html) + + def test_filename(self): + job = basic.program.Job.getInstance() + setattr(job.par, "testcase", "TC0001") + setattr(job.par, "tctime", "2022-03-23_21-23-32") + print(" ---------- test_filename") + cm = basic.componentHandling.ComponentManager() + for c in ["comp02"]: + comp = components.component.Component() + comp.name = c + basic.componentHandling.comps[c] = comp + report = self.getReport() + html = report.getFilepath("TC0001", "comp02", "arte01", M.MATCH_POSTCOND) + print(html) + + + def test_headlines(self): + job = basic.program.Job.getInstance() + setattr(job.par, "testcase", "TC0001") + setattr(job.par, "tctime", "2022-03-23_21-23-32") + cm = basic.componentHandling.ComponentManager() + for c in ["comp02"]: + comp = components.component.Component() + comp.name = c + basic.componentHandling.comps[c] = comp + print(" ---------- test_headlines") + report = self.getReport() + html = report.getTestcaseHead("TC0001") + print(html) + html = report.getComponentHead("TC0001", "comp02") + print(html) + html = report.getArtefactBlock("TC0001", "comp02", "arte01") + print(html) + + def test_reportS(self): + job = basic.program.Job.getInstance() + setattr(job.par, "testcase", "TC0001") + 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() + for compname in ["comp01", "comp02"]: + conf = {} + comp = components.component.Component() + comp.files = { "A": "/home/match/pre.csv", "B": "/home/match/post.csv"} + comp.name = compname + comp.conf = conf + basic.componentHandling.comps[compname] = comp + html_1 = report.reportTestcase("TC0001") + print(html_1) + print("<<---------------------------------- TC0001") + report.extractTestcase("TC0001", html_1) + setattr(job.par, "testcase", "TC0002") + html_2 = report.reportTestcase("TC0002") + print(html_2) + print("<<---------------------------------- TC0002") + report.extractTestcase("TC0002", html_2) + setattr(job.par, "testsuite", "TST001") + html = report.reportTestsuite() + print(html) + print("<<---------------------------------- TST001") + +if __name__ == '__main__': + unittest.main() + +# report.setPaths("TC0001", "comp01", "arte01", m, archiv+"path0111"+str(i), archiv+"path0111"+str(i)+"02") diff --git a/utils/config_tool.py b/utils/config_tool.py index 9f2474e..fcbcd56 100644 --- a/utils/config_tool.py +++ b/utils/config_tool.py @@ -114,6 +114,21 @@ def getConfValue(attribute, comp): return "" +def getAttr(o, name): + #print("hasAttr " + str(type(o))+" "+name) + if (isinstance(o, dict)): + if (name in o.keys()): + #print("hasAttr dict ok " + str(type(o))) + return o[name] + #print("hasAttr dict "+str(type(o))) + elif (isinstance(o, list)): + pass + #print("hasAttr list "+str(type(o))) + elif hasattr(o, name): + #print("hasAttr class ok "+str(type(o))) + return getattr(o, name) + return False + def hasAttr(o, name): #print("hasAttr " + str(type(o))+" "+name) diff --git a/utils/date_tool.py b/utils/date_tool.py index b0278c9..299da99 100644 --- a/utils/date_tool.py +++ b/utils/date_tool.py @@ -8,5 +8,8 @@ import datetime F_DIR = "%Y-%m-%d_%H-%M-%S" def getActdate(format): return getFormatdate(datetime.datetime.now(), format) + + def getFormatdate(date, format): + """ it return the date as string in the format """ return date.strftime(format) diff --git a/utils/db_abstract.py b/utils/db_abstract.py index c6f1a08..394da81 100644 --- a/utils/db_abstract.py +++ b/utils/db_abstract.py @@ -201,6 +201,8 @@ class DbFcts(): raise Exception("method is not implemented") def loadDdl(self): + """" load the DDL for each database-table + the ddl are mostly stored as csv in the component-folder """ job = basic.program.Job.getInstance() if (B.DATA_NODE_DDL in self.comp.conf): return diff --git a/utils/match_tool.py b/utils/match_tool.py index 8a322d3..20b8009 100644 --- a/utils/match_tool.py +++ b/utils/match_tool.py @@ -6,6 +6,7 @@ # --------------------------------------------------------------------------------------------------------- import json import utils.css_tool +import utils.report_tool import basic.program import basic.constants as B # ------------------------------------------------------------ @@ -82,6 +83,7 @@ MATCH = { "longA": "Soll-Vorher", "longB": "Ist-Vorher", "mode": "info", + "filename": "01_Vorbedingungen", "title": "Pruefung Vorbedingung (Soll-Vorher - Ist-Vorher)" }, MATCH_POSTCOND: { @@ -92,6 +94,7 @@ MATCH = { "longA": "Soll-Nachher", "longB": "Ist-Nachher", "mode": "hard", + "filename": "00_Fachabgleich", "title": "Fachliche Auswertung (Soll-Nachher - Ist-Nachher)" }, MATCH_SUCCESS: { @@ -102,6 +105,7 @@ MATCH = { "longA": "Ist-Vorher", "longB": "Ist-Nachher", "mode": "action", + "filename": "04_Ablauf", "title": "Ablauf-Differenz (Ist-Vorher - Ist-Nachher)" }, MATCH_PRESTEP: { @@ -112,6 +116,7 @@ MATCH = { "longA": "Vor-Schritt", "longB": "Ist-Nachher", "mode": "action", + "filename": "02_Vorschritt", "title": "Schritt-Differenz (Vorschritt-Nachher - Ist-Nachher)" }, MATCH_TESTEXAMPLE: { @@ -122,11 +127,11 @@ MATCH = { "longA": "Vor-Schritt", "longB": "Ist-Nachher", "mode": "action", + "filename": "03_Vergleichstestfall", "title": "Schritt-Differenz (Vorschritt-Nachher - Ist-Nachher)" }, } - class Matching(): def __init__(self, comp): self.comp = comp @@ -150,11 +155,14 @@ class Matching(): :param match: kind of actual match :return: """ - self.sideA = tdata[MATCH[match]["A"]] - self.sideB = tdata[MATCH[match]["B"]] + self.sideA = tdata[MATCH[match]["A"]]["data"] + self.sideB = tdata[MATCH[match]["B"]]["data"] + self.matchfiles["A"] = tdata[MATCH[match]["A"]]["path"] + self.matchfiles["B"] = tdata[MATCH[match]["B"]]["path"] self.matchtype = match self.mode = MATCH[match]["mode"] self.setDiffHeader() + self.report = utils.report_tool.Report.getInstance() def resetHits(self): self.linksA = {} @@ -163,8 +171,6 @@ class Matching(): self.matchkeys = {} def isHitA(self, key): - print("isHitA "+str(key)) - for k in self.linksA: print(k) return ((key in self.linksA) and (self.linksA[key] != "null")) def isHitB(self, key): return ((key in self.linksB) and (self.linksB[key] != "null")) @@ -333,9 +339,10 @@ def matchTree(matching): """ job = basic.program.Job.getInstance() verify = int(job.getDebugLevel("match_tool"))-4 - job.debug(verify, "matching "+matching.mode) + job.debug(verify, "..>> start matching "+matching.mode) matchElement(matching, matching.sideA, matching.sideB, "") matching.setDiffFooter() + job.debug(verify, "..>> ende matching "+matching.htmltext) return matching.htmltext def matchElement(matching, A, B, path): @@ -388,37 +395,53 @@ def matchDict(matching, A, B, path): job.debug(verify, "matchDict "+path) if (A is not None): for k in A: - print(k) - if k == "_match": + job.debug(verify, "matchDict 400 " + k + ".") + if k in ["_match"]: continue if (B is not None) and (B[k]): if (isinstance(A[k], dict)): A[k]["_match"] = "Y" if (isinstance(B[k], dict)): B[k]["_match"] = "Y" + job.debug(verify, "matchDict 404 " + k + "." + path) matchElement(matching, A[k], B[k], path+":"+k) else: if (isinstance(A[k], dict)): A[k]["_match"] = "N" + job.debug(verify, "matchDict 408 " + path) matchElement(matching, A[k], None, path+":"+k) if (B is not None): for k in B: - if k == "_match": + job.debug(verify, "matchDict 412 " + k + ".") + if k in ["_match"]: continue if (A is not None) and (A[k]): continue - else: + elif (A is None) or (k not in A): if (A is not None) and (isinstance(A[k], dict)): B[k]["_match"] = "N" + job.debug(verify, "matchDict 418 " + k + "." + path) matchElement(matching, None, B[k], path+":"+k) + job.debug(verify, "matchDict 420 ...<<---") return matching def matchArray(matching, A, B, path): """ matches the datarows of the datatree """ job = basic.program.Job.getInstance() - verify = int(job.getDebugLevel("match_tool"))-1 - job.debug(verify, "matchArray "+path) + verify = int(job.getDebugLevel("match_tool"))-4 + job.debug(verify, "matchArray "+path+"\n.."+matching.htmltext) matching.sideA = A matching.sideB = B matchBestfit(matching, path) matchRestfit(matching) - htmltext = compareRows(matching, path) + a = path.split(":") + for x in a: + 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.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 += compareRows(matching, path) matching.htmltext += htmltext def compareRows(matching, path): @@ -426,15 +449,11 @@ def compareRows(matching, path): job = basic.program.Job.getInstance() verify = int(job.getDebugLevel("match_tool"))-1 ddl = matching.getTableDdl(path) + report = utils.report_tool.Report.getInstance() table = "" - a = path.split(":") - for x in a: - if (x == "_data"): break - table = x header = [] - htmltext = "

Tabelle : "+table+"

" - htmltext += "" - htmltext += "" + # "

Tabelle : "+table+"

" + 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"]}) diff --git a/utils/path_tool.py b/utils/path_tool.py index 3ec0dc4..1bdc00b 100644 --- a/utils/path_tool.py +++ b/utils/path_tool.py @@ -14,7 +14,7 @@ import basic.constants as B def getKeyValue(key, comp=None): job = basic.program.Job.getInstance() - verify = job.getDebugLevel("path_tool") + verify = job.getDebugLevel("path_tool")-4 pt = PathConf.getInstance() job.debug(verify, "getKeyValue " + key) if 'job.par' in key: @@ -30,7 +30,7 @@ def getKeyValue(key, comp=None): raise Exception("Component is missing for "+key) if not utils.config_tool.hasAttr(comp, key[5:]): pass - pass + return utils.config_tool.getAttr(comp, key[5:]) elif 'env.' in key: #if key[4:] pass @@ -61,6 +61,7 @@ def composePatttern(pattern, comp): l = re.findall('\{.*?\}', pattern) job.debug(verify, l) for pat in l: + print(str(max) + ": " + pattern + ": " + pat) pit = getKeyValue(pat[1:-1], comp) job.debug(verify, str(max) + ": " + pattern + ": " + pat + ": " + pit) pattern = pattern.replace(pat, pit) diff --git a/utils/report_tool.py b/utils/report_tool.py index a07057d..ca43bff 100644 --- a/utils/report_tool.py +++ b/utils/report_tool.py @@ -13,40 +13,254 @@ the reporting-system in bottom-up (2.2) transfer of the summary result-code of each testcase to an extern reporting-system - protocol - (2.3) visualization of final result-code of each component and each testcase in test-set - result-report - (2.4) visualization of statistical result-codes of each component and each test-set in test-context - result-report - + | testcase-artefact | testcase-report | testsuite-report +title | comparison | testcase | testsuite +table0 | | each component | each testcase x each component + h1 | | | testcase + h2 | | component | component + h3 | -- | main-comparison | main-comparison + h4 | | other comparison | other comparison """ +import os +import re import basic.program +import utils.match_tool as M +import basic.constants as B +import utils.css_tool +import utils.path_tool -def getTcExtraction(tcpath, comp): - """ - extracts the pure differences of diff-files - :param comp: - :return: html-code with links to diff-files - """ - job = basic.program.Job.getInstance() - verify = -0 + job.getDebugLevel("report_tool") - job.debug(verify, "writeDataTable " + str(comp)) - body = '

' - # for f in diff-files: - # body = body + extractDiffLines - body = body + '

' - return body - -def getTcBody(tcpath): - """ +REP_TITLE = "Ergebnisbericht" +REP_TC = "Testfall" +REP_TS = "Testsuite" +REP_COMP = "Komponente" +REP_ART = "Artefakt" + +class Report(): + __instance = None + + @staticmethod + def getInstance(): + if (Report.__instance is not None): + return Report.__instance + else: + return Report() + + def __init__(self): + """ + :param report: matchtype + :param comp: optional on matching + structure: + report 1:k + testcase 1:l # only in testsuite-report + components 1:m + artefacts 1:n + matches + the html-side + title : subject of result for artefact/testcase/testsuite + overview : table with links, only for testcase/testsuite + testcase : h1 with anker, only testcase/testsuite + component: h2 with anker + artefact : h3 + matches : with links + paths : p with links to row-results + matching : table complete match for artefact-result resp. only diff for other matches + """ + job = basic.program.Job.getInstance() + self.report = {} + self.report["testcases"] = [] + self.testcase = "" + self.component = "" + self.artefact = "" + self.matchtype = "" + #return self + + def setPaths(self, testcase, component, artefact, matchtype, pathA, pathB): + if not testcase in self.report: + self.report[testcase] = {} + self.report["testcases"].append(testcase) + if not component in self.report[testcase]: + self.report[testcase][component] = {} + if not artefact in self.report[testcase][component]: + self.report[testcase][component][artefact] = {} + self.report[testcase][component][artefact][matchtype] = {} + self.report[testcase][component][artefact][matchtype]["pathA"] = pathA + self.report[testcase][component][artefact][matchtype]["pathB"] = pathB + self.testcase = testcase + self.component = component + self.artefact = artefact + self.matchtype = matchtype + + def setMatchResult(self, testcase, component, artefact, matchtype, cssClass, diffTable): + self.report[testcase][component][artefact][matchtype]["css"] = cssClass + if matchtype == M.MATCH_POSTCOND: + self.report[testcase][component][artefact][matchtype]["diff"] = diffTable + + def getTitle(self, testcase="", component="", artefact="", matchtype=""): + job = basic.program.Job.getInstance() + 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, "testsuite")+"

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

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

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

" + return html + + def getCssClass(self, testcase="", component="", artefact="", match=""): + """ + the function calculates the maximum cssClass of the granularity + the cssClass means the fault-class of the matching + :param testcase: + :param component: + :param artefact: + :return: + """ + cssClass = "result0" + if len(match) > 0: + if match in self.report[testcase][component][artefact]: + if "css" in self.report[testcase][component][artefact][match]: + if cssClass < self.report[testcase][component][artefact][match]["css"]: + cssClass = self.report[testcase][component][artefact][match]["css"] + return cssClass + elif len(artefact) > 0: + for match in self.report[testcase][component][artefact]: + if "css" in self.report[testcase][component][artefact][match]: + if cssClass < self.report[testcase][component][artefact][match]["css"]: + cssClass = self.report[testcase][component][artefact][match]["css"] + return cssClass + elif len(component) > 0: + for a in self.report[testcase][component]: + val = self.getCssClass(testcase, component, a) + if cssClass < val: + cssClass = val + return cssClass + elif len(testcase) > 0: + for c in self.report[testcase]: + val = self.getCssClass(testcase, c, "") + if cssClass < val: + cssClass = val + return cssClass + return cssClass + + def getHeader(self): + job = basic.program.Job.getInstance() + verify = int(job.getDebugLevel("report_tool"))-1 + htmltxt = "" + htmltxt += "" + htmltxt += utils.css_tool.getInternalStyle("diffFiles") + return htmltxt + + def getOverviewHead(self, testcase=""): + if len(testcase) < 1: + return "" + htmlHead = "
" + for c in self.report[testcase]: + if c in ["overview", "block"]: + continue + htmlHead += "" + return htmlHead + + def getOverview(self, testcase=""): + if len(testcase) < 1: + return "" + htmlHead = self.getOverviewHead(testcase) + htmlBody = "" + for c in self.report[testcase]: + cssClass = self.getCssClass(testcase, c, "") + htmlBody += "" + return htmlHead+""+htmlBody+"
"+REP_TC+"" + c + "
"+testcase+"" + testcase + "
" + + def getTestcaseHead(self, testcase="", component="", artefact="", matchtype=""): + if len(testcase) < 1: + return "" + cssClass = self.getCssClass(testcase, "", "") + html = "

"+REP_TC+" "+testcase+"

" + return html + + def getComponentHead(self, testcase="", component="", artefact="", matchtype=""): + job = basic.program.Job.getInstance() + return "

"+REP_COMP+" "+component+"

" + + def getArtefactBlock(self, testcase, component, artefact, matchtype=""): + job = basic.program.Job.getInstance() + 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 = path.replace(job.conf.confs[B.SUBJECT_PATH][B.ATTR_PATH_ARCHIV], os.path.join("..", "..")) + html += " "+M.MATCH[match]["filename"]+" " + html += "

" + if len(matchtype) < 1: + matchtype = M.MATCH_POSTCOND + html += "

\n" + for side in ["A", "B"]: + path = self.report[testcase][component][artefact][matchtype]["path"+side] + href = path.replace(job.conf.confs[B.SUBJECT_PATH][B.ATTR_PATH_ARCHIV], os.path.join("..", "..")) + html += M.MATCH[M.MATCH[M.MATCH_POSTCOND][side]]["long"]+" " + html += ""+path+"\n" + if side == "A": html += "
" + html += "

" + return html + + def getFilepath(self, testcase, component, artefact, matchtype): + cm = basic.componentHandling.ComponentManager() + comp = cm.getComponent(component) + path = os.path.join(utils.path_tool.composePatttern("{tcresult}", comp), artefact+"_"+M.MATCH[matchtype]["filename"]+".html") + return path + + def getComparisonBlock(self, testcase, component, artefact, matchtype): + html = self.report[testcase][component][artefact][matchtype]["diff"] + return html + + def reportTestcase(self, testcase): + job = basic.program.Job.getInstance() + verify = int(job.getDebugLevel("report_tool")) - 1 + html = self.getHeader() + html += self.getTitle(testcase) + html += self.getOverview(testcase) + html += "
" + html += self.getTestcaseHead(testcase) + for component in self.report[testcase]: + html += self.getComponentHead(testcase, component) + for artefact in self.report[testcase][component]: + html += self.getArtefactBlock(testcase, component, artefact, M.MATCH_POSTCOND) + html += self.getComparisonBlock(testcase, component, artefact, M.MATCH_POSTCOND) + html += "
<-- class=\"tc-block\" -->" + html += "" + return html + + def extractTestcase(self, testcase, html): + job = basic.program.Job.getInstance() + verify = int(job.getDebugLevel("report_tool")) - 1 + overview = re.findall("", html) + if len(overview) == 1: + self.report[testcase]["overview"] = overview[0] + startP = html.index("
") + block = html[startP:endP] + if len(block) > 1: + self.report[testcase]["block"] = block + + def reportTestsuite(self): + job = basic.program.Job.getInstance() + verify = int(job.getDebugLevel("report_tool")) - 1 + testcases = getattr(job.par, "testcases") + html = self.getHeader() + html += self.getTitle() + i = 0 + for testcase in testcases: + if i == 0: html += self.getOverviewHead(testcase) + html += self.report[testcase]["overview"] + i += 1 + html += "" + for testcase in testcases: + html += self.report[testcase]["block"] + html += "" + return html - :param tcpath: - :return: - """ - job = basic.program.Job.getInstance() - verify = -0+job.getDebugLevel("report_tool") - job.debug(verify, "writeDataTable " + str(tcpath)) - body = '

' - # for c in comps: - # - body = body + '

' - return body -def getTcHeader(tcpath): +def report_testsuite(tcpath): """ creates header :param tcpath: diff --git a/utils/xml2_tool.py b/utils/xml2_tool.py new file mode 100644 index 0000000..fc33e43 --- /dev/null +++ b/utils/xml2_tool.py @@ -0,0 +1,45 @@ +import os, sys, json +import xmltodict +import pprint + +class fcts: + def dict2xml(tree): + out = xmltodict.unparse(tree, pretty=True) + return out + + def xml2dict(xmlstring): + tree = {} + pp = pprint.PrettyPrinter(indent=4) + tree = xmlstring.parse(xmlstring) + return tree + +def readXml(filename): + pass + +def addNode(xpath, value): + pass + +def writeDataTable(teststatus, tdata, comp): + """ + writes the testdata into a csv-file for documentation of the test-run + :param teststatus: + :param tdata: + :param comp: if specific else None + :return: + """ + #output = xmljson.badgerfish.etree(tdata, root=xmljson.badgerfish.Element('root')) + result = bf.etree(tdata, root=Element('xml')) + # xmljson.badgerfish.tostring(output) + txt = tostring(result, pretty_print=True) + print (txt.decode('utf-8')) + + # out = tostring(result, pretty_print=True) + #print (prettify(result)) + pass + +def prettify(elem): + """Return a pretty-printed XML string for the Element. + """ + rough_string = tostring(elem, 'utf-8') + reparsed = xml.dom.minidom.parseString(rough_string ) + return reparsed.toprettyxml(indent=" ") \ No newline at end of file diff --git a/utils/zip_tool.py b/utils/zip_tool.py new file mode 100644 index 0000000..022b117 --- /dev/null +++ b/utils/zip_tool.py @@ -0,0 +1,51 @@ +import zipfile +import tarfile +import os + +ZIEL = '/home/ulrich/tmp' +QUELLE = '/home/ulrich/1_privat' +FOLDER = '64-UMKER' + + +def untarFolder(): + tar_file = tarfile.open(os.path.join(ZIEL, 'tartemp.tar.gz'), 'r:gz') + tar_file.extractall(path=os.path.join(ZIEL, 'tarliste')) + tar_file.close() + pass + +def tarFolder(): + with tarfile.open(os.path.join(ZIEL, 'tartemp.tar.gz'), 'w:gz') as tar_file: + for folderName, subfolders, filenames in os.walk(os.path.join(QUELLE, FOLDER)): + for filename in filenames: + folderShort = folderName.replace(QUELLE + '/', '') + # create complete filepath of file in directory + filePath = os.path.join(folderName, filename) + # Add file to zip + tar_file.add(filePath, os.path.join(folderShort, filename)) + tar_file.close() + + +def unzipFolder(): + zip_file = zipfile.ZipFile(os.path.join(ZIEL, 'temp.zip'), 'r') + zip_file.extractall(path=os.path.join(ZIEL, 'liste')) + zip_file.close() + pass + +def zipFolder(): + with zipfile.ZipFile(os.path.join(ZIEL, 'temp.zip'), 'w') as zip_file: + # Iterate over all the files in directory + for folderName, subfolders, filenames in os.walk(os.path.join(QUELLE, FOLDER)): + for filename in filenames: + folderShort = folderName.replace(QUELLE+'/', '') + # create complete filepath of file in directory + filePath = os.path.join(folderName, filename) + # Add file to zip + zip_file.write(filePath, os.path.join(folderShort, filename)) + zip_file.close() + return "" + +if __name__ == '__main__': + zipFolder() + unzipFolder() + tarFolder() + untarFolder()