Example #1
0
    def process_test_data(self, test_data):
        """
        Convert JUnit output into a a list of report entries.

        :param test_data: JUnit test output.
        :type test_data: ``list``
        :return: list of sub reports.
        :rtype: ``list`` of (``TestGroupReport`` or ``TestCaseReport``)
        """
        result = []
        for suite in test_data:
            suite_name = suite.get("name", "JUnit testsuite")
            suite_report = TestGroupReport(
                name=suite_name,
                uid=suite_name,
                category=ReportCategories.TESTSUITE,
            )
            for case in suite.xpath("testcase"):
                case_name = case.get("name", "JUnit testcase")
                testcase_report = TestCaseReport(name=case_name, uid=case_name)
                for error in case.xpath("error"):
                    testcase_report.append(
                        registry.serialize(
                            assertions.Fail("Error executing test")
                        )
                    )
                    testcase_report.append(
                        registry.serialize(
                            CodeLog(
                                error.text,
                                language="java",
                                description="stacktrace",
                            )
                        )
                    )
                for failure in case.xpath("failure"):
                    message = failure.get("message", "testcase failure")
                    testcase_report.append(
                        registry.serialize(assertions.Fail(message))
                    )
                    if failure.text:
                        testcase_report.append(
                            registry.serialize(
                                CodeLog(
                                    failure.text,
                                    language="java",
                                    description="stacktrace",
                                )
                            )
                        )
                if not testcase_report.entries:
                    assertion_obj = assertions.RawAssertion(
                        description="Passed",
                        content="Testcase {} passed".format(case_name),
                        passed=True,
                    )
                    testcase_report.append(registry.serialize(assertion_obj))

                testcase_report.runtime_status = RuntimeStatus.FINISHED
                suite_report.append(testcase_report)
Example #2
0
def test_create_pdf(tmpdir):
    """PDF exporter should generate a PDF file using the report data."""
    pdf_path = tmpdir.mkdir("reports").join("dummy_report.pdf").strpath

    assertion_entries = [
        assertions.Equal(1, 2),
        assertions.Greater(2, 1),
        assertions.IsFalse(True, "this should fail"),
        assertions.IsTrue(True, "this should pass"),
        assertions.Fail("Explicit failure"),
        base.Group(
            description="group description",
            entries=[
                assertions.NotEqual(2, 1),
                assertions.Contain(1, [1, 2, 3]),
            ],
        ),
    ]

    # Test large assertion
    for _ in range(10):
        assertion_entries.append(
            assertions.RegexMatch("Test.*", "Testplan\n" * 500))

    report = TestReport(
        name="my testplan",
        entries=[
            TestGroupReport(
                name="My Multitest",
                category=ReportCategories.MULTITEST,
                entries=[
                    TestGroupReport(
                        name="MySuite",
                        category=ReportCategories.TESTSUITE,
                        entries=[
                            TestCaseReport(
                                name="my_test_method",
                                entries=[
                                    registry.serialize(obj)
                                    for obj in assertion_entries
                                ],
                            )
                        ],
                    )
                ],
            )
        ],
    )

    exporter = PDFExporter(
        pdf_path=pdf_path,
        pdf_style=styles.Style(passing="assertion-detail",
                               failing="assertion-detail"),
    )

    with log_propagation_disabled(TESTPLAN_LOGGER):
        exporter.export(report)

    assert os.path.exists(pdf_path)
    assert os.stat(pdf_path).st_size > 0
Example #3
0
def test_create_pdf(tmpdir):
    """PDF exporter should generate a PDF file using the report data."""
    pdf_path = tmpdir.mkdir('reports').join('dummy_report.pdf').strpath

    assertion_entries = [
        assertions.Equal(1, 2),
        assertions.Greater(2, 1),
        assertions.IsFalse(True, 'this should fail'),
        assertions.IsTrue(True, 'this should pass'),
        assertions.Fail('Explicit failure'),
        base.Group(
            description='group description',
            entries=[
                assertions.NotEqual(2, 1),
                assertions.Contain(1, [1, 2, 3]),
            ]
        )
    ]

    report = TestReport(
        name='my testplan',
        entries=[
            TestGroupReport(
                name='My Multitest',
                category='multitest',
                entries=[
                    TestGroupReport(
                        name='MySuite',
                        entries=[
                            TestCaseReport(
                                name='my_test_method',
                                entries=[
                                    registry.serialize(obj)
                                    for obj in assertion_entries
                                ]
                            )
                        ]
                    )
                ]
            )
        ]
    )

    exporter = PDFExporter(
        pdf_path=pdf_path,
        pdf_style=styles.Style(
            passing='assertion-detail',
            failing='assertion-detail'
        )
    )

    with log_propagation_disabled(TESTPLAN_LOGGER):
        exporter.export(report)

    assert os.path.exists(pdf_path)
    assert os.stat(pdf_path).st_size > 0