예제 #1
0
    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 )
예제 #2
0
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()
예제 #3
0
 def __init__(self):
     self.state = self.NONE
     self.current = TestRunData()
     self.testcaseParser = TestCaseResultParser()
     self.lineNumber = 0