# functions in order to report the summaries # ------------------------------------------------------- """ the reporting-system in bottom-up (0) raw-data (0.1) artificats created from test-system - raw-files up to work-files - (0.2) in logs all contacts to test-system - raw-info - (1) comparison-result (1.1) comparison-result as difference for each file-comparison in html-files in testcases - diff-files - (1.2) extraction of diff-files (only not accepted differences) as html-file in test-set - result-report - (2) result-code (2.1) result-code of each test-step for each component in testcases - parameter-file - (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 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, "usecase")+"" html += "

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

" 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 and len(artefact) > 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(match) > 0: for a in self.report[testcase][component]: val = self.getCssClass(testcase, component, a, match) if cssClass < val: cssClass = val 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[matchtype][side]]["long"]+" " html += ""+path+"\n" if side == "A": html += "
" html += "

" return html def getFilepath(self, testcase, component, artefact, matchtype): cm = basic.componentHandling.ComponentManager.getInstance("init") comp = cm.getComponent(component) path = os.path.join(utils.path_tool.composePattern("{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 if not testcase in self.report: self.report = {} 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 testinstances = getattr(job.par, "testinstances") html = self.getHeader() html += self.getTitle() i = 0 for testcase in testinstances: if i == 0: html += self.getOverviewHead(testcase) html += self.report[testcase]["overview"] i += 1 html += "" for testcase in testinstances: html += self.report[testcase]["block"] html += "" return html def report_testsuite(tcpath): """ creates header :param tcpath: :return: html-code with result-codes of each component """ job = basic.program.Job.getInstance() verify = -0+job.getDebugLevel("report_tool") job.debug(verify, "writeDataTable " + str(tcpath))