예제 #1
0
파일: main.py 프로젝트: bloodlee/CoverageEx
def reCalcCoverageInfo(caseInfo):

    rcFilename = genCoverageRcFileName(caseInfo)

    coverageXmlFile = 'coverage_%d.xml' % caseInfo.getSeq()

    # generate coverage report
    os.system("coverage xml --rcfile=%s -o %s" % (rcFilename, coverageXmlFile))

    # parse the coverage report
    # default report file name is 'coverage.xml'
    fileContent = open(coverageXmlFile, 'r').read()

    coverageInfo = Parser.parse(fileContent)

    emptyLines = {}
    for scriptName in coverageInfo.keys():
        # get empty lines of each script name
        lines = EmptyLineFinder.findEmptyLines(scriptName)
        emptyLines[scriptName] = lines

    coverageInfo = Parser.mergeEmptyLines(coverageInfo, emptyLines)

    os.remove(rcFilename)
    os.remove(coverageXmlFile)

    return coverageInfo
예제 #2
0
    def testReportOnlyOnePackage(self):
        result = Parser.parse(self.fileContent)

        self.assertEqual(len(result), 2)

        covInfo = result['hello.py']
        self.assertEqual(covInfo.getScriptName(), 'hello.py')
        self.assertEqual(covInfo.getAllLines(), {2,4,5,6,10,12,14,16,17,18})
예제 #3
0
    def testMerge(self):

        result = Parser.parse(self.fileContent)

        emptyLines = {
            'hello.py': [3,7,8,13,15,19]
        }

        scriptCoverRange = Parser.mergeEmptyLines(result, emptyLines)

        ranges = scriptCoverRange['hello.py']
        self.assertEqual(ranges[0], Range(2,8))
        self.assertEqual(ranges[1], Range(10, 10))
        self.assertEqual(ranges[2], Range(12,19))
예제 #4
0
    def testReportDataWithDb(self):
        db = TestCaseDB(DEFAULT_DB_NAME)

        result = Parser.parse(self.fileContent)

        db.refreshCoverageData(1, result)

        result2 = db.getCoverageData(1)

        self.assertEqual(len(result), len(result2))

        for fileName in result.keys():
            self.assertTrue(fileName in result2.keys())

            covInfo1 = result[fileName]
            covInfo2 = result2[fileName]

            self.assertTrue(covInfo1.getAllLines(), covInfo2.getAllLines())