How to use the gcovr.utils.presentable_filename function in gcovr

To help you get started, we’ve selected a few gcovr 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 gcovr / gcovr / gcovr / cobertura_xml_generator.py View on Github external
"version", "gcovr %s" % (__version__,)
    )

    # Generate the  element: this is either the root directory
    # (specified by --root), or the CWD.
    # sources = doc.createElement("sources")
    sources = etree.SubElement(root, "sources")

    # Generate the coverage output (on a per-package basis)
    # packageXml = doc.createElement("packages")
    packageXml = etree.SubElement(root, "packages")
    packages = {}

    for f in sorted(covdata):
        data = covdata[f]
        filename = presentable_filename(f, root_filter=options.root_filter)
        if '/' in filename:
            directory, fname = filename.rsplit('/', 1)
        else:
            directory, fname = '', filename

        package = packages.setdefault(
            directory, [etree.Element("package"), {}, 0, 0, 0, 0]
        )
        c = etree.Element("class")
        # The Cobertura DTD requires a methods section, which isn't
        # trivial to get from gcov (so we will leave it blank)
        etree.SubElement(c, "methods")
        lines = etree.SubElement(c, "lines")

        class_lines = 0
        class_hits = 0
github gcovr / gcovr / gcovr / txt_generator.py View on Github external
def _summarize_file_coverage(coverage):
        filename = presentable_filename(
            coverage.filename, root_filter=options.root_filter)
        filename = filename.ljust(40)
        if len(filename) > 40:
            filename = filename + "\n" + " " * 40

        if options.show_branch:
            total, cover, percent = coverage.branch_coverage()
            uncovered_lines = coverage.uncovered_branches_str()
        else:
            total, cover, percent = coverage.line_coverage()
            uncovered_lines = coverage.uncovered_lines_str()
        percent = '--' if percent is None else str(int(percent))
        return (total, cover,
                filename + str(total).rjust(8) + str(cover).rjust(8)
                + percent.rjust(6) + "%   " + uncovered_lines)
github gcovr / gcovr / gcovr / json_generator.py View on Github external
def print_json_report(covdata, output_file, options):
    r"""produce an JSON report in the format partially
    compatible with gcov JSON output"""

    gcovr_json_root = {}
    gcovr_json_root['gcovr/format_version'] = JSON_FORMAT_VERSION
    gcovr_json_root['files'] = []

    for no in sorted(covdata):
        gcovr_json_file = {}
        gcovr_json_file['file'] = presentable_filename(covdata[no].filename, root_filter=options.root_filter)
        gcovr_json_file['lines'] = _json_from_lines(covdata[no].lines)
        gcovr_json_root['files'].append(gcovr_json_file)

    write_json = json.dump
    if options.prettyjson:
        write_json = functools.partial(write_json, indent=PRETTY_JSON_INDENT, separators=(',', ': '), sort_keys=True)
    else:
        write_json = functools.partial(write_json, sort_keys=True)

    if options.output:
        with open(options.output, 'w') as output:
            write_json(gcovr_json_root, output)
    else:
        write_json(gcovr_json_root, sys.stdout)
github gcovr / gcovr / gcovr / sonarqube_generator.py View on Github external
def print_sonarqube_report(covdata, output_file, options):
    """produce an XML report in the Sonarqube generic coverage format"""

    root = etree.Element("coverage")
    root.set("version", "1")

    for f in sorted(covdata):
        data = covdata[f]
        filename = presentable_filename(f, root_filter=options.root_filter)

        fileNode = etree.Element("file")
        fileNode.set("path", filename)

        for lineno in sorted(data.lines):
            line_cov = data.lines[lineno]
            if not line_cov.is_covered and not line_cov.is_uncovered:
                continue

            L = etree.Element("lineToCover")
            L.set("lineNumber", str(lineno))
            if line_cov.is_covered:
                L.set("covered", "true")
            else:
                L.set("covered", "false")