How to use the pycobertura.TextReporter function in pycobertura

To help you get started, we’ve selected a few pycobertura examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dhermes / bezier / scripts / report_lcov.py View on Github external
def report_coverage(lcov_filename):
    with open(lcov_filename, "r") as file_obj:
        contents = file_obj.read()
    converter = lcov_cobertura.LcovCobertura(contents)
    cobertura_xml = converter.convert()

    with tempfile.NamedTemporaryFile(mode="w+") as file_obj:
        file_obj.write(cobertura_xml)
        file_obj.seek(0)
        report = file_obj.name
        cobertura = pycobertura.Cobertura(report)

    reporter = pycobertura.TextReporter(cobertura)
    print(reporter.generate())
    # The status code will be the number of files under the
    # threshold.
    return sum(
        cobertura.line_rate(source_file) < THRESHOLD
        for source_file in cobertura.files()
    )