def testTestRunEquality(self): c1 = TestConditionData() c2 = TestConditionData() c1.filenamePrefix = "..\\..\\Test" c2.filenamePrefix = "..\\..\\Junk" t1 = TestCaseData() t2 = TestCaseData() t1.name = "Test 1" t2.name = "Test 1" t1.conditions.append(c1) t1.conditions.append(c2) t2.conditions.append(c1) t2.conditions.append(c2) r1 = TestRunData() r2 = TestRunData() r1.appname = "One" r2.appname = "One" self.assertTrue(r1 == r2) r1.testcases.append(t1) self.assertFalse(r1 == r2) r2.testcases.append(t2) self.assertTrue(r1 == r2) c3 = TestConditionData() c3.filenamePrefix = "..\\..\\Fail" t2.conditions.append(c3) self.assertFalse(r1 == r2)
def parseTrxFile(baseName, trxFile): print "TRX file:", trxFile if os.path.exists(trxFile): xml = "" f = open(trxFile, 'r') for line in f: xml += line #otherResultsTestParser = re.compile( r'(.*\\)(.*\..pp)' ) #hexParser = re.compile( r'(.*)\b(0[xX][0-9a-fA-F]+)\b(.*)' ) testRun = TestRunData() testRun.appname = "CatchSelfTest" root = etree.fromstring(xml) if testRun.appname == "TestCatch.exe": testRun.appname = "CatchSelfTest" qname = re.compile("{(?P<ns>.*)}(?P<element>.*)") ids = [] for ts in root: m = qname.match(ts.tag) if m: tag = m.group(2) print tag if tag != None: if tag == "TestDefinitions": for tc in ts: m = qname.match(tc.tag) if m: tag = m.group(2) if tag != None and tag == "UnitTest": name = tc.get("name") id = tc.get("id") for item in tc: m = qname.match(item.tag) if m: tag = m.group(2) if tag != None and tag == "Description": desc = item.text #print desc, id ids.append([id, desc]) elif tag == "Results": #print ids ids = dict(ids) #print ids["87ec526a-e414-1a3f-ba0f-e210b204bb42"] lineNumber = 0 resultParser = TestCaseResultParser() for tc in ts: m = qname.match(tc.tag) if m: tag = m.group(2) if tag != None and tag == "UnitTestResult": outcome = tc.get("outcome") id = tc.get("testId") if len(id) > 0: for item in tc: m = qname.match(item.tag) if m: tag = m.group(2) if tag != None and tag == "Output": for sub in item: m = qname.match(sub.tag) if m: tag = m.group(2) if tag != None and tag == "StdOut": desc = sub.text lines = desc.splitlines() found = False index = 0 for tmp in lines: if (len(lines) >= (index + 2) and lines[index]. startswith( "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" ) and lines[index + 1]. startswith( "Batch run using" )): found = True break index += 1 lines = lines[index + 3:] #print "*******",desc #print lines if found: endOfRun = False for line in lines: if endOfRun: testRun.results = line.strip( ) else: try: testcase = resultParser.parseResultLine( line) except RandomOutput as e: #print "E:", self.lineNumber, ", ",e.output testRun.output = e.output testRun.outputLine = lineNumber - len( e.output) if isinstance( testcase, TestCaseData ): testRun.testcases.append( testcase) if line.startswith( "===============================================================================" ): endOfRun = True lineNumber += 1 lines = testRun.generateSortedUnapprovedLines( testRun.outputLine) rawSortedPath = os.path.join( rootPath, '{0}.sorted.unapproved.txt'.format(baseName)) rawWriteFile = open(rawSortedPath, 'wb') for line in lines: #print "L:",line rawWriteFile.write(line + "\n") rawWriteFile.close()
def approveXml(baseName, args): global overallResult args[0:0] = [cmdPath] baselinesPath = os.path.join(rootPath, '{0}.approved.txt'.format(baseName)) baselinesSortedPath = os.path.join( rootPath, '{0}.sorted.approved.txt'.format(baseName)) #baselinesFixedPath = os.path.join( rootPath, '{0}.rewrite.approved.txt'.format( baseName ) ) rawResultsPath = os.path.join(rootPath, '_{0}.tmp'.format(baseName)) if os.path.exists(baselinesPath): xml = "" f = open(baselinesPath, 'r') for line in f: xml += line xml = xml.replace("<hex digits>", "<hex digits>") #otherApprovedTestParser = re.compile( r'(.*\..pp).*:<(.*).*>' ) testRun = TestRunData() testcase = None root = etree.fromstring(xml) testRun.appname = root.get("name") for ts in root: #print ts.tag for tc in ts: if tc.tag == "TestCase": testcase = testRun.addTestCase(tc.get("name")) for exp in tc: if exp.tag == "Expression": result = exp.get("success") filename = exp.get("filename") section = testcase.addExpression(result, filename) subExp = [] for cond in exp: if cond.tag == "Original": text = cond.text ls = text.splitlines() subExp.append(ls) elif cond.tag == "Expanded" and len( subExp) == 1: text = cond.text ls = text.splitlines() subExp.append(ls) elif cond.tag == "Exception" and len( subExp) == 2: subExp.append(cond.get("filename")) text = cond.text ls = text.splitlines() subExp.append(ls) else: print "X:", cond.tag if len(subExp) >= 2: testcase.addExpressionDetails(section, subExp) elif exp.tag == "Exception": filename = exp.get("filename") text = exp.text ls = text.splitlines() section = testcase.addException(filename, ls) elif exp.tag == "Section": addSubSection(testcase, None, exp) elif exp.tag == "Info": text = exp.text ls = text.splitlines() section = testcase.addInfo(ls) elif exp.tag == "Warning": text = exp.text ls = text.splitlines() section = testcase.addWarning(ls) elif exp.tag == "Failure": ls = [] if exp.text != None: text = exp.text ls = text.splitlines() section = testcase.addSimpleFailure(ls) elif exp.tag == "OverallResult": testcase.addOverallResult(exp.get("success")) else: print "E:", exp.tag elif tc.tag == "OverallResults": testRun.tests = tc.get("successes") testRun.failures = tc.get("failures") else: print "U:", tc.tag lines = testRun.generateSortedUnapprovedXml() rawWriteFile = open(baselinesSortedPath, 'wb') for line in lines: #print "L:",line rawWriteFile.write(line + "\n") rawWriteFile.close() if not (os.path.exists(args[0])): raise Exception("Executable does not exist: '" + args[0] + "'") f = open(rawResultsPath, 'w') subprocess.call(args, stdout=f, stderr=f) f.close() rawSortedPath = os.path.join(rootPath, '{0}.sorted.unapproved.txt'.format(baseName)) if os.path.exists(rawResultsPath): xml = "" f = open(rawResultsPath, 'r') for line in f: xml += line f.close() #xml = xml.replace("<hex digits>", "<hex digits>") os.remove(rawResultsPath) otherResultsTestParser = re.compile(r'(.*\\)(.*\..pp)') hexParser = re.compile(r'(.*)\b(0[xX][0-9a-fA-F]+)\b(.*)') testRun = TestRunData() testcase = None root = etree.fromstring(xml) testRun.appname = root.get("name") if testRun.appname == "TestCatch.exe": testRun.appname = "CatchSelfTest" for ts in root: #print ts.tag for tc in ts: if tc.tag == "TestCase": testcase = testRun.addTestCase(tc.get("name")) for exp in tc: if exp.tag == "Expression": result = exp.get("success") filename = exp.get("filename") m = otherResultsTestParser.match(filename) if m: filename = "/Users/philnash/Dev/OSS/Catch/projects/SelfTest/" + m.group( 2) section = testcase.addExpression(result, filename) subExp = [] for cond in exp: if cond.tag == "Original": text = cond.text tmp = text.splitlines() ls = [] for li in tmp: m = hexParser.match(li) if m: while m: #print li, m.group(1), m.group(3) li = m.group( 1 ) + "0x<hex digits>" + m.group( 3) m = hexParser.match(li) ls.append(li) subExp.append(ls) elif cond.tag == "Expanded" and len( subExp) == 1: text = cond.text tmp = text.splitlines() ls = [] for li in tmp: m = hexParser.match(li) if m: while m: #print li, m.group(1), m.group(3) li = m.group( 1 ) + "0x<hex digits>" + m.group( 3) m = hexParser.match(li) ls.append(li) subExp.append(ls) elif cond.tag == "Exception" and len( subExp) == 2: filename = cond.get("filename") m = otherResultsTestParser.match(filename) if m: filename = "/Users/philnash/Dev/OSS/Catch/projects/SelfTest/" + m.group( 2) subExp.append(filename) text = cond.text ls = text.splitlines() subExp.append(ls) else: print "X:", cond.tag if len(subExp) >= 2: testcase.addExpressionDetails(section, subExp) elif exp.tag == "Exception": filename = exp.get("filename") m = otherResultsTestParser.match(filename) if m: filename = "/Users/philnash/Dev/OSS/Catch/projects/SelfTest/" + m.group( 2) text = exp.text ls = text.splitlines() section = testcase.addException(filename, ls) elif exp.tag == "Section": addResultsSubSection(otherResultsTestParser, testcase, None, exp) elif exp.tag == "Info": text = exp.text ls = text.splitlines() section = testcase.addInfo(ls) elif exp.tag == "Warning": text = exp.text ls = text.splitlines() section = testcase.addWarning(ls) elif exp.tag == "Failure": ls = [] if exp.text != None: text = exp.text ls = text.splitlines() section = testcase.addSimpleFailure(ls) elif exp.tag == "OverallResult": testcase.addOverallResult(exp.get("success")) else: print "E:", exp.tag elif tc.tag == "OverallResults": testRun.tests = tc.get("successes") testRun.failures = tc.get("failures") else: print "U:", tc.tag lines = testRun.generateSortedUnapprovedXml() rawWriteFile = open(rawSortedPath, 'wb') for line in lines: #print "L:",line rawWriteFile.write(line + "\n") rawWriteFile.close()
def approveJunit(baseName, args): global overallResult args[0:0] = [cmdPath] baselinesPath = os.path.join(rootPath, '{0}.approved.txt'.format(baseName)) baselinesSortedPath = os.path.join( rootPath, '{0}.sorted.approved.txt'.format(baseName)) #baselinesFixedPath = os.path.join( rootPath, '{0}.rewrite.approved.txt'.format( baseName ) ) rawResultsPath = os.path.join(rootPath, '_{0}.tmp'.format(baseName)) if os.path.exists(baselinesPath): xml = "" f = open(baselinesPath, 'r') for line in f: xml += line xml = xml.replace("<line number>", "<line number>") xml = xml.replace("<hex digits>", "<hex digits>") #f2 = open( baselinesFixedPath, 'wb' ) #f2.write(xml) #f2.close() # ClassTests.cpp:<line number> otherApprovedTestParser = re.compile(r'(.*\..pp).*:<(.*).*>') testRun = TestRunData() testcase = None root = etree.fromstring(xml) for testsuites in root: if testsuites.tag == "testsuite": testRun = TestRunData() testRun.appname = testsuites.get("name") testRun.errors = testsuites.get("errors") testRun.failures = testsuites.get("failures") testRun.tests = testsuites.get("tests") for tc in testsuites: if tc.tag == "testcase": cls = tc.get("classname") #print "C:",cls,tc if len(cls): testcase = testRun.addClassTestCase( cls, tc.get("name")) else: testcase = testRun.addTestCase(tc.get("name")) for prop in tc: if prop.tag == "failure": text = prop.text.strip() lines = text.splitlines() filename = "" lineNumber = "" output = [] for l in lines: m = otherApprovedTestParser.match(l) if m: filename = m.group(1) lineNumber = m.group(2) else: output.append(l) testcase.addFailure(filename, lineNumber, output, prop.get("message"), prop.get("type")) elif prop.tag == "error": text = prop.text.strip() lines = text.splitlines() filename = "" lineNumber = "" output = [] for l in lines: m = otherApprovedTestParser.match(l) if m: filename = m.group(1) lineNumber = m.group(2) else: output.append(l) testcase.addError(filename, lineNumber, output, prop.get("message"), prop.get("type")) elif prop.tag == "system-out": text = prop.text.strip() lines = text.splitlines() testcase.addSysout(lines) elif prop.tag == "system-err": text = prop.text.strip() lines = text.splitlines() testcase.addSyserr(lines) elif tc.tag == "system-out": text = tc.text.strip() lines = text.splitlines() testRun.addSysout(lines) elif tc.tag == "system-err": text = tc.text.strip() lines = text.splitlines() testRun.addSyserr(lines) else: print tc.tag lines = testRun.generateSortedUnapprovedJunit() rawWriteFile = open(baselinesSortedPath, 'wb') for line in lines: #print "L:",line rawWriteFile.write(line + "\n") rawWriteFile.close() if not (os.path.exists(args[0])): raise Exception("Executable does not exist: '" + args[0] + "'") f = open(rawResultsPath, 'w') subprocess.call(args, stdout=f, stderr=f) f.close() rawSortedPath = os.path.join(rootPath, '{0}.sorted.unapproved.txt'.format(baseName)) if os.path.exists(rawResultsPath): xml = "" f = open(rawResultsPath, 'r') for line in f: xml += line #xml = xml.replace("<line number>", "<line number>") #xml = xml.replace("<hex digits>", "<hex digits>") # ClassTests.cpp:<line number> otherResultsTestParser = re.compile(r'(.*\\)(.*\..pp).*\((.*).*\)') testRun = TestRunData() testcase = None root = etree.fromstring(xml) for testsuites in root: if testsuites.tag == "testsuite": testRun = TestRunData() testRun.appname = testsuites.get("name") testRun.errors = testsuites.get("errors") testRun.failures = testsuites.get("failures") testRun.tests = testsuites.get("tests") for tc in testsuites: if tc.tag == "testcase": cls = tc.get("classname") #print "C:",cls,tc if len(cls): if cls.startswith("::"): cls = cls[2:] testcase = testRun.addClassTestCase( cls, tc.get("name")) else: testcase = testRun.addTestCase(tc.get("name")) for prop in tc: if prop.tag == "failure": text = prop.text.strip() lines = text.splitlines() filename = "" lineNumber = "" output = [] for l in lines: m = otherResultsTestParser.match(l) if m: filename = m.group(2) lineNumber = "line number" else: output.append(l) testcase.addFailure(filename, lineNumber, output, prop.get("message"), prop.get("type")) elif prop.tag == "error": text = prop.text.strip() lines = text.splitlines() filename = "" lineNumber = "" output = [] for l in lines: m = otherResultsTestParser.match(l) if m: filename = m.group(2) lineNumber = "line number" else: output.append(l) testcase.addError(filename, lineNumber, output, prop.get("message"), prop.get("type")) elif prop.tag == "system-out": text = prop.text.strip() lines = text.splitlines() testcase.addSysout(lines) elif prop.tag == "system-err": text = prop.text.strip() lines = text.splitlines() testcase.addSyserr(lines) elif tc.tag == "system-out": text = tc.text.strip() lines = text.splitlines() testRun.addSysout(lines) elif tc.tag == "system-err": text = tc.text.strip() lines = text.splitlines() testRun.addSyserr(lines) else: print tc.tag lines = testRun.generateSortedUnapprovedJunit() rawWriteFile = open(rawSortedPath, 'wb') for line in lines: #print "L:",line rawWriteFile.write(line + "\n") rawWriteFile.close()
def approveJunit( baseName, args ): global overallResult args[0:0] = [cmdPath] baselinesPath = os.path.join( rootPath, '{0}.approved.txt'.format( baseName ) ) baselinesSortedPath = os.path.join( rootPath, '{0}.sorted.approved.txt'.format( baseName ) ) #baselinesFixedPath = os.path.join( rootPath, '{0}.rewrite.approved.txt'.format( baseName ) ) rawResultsPath = os.path.join( rootPath, '_{0}.tmp'.format( baseName ) ) if os.path.exists( baselinesPath ): xml = "" f = open( baselinesPath, 'r' ) for line in f: xml += line xml = xml.replace("<line number>", "<line number>") xml = xml.replace("<hex digits>", "<hex digits>") #f2 = open( baselinesFixedPath, 'wb' ) #f2.write(xml) #f2.close() # ClassTests.cpp:<line number> otherApprovedTestParser = re.compile( r'(.*\..pp).*:<(.*).*>' ) testRun = TestRunData() testcase = None root = etree.fromstring(xml) for testsuites in root: if testsuites.tag == "testsuite": testRun = TestRunData() testRun.appname = testsuites.get("name") testRun.errors = testsuites.get("errors") testRun.failures = testsuites.get("failures") testRun.tests = testsuites.get("tests") for tc in testsuites: if tc.tag == "testcase": cls = tc.get("classname") #print( "C:" + cls + tc ) if len(cls): testcase = testRun.addClassTestCase(cls, tc.get("name")) else: testcase = testRun.addTestCase(tc.get("name")) for prop in tc: if prop.tag == "failure": text = prop.text.strip() lines = text.splitlines() filename = "" lineNumber = "" output = [] for l in lines: m = otherApprovedTestParser.match(l) if m: filename = m.group(1) lineNumber = m.group(2) else: output.append(l) testcase.addFailure(filename, lineNumber, output, prop.get("message"), prop.get("type")) elif prop.tag == "error": text = prop.text.strip() lines = text.splitlines() filename = "" lineNumber = "" output = [] for l in lines: m = otherApprovedTestParser.match(l) if m: filename = m.group(1) lineNumber = m.group(2) else: output.append(l) testcase.addError(filename, lineNumber, output, prop.get("message"), prop.get("type")) elif prop.tag == "system-out": text = prop.text.strip() lines = text.splitlines() testcase.addSysout(lines) elif prop.tag == "system-err": text = prop.text.strip() lines = text.splitlines() testcase.addSyserr(lines) elif tc.tag == "system-out": text = tc.text.strip() lines = text.splitlines() testRun.addSysout(lines) elif tc.tag == "system-err": text = tc.text.strip() lines = text.splitlines() testRun.addSyserr(lines) else: print( tc.tag ) lines = testRun.generateSortedUnapprovedJunit() rawWriteFile = open( baselinesSortedPath, 'wb' ) for line in lines: #print( "L:" + line ) rawWriteFile.write(line + "\n") rawWriteFile.close() if not(os.path.exists( args[0] )): raise Exception("Executable does not exist: '" + args[0] + "'") f = open( rawResultsPath, 'w' ) subprocess.call( args, stdout=f, stderr=f ) f.close() rawSortedPath = os.path.join( rootPath, '{0}.sorted.unapproved.txt'.format( baseName ) ) if os.path.exists( rawResultsPath ): xml = "" f = open( rawResultsPath, 'r' ) for line in f: xml += line #xml = xml.replace("<line number>", "<line number>") #xml = xml.replace("<hex digits>", "<hex digits>") # ClassTests.cpp:<line number> otherResultsTestParser = re.compile( r'(.*\\)(.*\..pp).*\((.*).*\)' ) testRun = TestRunData() testcase = None root = etree.fromstring(xml) for testsuites in root: if testsuites.tag == "testsuite": testRun = TestRunData() testRun.appname = testsuites.get("name") testRun.errors = testsuites.get("errors") testRun.failures = testsuites.get("failures") testRun.tests = testsuites.get("tests") for tc in testsuites: if tc.tag == "testcase": cls = tc.get("classname") #print( "C:" + cls + tc ) if len(cls): if cls.startswith("::"): cls = cls[2:] testcase = testRun.addClassTestCase(cls, tc.get("name")) else: testcase = testRun.addTestCase(tc.get("name")) for prop in tc: if prop.tag == "failure": text = prop.text.strip() lines = text.splitlines() filename = "" lineNumber = "" output = [] for l in lines: m = otherResultsTestParser.match(l) if m: filename = m.group(2) lineNumber = "line number" else: output.append(l) testcase.addFailure(filename, lineNumber, output, prop.get("message"), prop.get("type")) elif prop.tag == "error": text = prop.text.strip() lines = text.splitlines() filename = "" lineNumber = "" output = [] for l in lines: m = otherResultsTestParser.match(l) if m: filename = m.group(2) lineNumber = "line number" else: output.append(l) testcase.addError(filename, lineNumber, output, prop.get("message"), prop.get("type")) elif prop.tag == "system-out": text = prop.text.strip() lines = text.splitlines() testcase.addSysout(lines) elif prop.tag == "system-err": text = prop.text.strip() lines = text.splitlines() testcase.addSyserr(lines) elif tc.tag == "system-out": text = tc.text.strip() lines = text.splitlines() testRun.addSysout(lines) elif tc.tag == "system-err": text = tc.text.strip() lines = text.splitlines() testRun.addSyserr(lines) else: print( tc.tag ) lines = testRun.generateSortedUnapprovedJunit() rawWriteFile = open( rawSortedPath, 'wb' ) for line in lines: #print( "L:" + line ) rawWriteFile.write(line + "\n") rawWriteFile.close()
def parseTrxFile(baseName, trxFile): print( "TRX file:" + trxFile ) if os.path.exists( trxFile ): xml = "" f = open( trxFile, 'r' ) for line in f: xml += line #otherResultsTestParser = re.compile( r'(.*\\)(.*\..pp)' ) #hexParser = re.compile( r'(.*)\b(0[xX][0-9a-fA-F]+)\b(.*)' ) testRun = TestRunData() testRun.appname = "CatchSelfTest" root = etree.fromstring(xml) if testRun.appname == "TestCatch.exe": testRun.appname = "CatchSelfTest" qname=re.compile("{(?P<ns>.*)}(?P<element>.*)") ids = [] for ts in root: m = qname.match(ts.tag) if m: tag = m.group(2) print( tag ) if tag != None: if tag == "TestDefinitions": for tc in ts: m = qname.match(tc.tag) if m: tag = m.group(2) if tag != None and tag == "UnitTest": name = tc.get("name") id = tc.get("id") for item in tc: m = qname.match(item.tag) if m: tag = m.group(2) if tag != None and tag == "Description": desc = item.text #print( desc + id ) ids.append([id,desc]) elif tag == "Results": #print( ids ) ids = dict(ids) #print( ids["87ec526a-e414-1a3f-ba0f-e210b204bb42"] ) lineNumber = 0 resultParser = TestCaseResultParser() for tc in ts: m = qname.match(tc.tag) if m: tag = m.group(2) if tag != None and tag == "UnitTestResult": outcome = tc.get("outcome") id = tc.get("testId") if len(id) > 0: for item in tc: m = qname.match(item.tag) if m: tag = m.group(2) if tag != None and tag == "Output": for sub in item: m = qname.match(sub.tag) if m: tag = m.group(2) if tag != None and tag == "StdOut": desc = sub.text lines = desc.splitlines() found = False index = 0 for tmp in lines: if (len(lines) >= (index + 2) and lines[index].startswith("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~") and lines[index + 1].startswith("Batch run using") ): found = True break index += 1 lines = lines[index + 3:] #print( "*******" + desc ) #print( lines ) if found: endOfRun = False for line in lines: if endOfRun: testRun.results = line.strip() else: try: testcase = resultParser.parseResultLine(line) except RandomOutput as e: #print( "E:" + self.lineNumber + ", " + e.output ) testRun.output = e.output testRun.outputLine = lineNumber - len(e.output) if isinstance(testcase, TestCaseData): testRun.testcases.append(testcase) if line.startswith("==============================================================================="): endOfRun = True lineNumber += 1 lines = testRun.generateSortedUnapprovedLines(testRun.outputLine) rawSortedPath = os.path.join( rootPath, '{0}.sorted.unapproved.txt'.format( baseName ) ) rawWriteFile = open( rawSortedPath, 'wb' ) for line in lines: #print( "L:" + line ) rawWriteFile.write(line + "\n") rawWriteFile.close()
def approveXml( baseName, args ): global overallResult args[0:0] = [cmdPath] baselinesPath = os.path.join( rootPath, '{0}.approved.txt'.format( baseName ) ) baselinesSortedPath = os.path.join( rootPath, '{0}.sorted.approved.txt'.format( baseName ) ) #baselinesFixedPath = os.path.join( rootPath, '{0}.rewrite.approved.txt'.format( baseName ) ) rawResultsPath = os.path.join( rootPath, '_{0}.tmp'.format( baseName ) ) if os.path.exists( baselinesPath ): xml = "" f = open( baselinesPath, 'r' ) for line in f: xml += line xml = xml.replace("<hex digits>", "<hex digits>") #otherApprovedTestParser = re.compile( r'(.*\..pp).*:<(.*).*>' ) testRun = TestRunData() testcase = None root = etree.fromstring(xml) testRun.appname = root.get("name") for ts in root: #print( ts.tag ) for tc in ts: if tc.tag == "TestCase": testcase = testRun.addTestCase(tc.get("name")) for exp in tc: if exp.tag == "Expression": result = exp.get("success") filename = exp.get("filename") section = testcase.addExpression(result,filename) subExp = [] for cond in exp: if cond.tag == "Original": text = cond.text ls = text.splitlines() subExp.append(ls) elif cond.tag == "Expanded" and len(subExp) == 1: text = cond.text ls = text.splitlines() subExp.append(ls) elif cond.tag == "Exception" and len(subExp) == 2: subExp.append(cond.get("filename")) text = cond.text ls = text.splitlines() subExp.append(ls) else: print( "X:" + cond.tag ) if len(subExp) >= 2: testcase.addExpressionDetails(section, subExp) elif exp.tag == "Exception": filename = exp.get("filename") text = exp.text ls = text.splitlines() section = testcase.addException(filename,ls) elif exp.tag == "Section": addSubSection(testcase, None, exp) elif exp.tag == "Info": text = exp.text ls = text.splitlines() section = testcase.addInfo(ls) elif exp.tag == "Warning": text = exp.text ls = text.splitlines() section = testcase.addWarning(ls) elif exp.tag == "Failure": ls = [] if exp.text != None: text = exp.text ls = text.splitlines() section = testcase.addSimpleFailure(ls) elif exp.tag == "OverallResult": testcase.addOverallResult(exp.get("success")) else: print( "E:" + exp.tag ) elif tc.tag == "OverallResults": testRun.tests = tc.get("successes") testRun.failures = tc.get("failures") else: print( "U:" + tc.tag ) lines = testRun.generateSortedUnapprovedXml() rawWriteFile = open( baselinesSortedPath, 'wb' ) for line in lines: #print( "L:" + line ) rawWriteFile.write(line + "\n") rawWriteFile.close() if not(os.path.exists( args[0] )): raise Exception("Executable does not exist: '" + args[0] + "'") f = open( rawResultsPath, 'w' ) subprocess.call( args, stdout=f, stderr=f ) f.close() rawSortedPath = os.path.join( rootPath, '{0}.sorted.unapproved.txt'.format( baseName ) ) if os.path.exists( rawResultsPath ): xml = "" f = open( rawResultsPath, 'r' ) for line in f: xml += line f.close() #xml = xml.replace("<hex digits>", "<hex digits>") os.remove( rawResultsPath ) otherResultsTestParser = re.compile( r'(.*\\)(.*\..pp)' ) hexParser = re.compile( r'(.*)\b(0[xX][0-9a-fA-F]+)\b(.*)' ) testRun = TestRunData() testcase = None root = etree.fromstring(xml) testRun.appname = root.get("name") if testRun.appname == "TestCatch.exe": testRun.appname = "CatchSelfTest" for ts in root: #print( ts.tag ) for tc in ts: if tc.tag == "TestCase": testcase = testRun.addTestCase(tc.get("name")) for exp in tc: if exp.tag == "Expression": result = exp.get("success") filename = exp.get("filename") m = otherResultsTestParser.match(filename) if m: filename = "/Users/philnash/Dev/OSS/Catch/projects/SelfTest/" + m.group(2) section = testcase.addExpression(result,filename) subExp = [] for cond in exp: if cond.tag == "Original": text = cond.text tmp = text.splitlines() ls = [] for li in tmp: m = hexParser.match(li) if m: while m: #print( li + m.group(1) + m.group(3) ) li = m.group(1) + "0x<hex digits>" + m.group(3) m = hexParser.match(li) ls.append(li) subExp.append(ls) elif cond.tag == "Expanded" and len(subExp) == 1: text = cond.text tmp = text.splitlines() ls = [] for li in tmp: m = hexParser.match(li) if m: while m: #print( li + m.group(1) + m.group(3) ) li = m.group(1) + "0x<hex digits>" + m.group(3) m = hexParser.match(li) ls.append(li) subExp.append(ls) elif cond.tag == "Exception" and len(subExp) == 2: filename = cond.get("filename") m = otherResultsTestParser.match(filename) if m: filename = "/Users/philnash/Dev/OSS/Catch/projects/SelfTest/" + m.group(2) subExp.append(filename) text = cond.text ls = text.splitlines() subExp.append(ls) else: print( "X:" + cond.tag ) if len(subExp) >= 2: testcase.addExpressionDetails(section, subExp) elif exp.tag == "Exception": filename = exp.get("filename") m = otherResultsTestParser.match(filename) if m: filename = "/Users/philnash/Dev/OSS/Catch/projects/SelfTest/" + m.group(2) text = exp.text ls = text.splitlines() section = testcase.addException(filename,ls) elif exp.tag == "Section": addResultsSubSection(otherResultsTestParser, testcase, None, exp) elif exp.tag == "Info": text = exp.text ls = text.splitlines() section = testcase.addInfo(ls) elif exp.tag == "Warning": text = exp.text ls = text.splitlines() section = testcase.addWarning(ls) elif exp.tag == "Failure": ls = [] if exp.text != None: text = exp.text ls = text.splitlines() section = testcase.addSimpleFailure(ls) elif exp.tag == "OverallResult": testcase.addOverallResult(exp.get("success")) else: print( "E:" + exp.tag ) elif tc.tag == "OverallResults": testRun.tests = tc.get("successes") testRun.failures = tc.get("failures") else: print( "U:" + tc.tag ) lines = testRun.generateSortedUnapprovedXml() rawWriteFile = open( rawSortedPath, 'wb' ) for line in lines: #print( "L:" + line ) rawWriteFile.write(line + "\n") rawWriteFile.close()