def testCaseBasicResults(self): obj = TestCaseResultParser() lines = [ "-------------------------------------------------------------------------------", "./failing/TestClass/failingCase", "-------------------------------------------------------------------------------", "..\..\..\SelfTest\ClassTests.cpp(34)", "...............................................................................", "", "..\..\..\SelfTest\ClassTests.cpp(28): FAILED:", " REQUIRE( s == \"world\" )", "with expansion:", " \"hello\" == \"world\"", "", "===============================================================================" ] newLines = [] for line in lines: result = obj.parseResultLine(line) if isinstance(result, TestCaseData): newLines += result.generateResultLines() newLines.append("===============================================================================") #for line in newLines: # print line self.assertTrue( len(lines) == len(newLines) ) self.assertTrue( lines == newLines )
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 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 __init__(self): self.state = self.NONE self.current = TestRunData() self.testcaseParser = TestCaseResultParser() self.lineNumber = 0
class TestRunResultParser: NONE = 0 VERSION_EXPECTED = 1 TEST_CASE_EXPECTED = 2 END_RUN_INFO = 3 versionParser = re.compile( r'(.*)is a (Catch v[0-9]*.[0-9]* b[0-9]*).*' ) def __init__(self): self.state = self.NONE self.current = TestRunData() self.testcaseParser = TestCaseResultParser() self.lineNumber = 0 def parseResultLine(self,line): result = None if self.state == self.NONE: if line.startswith("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"): self.state = self.VERSION_EXPECTED elif len(line): self.current.output.append(line.strip()) if len(self.current.output) == 10: if (self.current.output[0] == "Message from section one" and self.current.output[1] == "Message from section two" and self.current.output[2] == "Some information" and self.current.output[3] == "An error" and self.current.output[4] == "Message from section one" and self.current.output[5] == "Message from section two" and self.current.output[6] == "Some information" and self.current.output[7] == "An error" and self.current.output[8] == "hello" and self.current.output[9] == "hello" ): self.current.outputLine = self.lineNumber - 9 elif self.state == self.VERSION_EXPECTED: m = self.versionParser.match(line) if m: self.current.appname = m.group(1).strip() self.current.version = m.group(2).strip() self.state = self.TEST_CASE_EXPECTED elif len(line): raise Exception("Unknown parse line: '" + line + "'") elif self.state == self.TEST_CASE_EXPECTED: if line == "Run with -? for options": pass else: testcase = None try: testcase = self.testcaseParser.parseResultLine(line) except RandomOutput as e: #print "E:", self.lineNumber, ", ",e.output self.current.output = e.output self.current.outputLine = self.lineNumber - 10 if isinstance(testcase, TestCaseData): self.current.testcases.append(testcase) if line.startswith("==============================================================================="): self.state = self.END_RUN_INFO elif self.state == self.END_RUN_INFO: if len(line): self.current.results = line.strip() result = self.current self.lineNumber += 1 return result
class TestRunResultParser: NONE = 0 VERSION_EXPECTED = 1 TEST_CASE_EXPECTED = 2 END_RUN_INFO = 3 versionParser = re.compile(r'(.*)is a (Catch v[0-9]*.[0-9]* b[0-9]*).*') def __init__(self): self.state = self.NONE self.current = TestRunData() self.testcaseParser = TestCaseResultParser() self.lineNumber = 0 def parseResultLine(self, line): result = None if self.state == self.NONE: if line.startswith( "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" ): self.state = self.VERSION_EXPECTED elif len(line): self.current.output.append(line.strip()) if len(self.current.output) == 10: if (self.current.output[0] == "Message from section one" and self.current.output[1] == "Message from section two" and self.current.output[2] == "Some information" and self.current.output[3] == "An error" and self.current.output[4] == "Message from section one" and self.current.output[5] == "Message from section two" and self.current.output[6] == "Some information" and self.current.output[7] == "An error" and self.current.output[8] == "hello" and self.current.output[9] == "hello"): self.current.outputLine = self.lineNumber - 9 elif self.state == self.VERSION_EXPECTED: m = self.versionParser.match(line) if m: self.current.appname = m.group(1).strip() self.current.version = m.group(2).strip() self.state = self.TEST_CASE_EXPECTED elif len(line): raise Exception("Unknown parse line: '" + line + "'") elif self.state == self.TEST_CASE_EXPECTED: if line == "Run with -? for options": pass else: testcase = None try: testcase = self.testcaseParser.parseResultLine(line) except RandomOutput as e: #print "E:", self.lineNumber, ", ",e.output self.current.output = e.output self.current.outputLine = self.lineNumber - 10 if isinstance(testcase, TestCaseData): self.current.testcases.append(testcase) if line.startswith( "===============================================================================" ): self.state = self.END_RUN_INFO elif self.state == self.END_RUN_INFO: if len(line): self.current.results = line.strip() result = self.current self.lineNumber += 1 return result