コード例 #1
0
ファイル: report.py プロジェクト: kbm1422/New_Framework
    def genXMLReport(self, dstFilename):
        self._dom = minidom.getDOMImplementation()
        self._doc = self._dom.createDocument(None, "TestReport", None)
        self._rootelement = self._doc.documentElement
        all_totaltests = 0
        all_failures = 0
        all_warnings = 0
        for suiteresult in self._suiteresults:
            suite_totaltests = 0
            suite_failures = 0
            suite_warnings = 0
            suiteName = suiteresult["suitename"]
            suiteElement = self._rootelement.addSubElement("TestSuite")
            suiteElement.addSubElement("Name").addTextNode(suiteName)

            repeatedTestStatistics = collections.OrderedDict()
            for testresult in suiteresult["testresults"]:
                suite_totaltests += 1

                if testresult["name"] not in repeatedTestStatistics:
                    repeatedTestStatistics[testresult["name"]] = {
                        "case_totaltests": 1,
                        "statistics": collections.OrderedDict(),
                        "case_failures": 0,
                        "case_warnings": 0,
                    }
                else:
                    repeatedTestStatistics[testresult["name"]]["case_totaltests"] += 1

                testElement = suiteElement.addSubElement("Test")
                match = re.search("(\d+)$", testresult["title"])
                if match:
                    number = match.group(1)
                    testElement.addSubElement("Number").addTextNode(number)

                testElement.addSubElement("Title").addTextNode(testresult["title"])
                testElement.addSubElement("Name").addTextNode(testresult["name"])

                for comment in testresult["comments"]:
                    testElement.addSubElement("Comment").addTextNode(comment)
                    if testresult["name"] in self._statisticsCommentPrefixes:
                        filtercomments = self._statisticsCommentPrefixes[testresult["name"]]
                    else:
                        filtercomments = []
                    if testresult["result"] != "failed" and filter(lambda x: x in comment, filtercomments):
                        if "issued" in comment:
                            if "[" in comment and "]" in comment:
                                match = re.search(r"(.* issued) (\[[\.\d,]+\])s", comment)
                                name = match.group(1)
                                values = eval(match.group(2))
                                value = sum(values) / len(values)
                            else:
                                match = re.search(r"(.* issued) ([\.\d]+)", comment)
                                name = match.group(1)
                                value = match.group(2)
                        else:
                            match = re.search(r"(.*)(?: is|[ ]?:) ([\.\d]+)", comment)
                            name = match.group(1)
                            value = match.group(2)
                        if name in repeatedTestStatistics[testresult["name"]]["statistics"]:
                            repeatedTestStatistics[testresult["name"]]["statistics"][name].append(float(value))
                        else:
                            repeatedTestStatistics[testresult["name"]]["statistics"][name] = list()

                if testresult["result"] == "failed":
                    suite_failures += 1
                    repeatedTestStatistics[testresult["name"]]["case_failures"] += 1
                elif testresult["result"] == "warning":
                    suite_warnings += 1
                    repeatedTestStatistics[testresult["name"]]["case_warnings"] += 1
                else:
                    pass

                testElement.addSubElement("Result").addTextNode(testresult["result"].upper())

            for key, value in repeatedTestStatistics.items():
                if value["case_totaltests"] == 1:
                    continue
                statisticsElement = suiteElement.addSubElement("RepeatedTestStatistics")
                statisticsElement.addSubElement("Name").addTextNode(key)
                statisticsElement.addSubElement("TotalTests").addTextNode(str(value["case_totaltests"]))
                statisticsElement.addSubElement("Failures").addTextNode(str(value["case_failures"]))
                statisticsElement.addSubElement("Warnings").addTextNode(str(value["case_warnings"]))

                failrate = round(float(value["case_failures"]) / float(value["case_totaltests"]), 3) * 100
                statisticsElement.addSubElement("FailRate").addTextNode(str(failrate) + "%")

                for stakey, stavalue in repeatedTestStatistics[key]["statistics"].items():
                    if stavalue:
                        statisticsElement.addSubElement("AverageStatistics").addTextNode(
                            "%s: %s" % (stakey, sum(stavalue) / len(stavalue))
                        )

            suiteElement.addSubElement("TotalTests").addTextNode(str(suite_totaltests))
            suiteElement.addSubElement("Failures").addTextNode(str(suite_failures))
            suiteElement.addSubElement("Warnings").addTextNode(str(suite_warnings))

            failrate = round(float(suite_failures) / float(suite_totaltests), 3) * 100
            warnrate = round(float(suite_warnings) / float(suite_totaltests), 3) * 100
            summary = "Total Tests:%s. Failures:%s. Warnings:%s. Fail Rate: %s%%. Warning Rate: %s%%" % (
                suite_totaltests,
                suite_failures,
                suite_warnings,
                failrate,
                warnrate,
            )
            suiteElement.addSubElement("Summary").addTextNode(summary)

            all_totaltests += suite_totaltests
            all_failures += suite_failures
            all_warnings += suite_warnings

        failrate = round(float(all_failures) / float(all_totaltests), 3) * 100
        warnrate = round(float(all_warnings) / float(all_totaltests), 3) * 100
        summary = "Total Tests:%s. Failures:%s. Warnings:%s. Suite Fail Rate: %s%%. Suite Warning Rate: %s%%" % (
            all_totaltests,
            all_failures,
            all_warnings,
            failrate,
            warnrate,
        )
        self._rootelement.addSubElement("Summary").addTextNode(summary)

        with open(dstFilename, "w") as fdst:
            fdst.write(self._doc.toprettyxml())
コード例 #2
0
ファイル: report.py プロジェクト: kbm1422/New_Framework
    def genXMLReport(self, dstFilename):
        self._dom = minidom.getDOMImplementation()
        self._doc = self._dom.createDocument(None, "TestReport", None)
        self._rootelement = self._doc.documentElement
        all_totaltests = 0
        all_failures = 0
        all_warnings = 0
        tests_number = 0
        for suiteresult in self._suiteresults:
            suite_totaltests = 0
            suite_failures = 0
            suite_warnings = 0
            suiteName = suiteresult["suitename"]
            suiteElement = self._rootelement.addSubElement("TestSuite")
            suiteElement.addSubElement("Name").addTextNode(suiteName)

            repeatedTestStatistics = collections.OrderedDict()
            for testresult in suiteresult["testresults"]:
                suite_totaltests += 1

                if testresult["name"] not in repeatedTestStatistics:
                    repeatedTestStatistics[testresult["name"]] = {
                        "case_totaltests": 1,
                        "statistics": collections.OrderedDict(),
                        "case_failures": 0,
                        "case_warnings": 0,
                    }
                else:
                    repeatedTestStatistics[testresult["name"]]["case_totaltests"] += 1

                testElement = suiteElement.addSubElement("Test")
                # match = re.search("(\d+)$", testresult["title"])
                # if match:
                #    number = match.group(1)
                tests_number += 1
                testElement.addSubElement("Number").addTextNode(str(tests_number))

                testElement.addSubElement("Title").addTextNode(testresult["title"])
                testElement.addSubElement("Name").addTextNode(testresult["name"])

                for comment in testresult["comments"]:
                    _comment_text = comment["CheckPoint"]
                    if not _comment_text:
                        _comment_text = "CheckPort:None"
                    else:
                        _comment_text = (
                            "CheckPoint:"
                            + comment["CheckPoint"][0]
                            + " Result:"
                            + self.results[str(comment["CheckPoint"][1])]
                        )

                    testElement.addSubElement("Comment").addTextNode(_comment_text)

                if testresult["result"] == "FAILED":
                    suite_failures += 1
                    repeatedTestStatistics[testresult["name"]]["case_failures"] += 1
                elif testresult["result"] == "WARNING":
                    suite_warnings += 1
                    repeatedTestStatistics[testresult["name"]]["case_warnings"] += 1
                else:
                    pass

                testElement.addSubElement("Result").addTextNode(testresult["result"].upper())

            for key, value in repeatedTestStatistics.items():
                if value["case_totaltests"] == 1:
                    continue
                statisticsElement = suiteElement.addSubElement("RepeatedTestStatistics")
                statisticsElement.addSubElement("Name").addTextNode(key)
                statisticsElement.addSubElement("TotalTests").addTextNode(str(value["case_totaltests"]))
                statisticsElement.addSubElement("Failures").addTextNode(str(value["case_failures"]))
                statisticsElement.addSubElement("Warnings").addTextNode(str(value["case_warnings"]))

                failrate = round(float(value["case_failures"]) / float(value["case_totaltests"]), 3) * 100
                statisticsElement.addSubElement("FailRate").addTextNode(str(failrate) + "%")

                for stakey, stavalue in repeatedTestStatistics[key]["statistics"].items():
                    if stavalue:
                        statisticsElement.addSubElement("AverageStatistics").addTextNode(
                            "%s: %s" % (stakey, sum(stavalue) / len(stavalue))
                        )

            suiteElement.addSubElement("TotalTests").addTextNode(str(suite_totaltests))
            suiteElement.addSubElement("Failures").addTextNode(str(suite_failures))
            suiteElement.addSubElement("Warnings").addTextNode(str(suite_warnings))

            failrate = round(float(suite_failures) / float(suite_totaltests), 3) * 100
            warnrate = round(float(suite_warnings) / float(suite_totaltests), 3) * 100
            summary = "Total Tests:%s. Failures:%s. Warnings:%s. Fail Rate: %s%%. Warning Rate: %s%%" % (
                suite_totaltests,
                suite_failures,
                suite_warnings,
                failrate,
                warnrate,
            )
            suiteElement.addSubElement("Summary").addTextNode(summary)

            all_totaltests += suite_totaltests
            all_failures += suite_failures
            all_warnings += suite_warnings

        failrate = round(float(all_failures) / float(all_totaltests), 3) * 100
        warnrate = round(float(all_warnings) / float(all_totaltests), 3) * 100
        summary = "Total Tests:%s. Failures:%s. Warnings:%s. Suite Fail Rate: %s%%. Suite Warning Rate: %s%%" % (
            all_totaltests,
            all_failures,
            all_warnings,
            failrate,
            warnrate,
        )
        self._rootelement.addSubElement("Summary").addTextNode(summary)

        with open(dstFilename, "w") as fdst:
            fdst.write(self._doc.toprettyxml())