def generate(self):
        test_cases = []
        t = self.tasks_results[0]
        created_at = dt.datetime.strptime(t["created_at"], "%Y-%m-%dT%H:%M:%S")
        updated_at = dt.datetime.strptime(t["updated_at"], "%Y-%m-%dT%H:%M:%S")
        testsuite_data = {
            "id": t["uuid"],
            "name": "heketi-rally-cases",
            "tests": 0,
            "errors": "0",
            "skipped": "0",
            "failures": 0,
            "time": "%.2f" % (updated_at - created_at).total_seconds(),
            "timestamp": t["created_at"],
        }
        for test_suite in self.tasks_results:
            for subtask in test_suite["subtasks"]:
                for workload in subtask["workloads"]:
                    test_case = {
                        "time": "%.2f" % workload["full_duration"],
                        "name": subtask["title"],
                        "classname": workload["name"],
                        "timestamp": workload["created_at"],
                    }
                    if not workload["pass_sla"]:
                        testsuite_data["failures"] += 1
                        test_case["failure"] = "\n".join([
                            s["detail"] for s in workload["sla_results"]["sla"]
                            if not s["success"]
                        ])
                    test_cases.append(test_case)

        testsuite_data["tests"] = str(len(test_cases))
        testsuite_data["failures"] = str(testsuite_data["failures"])

        testsuite = ET.Element("testsuite", testsuite_data)
        testsuite.append(
            ET.Comment(
                "Report is generated by Rally %s at %s" %
                (version.version_string(), dt.datetime.utcnow().strftime(
                    consts.TimeFormat.ISO8601))))
        for test_case in test_cases:
            failure = test_case.pop("failure", None)
            test_case = ET.SubElement(testsuite, "testcase", test_case)
            if failure:
                ET.SubElement(test_case, "failure").text = failure

        utils.prettify_xml(testsuite)
        raw_report = ET.tostring(testsuite, encoding="utf-8").decode("utf-8")

        if self.output_destination:
            return {
                "files": {
                    self.output_destination: raw_report
                },
                "open": "file://" + os.path.abspath(self.output_destination),
            }
        else:
            return {"print": raw_report}
コード例 #2
0
ファイル: junit.py プロジェクト: andreykurilin/rally
    def generate(self):
        root = ET.Element("testsuites")
        root.append(ET.Comment("Report is generated by Rally %s at %s" % (
            version.version_string(),
            dt.datetime.utcnow().strftime(consts.TimeFormat.ISO8601))))

        for t in self.tasks_results:
            created_at = dt.datetime.strptime(t["created_at"],
                                              "%Y-%m-%dT%H:%M:%S")
            updated_at = dt.datetime.strptime(t["updated_at"],
                                              "%Y-%m-%dT%H:%M:%S")
            task = {
                "id": t["uuid"],
                "tests": 0,
                "errors": "0",
                "skipped": "0",
                "failures": 0,
                "time": "%.2f" % (updated_at - created_at).total_seconds(),
                "timestamp": t["created_at"],
            }
            test_cases = []
            for workload in itertools.chain(
                    *[s["workloads"] for s in t["subtasks"]]):
                class_name, name = workload["name"].split(".", 1)
                test_case = {
                    "id": workload["uuid"],
                    "time": "%.2f" % workload["full_duration"],
                    "name": name,
                    "classname": class_name,
                    "timestamp": workload["created_at"]
                }
                if not workload["pass_sla"]:
                    task["failures"] += 1
                    test_case["failure"] = "\n".join(
                        [s["detail"]
                         for s in workload["sla_results"]["sla"]
                         if not s["success"]])
                test_cases.append(test_case)

            task["tests"] = str(len(test_cases))
            task["failures"] = str(task["failures"])

            testsuite = ET.SubElement(root, "testsuite", task)
            for test_case in test_cases:
                failure = test_case.pop("failure", None)
                test_case = ET.SubElement(testsuite, "testcase", test_case)
                if failure:
                    ET.SubElement(test_case, "failure").text = failure

        utils.prettify_xml(root)

        raw_report = ET.tostring(root, encoding="utf-8").decode("utf-8")

        if self.output_destination:
            return {"files": {self.output_destination: raw_report},
                    "open": "file://" + os.path.abspath(
                        self.output_destination)}
        else:
            return {"print": raw_report}
コード例 #3
0
ファイル: mdutils.py プロジェクト: xrally/xrally-docs
    def get_string(self):
        document = ET.Element("table")

        if self._title:
            title = ET.SubElement(document, "caption")
            title.text = self._title
        if self._headers:
            thead = ET.SubElement(document, "thead")
            tr = ET.SubElement(thead, "tr")
            for header in self._headers:
                th = ET.SubElement(tr, "th")
                th.text = header

        tbody = ET.SubElement(document, "tbody")
        for row in self._rows:
            tr = ET.SubElement(tbody, "tr")
            for i, cell in enumerate(row):
                if self._nowrap is True or (i < len(self._nowrap)
                                            and self._nowrap[i]):
                    td = ET.SubElement(tr, "td", style="white-space: nowrap")
                else:
                    td = ET.SubElement(tr, "td")
                if isinstance(cell, dict):
                    if cell["elements"]:
                        for elem in cell["elements"]:
                            td.append(elem)
                    if cell["text"]:
                        td.text = cell["text"]
                else:
                    td.text = cell

        rally_utils.prettify_xml(document)

        # NOTE(andreykurilin): we do not want to escape chars, so we can inject
        #   custom things.
        original_escape_cdata = ET._escape_cdata
        ET._escape_cdata = _escape_cdata

        document = ET.tostring(
            document,
            encoding="utf-8",
            # use 'html' method to force adding closing tags
            method="html").decode("utf-8")
        ET._escape_cdata = original_escape_cdata
        return document
コード例 #4
0
ファイル: reporters.py プロジェクト: andreykurilin/rally
    def generate(self):
        root = ET.Element("testsuites")

        root.append(ET.Comment("Report is generated by Rally %s at %s" % (
            version.version_string(),
            dt.datetime.utcnow().strftime(TIME_FORMAT))))

        for v in self.verifications:
            verification = ET.SubElement(root, "testsuite", {
                "id": v.uuid,
                "time": str(v.tests_duration),
                "tests": str(v.tests_count),
                "errors": "0",
                "skipped": str(v.skipped),
                "failures": str(v.failures + v.unexpected_success),
                "timestamp": v.created_at.strftime(TIME_FORMAT)
            })
            tests = sorted(v.tests.values(),
                           key=lambda t: (t.get("timestamp", ""), t["name"]))
            for result in tests:
                class_name, name = result["name"].rsplit(".", 1)
                test_case = {
                    "time": result["duration"],
                    "name": name, "classname": class_name
                }

                test_id = [tag[3:] for tag in result.get("tags", [])
                           if tag.startswith("id-")]
                if test_id:
                    test_case["id"] = test_id[0]
                if "timestamp" in result:
                    test_case["timestamp"] = result["timestamp"]

                test_case_element = ET.SubElement(verification, "testcase",
                                                  test_case)
                if result["status"] == "success":
                    # nothing to add
                    pass
                elif result["status"] == "uxsuccess":
                    # NOTE(andreykurilin): junit doesn't support uxsuccess
                    #   status, so let's display it like "fail" with proper
                    # comment.
                    failure = ET.SubElement(test_case_element, "failure")
                    failure.text = ("It is an unexpected success. The test "
                                    "should fail due to: %s" %
                                    result.get("reason", "Unknown reason"))
                elif result["status"] == "fail":
                    failure = ET.SubElement(test_case_element, "failure")
                    failure.text = result.get("traceback", None)
                elif result["status"] == "xfail":
                    # NOTE(andreykurilin): junit doesn't support xfail status,
                    # so let's display it like "success" with proper comment
                    test_case_element.append(ET.Comment(
                        "It is an expected failure due to: %s" %
                        result.get("reason", "Unknown reason")))
                    trace = result.get("traceback", None)
                    if trace:
                        test_case_element.append(ET.Comment(
                            "Traceback:\n%s" % trace))
                elif result["status"] == "skip":
                    skipped = ET.SubElement(test_case_element, "skipped")
                    skipped.text = result.get("reason", "Unknown reason")
                else:
                    # wtf is it?! we should add validation of results...
                    pass

            utils.prettify_xml(root)

        raw_report = ET.tostring(root, encoding="utf-8").decode("utf-8")
        if self.output_destination:
            return {"files": {self.output_destination: raw_report},
                    "open": self.output_destination}
        else:
            return {"print": raw_report}
コード例 #5
0
    def generate(self):
        root = ET.Element("testsuites")

        root.append(ET.Comment("Report is generated by Rally %s at %s" % (
            version.version_string(),
            dt.datetime.utcnow().strftime(TIME_FORMAT))))

        for v in self.verifications:
            verification = ET.SubElement(root, "testsuite", {
                "id": v.uuid,
                "time": str(v.tests_duration),
                "tests": str(v.tests_count),
                "errors": "0",
                "skipped": str(v.skipped),
                "failures": str(v.failures + v.unexpected_success),
                "timestamp": v.created_at.strftime(TIME_FORMAT)
            })
            tests = sorted(v.tests.values(),
                           key=lambda t: (t.get("timestamp", ""), t["name"]))
            for result in tests:
                class_name, name = result["name"].rsplit(".", 1)
                test_case = {
                    "time": result["duration"],
                    "name": name, "classname": class_name
                }

                test_id = [tag[3:] for tag in result.get("tags", [])
                           if tag.startswith("id-")]
                if test_id:
                    test_case["id"] = test_id[0]
                if "timestamp" in result:
                    test_case["timestamp"] = result["timestamp"]

                test_case_element = ET.SubElement(verification, "testcase",
                                                  test_case)
                if result["status"] == "success":
                    # nothing to add
                    pass
                elif result["status"] == "uxsuccess":
                    # NOTE(andreykurilin): junit doesn't support uxsuccess
                    #   status, so let's display it like "fail" with proper
                    # comment.
                    failure = ET.SubElement(test_case_element, "failure")
                    failure.text = ("It is an unexpected success. The test "
                                    "should fail due to: %s" %
                                    result.get("reason", "Unknown reason"))
                elif result["status"] == "fail":
                    failure = ET.SubElement(test_case_element, "failure")
                    failure.text = result.get("traceback", None)
                elif result["status"] == "xfail":
                    # NOTE(andreykurilin): junit doesn't support xfail status,
                    # so let's display it like "success" with proper comment
                    test_case_element.append(ET.Comment(
                        "It is an expected failure due to: %s" %
                        result.get("reason", "Unknown reason")))
                    trace = result.get("traceback", None)
                    if trace:
                        test_case_element.append(ET.Comment(
                            "Traceback:\n%s" % trace))
                elif result["status"] == "skip":
                    skipped = ET.SubElement(test_case_element, "skipped")
                    skipped.text = result.get("reason", "Unknown reason")
                else:
                    # wtf is it?! we should add validation of results...
                    pass

            utils.prettify_xml(root)

        raw_report = ET.tostring(root, encoding="utf-8").decode("utf-8")
        if self.output_destination:
            return {"files": {self.output_destination: raw_report},
                    "open": self.output_destination}
        else:
            return {"print": raw_report}