import isystem.connect as ic
import isystem.itest as it
winidea_id = ''
def createExampleOfLogEntry():
lr = ic.CLogResult(None)
lr.add('counter', '234', ic.CLogResult.E_SECTION_BEFORE_ASSIGN)
lr.add('size', '25', ic.CLogResult.E_SECTION_AFTER_ASSIGN)
return lr
def createExampleOfStubResult(hitNo, stepIdx):
sr = ic.CTestPointResult(None)
sr.setId('fillArray')
sr.setLogResult(createExampleOfLogEntry())
sr.setExecStatus(ic.CTestPointResult.EXECUTED)
sr.setHitNoAndStepIdx(hitNo, stepIdx)
sr.setScriptInfoVar("evaluated all expressions")
sr.setScriptRetVal("")
sr.addExpressionError("a == 10", "a = 9")
return sr
def createExampleOfTestPointResult():
sr = ic.CTestPointResult(None)
sr.setId('myTestPointID')
sr.setLocation('src/main.cpp')
sr.setLogResult(createExampleOfLogEntry())
sr.setExecStatus(ic.CTestPointResult.EXECUTED)
sr.setHitNoAndStepIdx(0, 0)
sr.setScriptInfoVar("evaluated all expressions")
sr.setScriptRetVal("Eval. failed!")
return sr
def createExampleOfStackUsage():
su = ic.CStackUsageResult(None)
minExpectedSize = 200
maxExpectedSize = 600
stackUsedBeforeTest = 150
testUsage = 0
appUsage = 50
su.setValues(minExpectedSize, maxExpectedSize, stackUsedBeforeTest,
testUsage, appUsage)
return su
def createExampleOfPreConditionResult(isError):
pc = ic.CTestExprResult(None)
pc.setExpression('a == 2')
pc.addSubexpression('a', '2')
pc.setError(isError)
return pc
def createExampleOfExprResult(expr, subExpr, value, isError):
pc = ic.CTestExprResult(None)
pc.setExpression(expr)
pc.addSubexpression(subExpr, value)
pc.setError(isError)
return pc
def createExampleOfTestResult():
testSpec = ic.CTestSpecification()
testSpec.setTestId('demoTest')
testResult = ic.CTestResult(testSpec)
testResult.setResultComment('This is demo script for test report creation')
testResult.setTargetException(False)
testResult.appendScriptOutput("", "timing OK")
testResult.addStubResult(createExampleOfStubResult(0, 0))
testResult.addStubResult(createExampleOfStubResult(1, 0))
testResult.addTestPointResult(createExampleOfTestPointResult())
testResult.setStackUsageResult(createExampleOfStackUsage())
testResult.addExprResult(ic.CTestResult.E_SECTION_PRE_CONDITION,
createExampleOfPreConditionResult(False))
testResult.addExprResult(ic.CTestResult.E_SECTION_ASSERT,
createExampleOfExprResult('a == 4', 'a', '2', True))
testResult.setLogResult(createExampleOfLogEntry())
return testResult
def getWinIDEAVersion():
cm = ic.ConnectionMgr()
cm.connect(ic.CConnectionConfig().instanceId(winidea_id))
ide = ic.CIDEController(cm)
ver = ide.getWinIDEAVersion()
return ver.toString()
def createExampleOfReportConfig():
reportConfig = ic.CTestReportConfig()
reportConfig.setReportContents(ic.CTestReportConfig.RCONFIG_FULL)
reportConfig.setTestIDEAVersion("0.9")
cm = ic.ConnectionMgr()
cm.connect(ic.CConnectionConfig().instanceId(winidea_id))
ide = ic.CIDEController(cm)
reportConfig.setWinIDEAVersion(getWinIDEAVersion())
reportConfig.setOutputFormat(ic.CTestReportConfig.FMT_XML)
reportConfig.setFileName('reportGeneratedByCustomScript.xml')
reportConfig.setIYamlFileName("./")
reportConfig.setXsltForFullReport(it.DEFAULT_XSLT)
reportConfig.setCssFile(it.BLUE_CSS)
reportConfig.setIncludeTestSpec(False)
reportConfig.setXmlReportHeader("CUSTOM REPORT")
reportConfig.addUserInfo("date", "2019-04-04")
reportConfig.addUserInfo("testerName", "john")
return reportConfig
def saveTestReport(testResults, reportConfig):
resultContainer = ic.CTestReportContainer()
for testResult in testResults:
resultContainer.putTestResult(ic.CTestSpecification(), testResult)
ic.CTestBench.saveTestResults(resultContainer, reportConfig)
def main():
reportConfig = createExampleOfReportConfig()
testResults = []
testResults.append(createExampleOfTestResult())
saveTestReport(testResults, reportConfig)
it.copyXsltAndCss(reportConfig)
print("OK")
if __name__ == "__main__":
main()