Beispiel #1
0
 def test_invalid_outcome(self):
     j = junit.JUnit("test")
     self.assertRaises(ValueError,
                       j.add_test,
                       "Foo.Bar",
                       1.23,
                       outcome=1024)
Beispiel #2
0
    def test_basic_testsuite(self):
        j = junit.JUnit("test")
        j.add_test("Foo.Bar", 3.14)
        j.add_test("Foo.Baz", 13.37, outcome=junit.JUnit.FAILURE)
        j.add_test("Eggs.Spam", 42.00, outcome=junit.JUnit.ERROR)

        expected = """
<testsuite errors="1" failures="1" name="test" tests="3" time="58.51">
<testcase classname="Foo" name="Bar" time="3.14" />
<testcase classname="Foo" name="Baz" time="13.37" />
<testcase classname="Eggs" name="Spam" time="42.00" />
</testsuite>"""
        self.assertEqual(expected.replace("\n", ""), j.to_xml())
Beispiel #3
0
    def report(self, tasks=None, out=None, open_it=False, out_format="html"):
        """Generate report file for specified task.

        :param task_id: UUID, task identifier
        :param tasks: list, UUIDs od tasks or pathes files with tasks results
        :param out: str, output file name
        :param open_it: bool, whether to open output file in web browser
        :param out_format: output format (junit, html or html_static)
        """

        tasks = isinstance(tasks, list) and tasks or [tasks]

        results = []
        message = []
        processed_names = {}
        for task_file_or_uuid in tasks:
            if os.path.exists(os.path.expanduser(task_file_or_uuid)):
                with open(os.path.expanduser(task_file_or_uuid),
                          "r") as inp_js:
                    tasks_results = json.load(inp_js)
                    for result in tasks_results:
                        try:
                            jsonschema.validate(result,
                                                api.Task.TASK_RESULT_SCHEMA)
                        except jsonschema.ValidationError as e:
                            print(
                                _("ERROR: Invalid task result format in %s") %
                                task_file_or_uuid,
                                file=sys.stderr)
                            print(six.text_type(e), file=sys.stderr)
                            return 1

            elif uuidutils.is_uuid_like(task_file_or_uuid):
                tasks_results = map(
                    lambda x: {
                        "key": x["key"],
                        "sla": x["data"]["sla"],
                        "result": x["data"]["raw"],
                        "load_duration": x["data"]["load_duration"],
                        "full_duration": x["data"]["full_duration"]
                    },
                    api.Task.get(task_file_or_uuid).get_results())
            else:
                print(_("ERROR: Invalid UUID or file name passed: %s") %
                      task_file_or_uuid,
                      file=sys.stderr)
                return 1

            for task_result in tasks_results:
                if task_result["key"]["name"] in processed_names:
                    processed_names[task_result["key"]["name"]] += 1
                    task_result["key"]["pos"] = processed_names[
                        task_result["key"]["name"]]
                else:
                    processed_names[task_result["key"]["name"]] = 0
                results.append(task_result)

        if out_format.startswith("html"):
            result = plot.plot(results,
                               include_libs=(out_format == "html_static"))
        elif out_format == "junit":
            test_suite = junit.JUnit("Rally test suite")
            for result in results:
                if isinstance(result["sla"], list):
                    message = ",".join([
                        sla["detail"] for sla in result["sla"]
                        if not sla["success"]
                    ])
                if message:
                    outcome = junit.JUnit.FAILURE
                else:
                    outcome = junit.JUnit.SUCCESS
                test_suite.add_test(result["key"]["name"],
                                    result["full_duration"], outcome, message)
            result = test_suite.to_xml()
        else:
            print(_("Invalid output format: %s") % out_format, file=sys.stderr)
            return 1

        if out:
            output_file = os.path.expanduser(out)

            with open(output_file, "w+") as f:
                f.write(result)
            if open_it:
                webbrowser.open_new_tab("file://" + os.path.realpath(out))
        else:
            print(result)
Beispiel #4
0
    def test_empty_testsuite(self):
        j = junit.JUnit("test")
        expected = """
<testsuite errors="0" failures="0" name="test" tests="0" time="0.00" />"""
        self.assertEqual(expected.replace("\n", ""), j.to_xml())