示例#1
0
    def test_generate(self, mock__generate, mock_dumps):
        reporter = reporters.JSONReporter([], output_destination=None)
        self.assertEqual({"print": mock_dumps.return_value},
                         reporter.generate())
        mock__generate.assert_called_once_with()
        mock_dumps.assert_called_once_with(mock__generate.return_value,
                                           indent=4)

        mock__generate.reset_mock()
        mock_dumps.reset_mock()

        path = "some_path"
        reporter = reporters.JSONReporter([], output_destination=path)
        self.assertEqual({"files": {path: mock_dumps.return_value},
                          "open": path}, reporter.generate())
        mock__generate.assert_called_once_with()
        mock_dumps.assert_called_once_with(mock__generate.return_value,
                                           indent=4)
示例#2
0
    def test__generate(self):
        reporter = reporters.JSONReporter(get_verifications(), None)
        report = reporter._generate()

        self.assertEqual(
            collections.OrderedDict(
                [("foo-bar-1", {"status": "finished",
                                "started_at": "2001-01-01T00:00:00",
                                "finished_at": "2001-01-02T00:00:00",
                                "tests_duration": 1.111,
                                "tests_count": 9,
                                "run_args": "set_name=compute",
                                "skipped": 0,
                                "success": 3,
                                "unexpected_success": 2,
                                "expected_failures": 3,
                                "failures": 1}),
                 ("foo-bar-2", {"status": "finished",
                                "started_at": "2002-01-01T00:00:00",
                                "finished_at": "2002-01-02T00:00:00",
                                "tests_duration": 22.222,
                                "tests_count": 99,
                                "run_args": "set_name=full",
                                "skipped": 0,
                                "success": 33,
                                "unexpected_success": 22,
                                "expected_failures": 33,
                                "failures": 11}),
                 ("foo-bar-3", {"status": "finished",
                                "started_at": "2003-01-01T00:00:00",
                                "finished_at": "2003-01-02T00:00:00",
                                "tests_duration": 33.333,
                                "tests_count": 99,
                                "run_args": "set_name=full",
                                "skipped": 0,
                                "success": 33,
                                "unexpected_success": 22,
                                "expected_failures": 33,
                                "failures": 11})]),
            report["verifications"])

        self.assertEqual({
            "some.test.TestCase.test_foo[id=iiiidddd;smoke]": {
                "by_verification": {"foo-bar-1": {"duration": "8",
                                                  "status": "success"},
                                    "foo-bar-2": {"duration": "8",
                                                  "status": "success"},
                                    "foo-bar-3": {"duration": "8",
                                                  "status": "success"}
                                    },
                "name": "some.test.TestCase.test_foo",
                "tags": ["smoke", "id"]},
            "some.test.TestCase.test_failed": {
                "by_verification": {"foo-bar-2": {"details": "HEEEEEEELP",
                                                  "duration": "8",
                                                  "status": "fail"},
                                    "foo-bar-3": {"details": "HEEEEEEELP",
                                                  "duration": "7",
                                                  "status": "fail"}},
                "name": "some.test.TestCase.test_failed",
                "tags": []},
            "some.test.TestCase.test_skipped": {
                "by_verification": {
                    "foo-bar-1": {
                        "details": "Skipped until Bug: https://launchpad.net/"
                                   "bugs/666 is resolved.",
                        "duration": "0",
                        "status": "skip"},
                    "foo-bar-2": {
                        "details": "Skipped until Bug: https://launchpad.net/"
                                   "bugs/666 is resolved.",
                        "duration": "0",
                        "status": "skip"},
                    "foo-bar-3": {
                        "details": "Skipped until Bug: https://launchpad.net/"
                                   "bugs/666 is resolved.",
                        "duration": "0",
                        "status": "skip"}},
                "name": "some.test.TestCase.test_skipped",
                "tags": []},
            "some.test.TestCase.test_xfail": {
                "by_verification": {
                    "foo-bar-1": {"details": "something\n\nHEEELP",
                                  "duration": "3",
                                  "status": "xfail"},
                    "foo-bar-2": {"details": "something\n\nHEEELP",
                                  "duration": "4",
                                  "status": "xfail"},
                    "foo-bar-3": {"details": "something\n\nHEEELP",
                                  "duration": "3",
                                  "status": "xfail"}},
                "name": "some.test.TestCase.test_xfail",
                "tags": []},
            "some.test.TestCase.test_uxsuccess": {
                "name": "some.test.TestCase.test_uxsuccess",
                "tags": [],
                "by_verification": {"foo-bar-1": {
                    "details": "It should fail since I expect it",
                    "duration": "3",
                    "status": "uxsuccess"}}}},
            report["tests"])