Exemple #1
0
def report_file(path, html_writer):
    """Report on one XML file."""

    with open(path) as xml_file:
        tree = etree.parse(xml_file)                # pylint: disable=no-member
    suite = tree.xpath("/testsuite")[0]

    results = TestResults.from_element(suite)
    html = u'<span class="count">{number}:</span> {path}: {results}'.format(
        path=escape(path),
        results=results,
        number=results.errors+results.failures,
    )
    html_writer.start_section(html, klass="file")

    errors = collections.defaultdict(list)
    for element in tree.xpath(".//error|.//failure"):
        error_line = error_line_from_error_element(element)
        testcases = element.xpath("..")
        if testcases:
            errors[error_line].append(testcases[0])

    errors = sorted(errors.items(), key=lambda kv: len(kv[1]), reverse=True)
    for message, testcases in errors:
        html = u'<span class="count">{0:d}:</span> {1}'.format(len(testcases), escape(clipped(message)))
        html_writer.start_section(html, klass="error")
        for testcase in testcases:
            html_writer.start_section(escape(testcase_name(testcase)), klass="test")
            error_element = testcase.xpath("error|failure")[0]
            html_writer.write("""<pre class="stdout">""")
            html_writer.write(escape(error_element.get("message")))
            html_writer.write(u"\n"+escape(error_element.text))
            html_writer.write("</pre>")
            html_writer.end_section()
        html_writer.end_section()

    skipped = collections.defaultdict(list)
    for element in tree.xpath(".//skipped"):
        error_line = error_line_from_error_element(element)
        testcases = element.xpath("..")
        if testcases:
            skipped[error_line].append(testcases[0])

    if skipped:
        total = sum(len(v) for v in skipped.values())
        html_writer.start_section(u'<span class="count">{0:d}:</span> Skipped'.format(total), klass="skipped")
        skipped = sorted(skipped.items(), key=lambda kv: len(kv[1]), reverse=True)
        for message, testcases in skipped:
            html = u'<span class="count">{0:d}:</span> {1}'.format(len(testcases), escape(clipped(message)))
            html_writer.start_section(html, klass="error")
            for testcase in testcases:
                html_writer.write('<div>{}</div>'.format(escape(testcase_name(testcase))))
            html_writer.end_section()

        html_writer.end_section()

    html_writer.end_section()
    return results
Exemple #2
0
def main(start):
    totals = TestResults()
    html_writer = HtmlOutlineWriter(sys.stdout)
    for dirpath, _, filenames in os.walk(start):
        for name in ["nosetests.xml", "xunit.xml"]:
            if name in filenames:
                results = report_file(os.path.join(dirpath, name), html_writer)
                totals += results
    html_writer.write(escape(str(totals)))
Exemple #3
0
def main(input_files, output_file):
    os.makedirs(os.path.dirname(output_file))

    out_suite = etree.fromstring("<testsuite></testsuite>")
    tree = etree.ElementTree(out_suite)

    totals = TestResults()

    for input_file in input_files:
        with open(input_file) as in_xml:
            in_tree = etree.parse(in_xml)
        for testsuite in in_tree.xpath("/testsuite"):
            totals += TestResults.from_element(testsuite)
            for testcase in testsuite.xpath("testcase"):
                out_suite.append(testcase)

    totals.onto_element(out_suite)

    with open(output_file, "w") as out_xml:
        out_xml.write(etree.tostring(tree, pretty_print=True, xml_declaration=True, encoding="utf8"))
Exemple #4
0
def main(input_files, output_file):
    os.makedirs(os.path.dirname(output_file))

    out_suite = etree.fromstring("<testsuite></testsuite>")
    tree = etree.ElementTree(out_suite)

    totals = TestResults()

    for input_file in input_files:
        with open(input_file) as in_xml:
            in_tree = etree.parse(in_xml)
        for testsuite in in_tree.xpath("/testsuite"):
            totals += TestResults.from_element(testsuite)
            for testcase in testsuite.xpath("testcase"):
                out_suite.append(testcase)

    totals.onto_element(out_suite)

    with open(output_file, "w") as out_xml:
        out_xml.write(
            etree.tostring(tree,
                           pretty_print=True,
                           xml_declaration=True,
                           encoding="utf8"))