Data-Test-Executer Framework speziell zum Test von Datenverarbeitungen mit Datengenerierung, Systemvorbereitungen, Einspielungen, ganzheitlicher diversifizierender Vergleich
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

292 lines
13 KiB

# 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_const 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"
TOOL_NAME = "report_tool"
class Report:
__instance = None
__instances = {}
@staticmethod
def getInstance(job):
if (job.jobid in Report.__instances):
return Report.__instances[job.jobid]
else:
return Report(job)
def __init__(self, job):
"""
: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.job = job
self.report = {}
Report.__instances[job.jobid] = self
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 = self.job # basic.program.Job.getInstance()
if len(matchtype) > 1:
html = "<title>"+M.MATCH[matchtype]["title"]+"</title></head><body><h1>"+M.MATCH[matchtype]["title"]+"</h1>"
elif len(testcase) > 1:
html = "<title>"+REP_TITLE+" "+REP_TC+" "+testcase+"</title></head>"
html += "<body><h1>"+REP_TITLE+" "+REP_TC+" "+testcase+"</h1>"
elif hasattr(job.par, B.PAR_TESTSUITE):
html = "<title>" + REP_TITLE + " " + REP_TS + " " + getattr(job.par, B.PAR_TESTSUITE) + "</title>"
html += "</head><body><h1>" + REP_TITLE + " " + REP_TS + " " + getattr(job.par, B.PAR_TESTSUITE) + "</h1>"
elif hasattr(job.par, B.PAR_TESTCASE):
html = "<title>" + REP_TITLE + " " + REP_TC + " " + getattr(job.par, B.PAR_TESTCASE) + "</title></head>"
html += "<body><h1>" + REP_TITLE + " " + REP_TC + " " + getattr(job.par, B.PAR_TESTCASE) + "</h1>"
if hasattr(job.par, B.PAR_DESCRIPT):
html += "<p>"+getattr(job.par, B.PAR_DESCRIPT)+"</p>"
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 = self.job # basic.program.Job.getInstance()
verify = int(job.getDebugLevel(TOOL_NAME))-1
htmltxt = "<!DOCTYPE html>"
htmltxt += "<html><head>"
htmltxt += utils.css_tool.getInternalStyle(job, "diffFiles")
return htmltxt
def getOverviewHead(self, testcase=""):
if len(testcase) < 1:
return ""
htmlHead = "<table><tr><th>"+REP_TC+"</th>"
for c in self.report[testcase]:
if c in ["overview", "block"]:
continue
htmlHead += "<th>" + c + "</th>"
return htmlHead
def getOverview(self, testcase=""):
if len(testcase) < 1:
return ""
htmlHead = self.getOverviewHead(testcase)
htmlBody = "<tr class=\"tc-overview\"><td><a href=\"#"+testcase+"_testcase\">"+testcase+"</td>"
for c in self.report[testcase]:
cssClass = self.getCssClass(testcase, c, "")
htmlBody += "<td "+utils.css_tool.getInlineStyle("resultFile", cssClass)+"><a href=\"#"+testcase+"_"+c+"\">"+testcase+"</td>"
return htmlHead+"</tr>"+htmlBody+"</tr></table>"
def getTestcaseHead(self, testcase="", component="", artefact="", matchtype=""):
if len(testcase) < 1:
return ""
cssClass = self.getCssClass(testcase, "", "")
html = "<h1><a id=\""+testcase+"_testcase\">"+REP_TC+" "+testcase+"</h1>"
return html
def getComponentHead(self, testcase="", component="", artefact="", matchtype=""):
job = self.job # basic.program.Job.getInstance()
html = "<h2 id=\""+testcase+"_"+component+"\">"+REP_COMP+" "+component+"</h2>"
return html
def getArtefactBlock(self, testcase, component, artefact, matchtype=""):
job = self.job # basic.program.Job.getInstance()
html = "<h3>"+REP_ART+" "+artefact+"</h3><p>"
for match in self.report[testcase][component][artefact]:
cssClass = self.getCssClass(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 += " <a href=\""+path+"\" "+utils.css_tool.getInlineStyle(job, "resultFile", cssClass)+">"+M.MATCH[match]["filename"]+"<a> "
html += "</p>"
if len(matchtype) < 1:
matchtype = M.MATCH_POSTCOND
html += "<p>\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 += "<a href=\""+href+"\">"+path+"<a>\n"
if side == "A": html += "<br>"
html += "</p>"
return html
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
def getComparisonBlock(self, testcase, component, artefact, matchtype):
html = self.report[testcase][component][artefact][matchtype]["diff"]
return html
def reportTestcase(self, testcase):
job = self.job # basic.program.Job.getInstance()
verify = int(job.getDebugLevel(TOOL_NAME)) - 1
html = self.getHeader()
html += self.getTitle(testcase)
html += self.getOverview(testcase)
html += "<div class=\"tc-block\">"
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 += "</div><-- class=\"tc-block\" -->"
html += "</body></html>"
return html
def extractTestcase(self, testcase, html):
job = self.job # basic.program.Job.getInstance()
verify = int(job.getDebugLevel(TOOL_NAME)) - 1
if not testcase in self.report:
self.report = {}
overview = re.findall("<tr class.+tc-overview.*</tr>", html)
if len(overview) == 1:
self.report[testcase]["overview"] = overview[0]
startP = html.index("<div class=\"tc-block\"")
endP = html.index("</div>")
block = html[startP:endP]
if len(block) > 1:
self.report[testcase]["block"] = block
def reportTestsuite(self):
job = self.job # basic.program.Job.getInstance()
verify = int(job.getDebugLevel(TOOL_NAME)) - 1
testinstances = getattr(job.par, B.PAR_TESTCASES)
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 += "</table>"
for testcase in testinstances:
html += self.report[testcase]["block"]
html += "</body></html>"
return html
def report_testsuite(job, tcpath):
"""
creates header
:param tcpath:
:return: html-code with result-codes of each component
"""
# job = basic.program.Job.getInstance()
verify = -0+job.getDebugLevel(TOOL_NAME)
job.debug(verify, "writeDataTable " + str(tcpath))