How to use the pycobertura.utils.reconcile_lines 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 aconrad / pycobertura / pycobertura / cobertura.py View on Github external
"""
        if self.cobertura1.has_file(filename) and self.cobertura1.filesystem.has_file(
            filename
        ):
            lines1 = self.cobertura1.source_lines(filename)
            line_statuses1 = dict(self.cobertura1.line_statuses(filename))
        else:
            lines1 = []
            line_statuses1 = {}

        lines2 = self.cobertura2.source_lines(filename)
        line_statuses2 = dict(self.cobertura2.line_statuses(filename))

        # Build a dict of lineno2 -> lineno1
        lineno_map = reconcile_lines(lines2, lines1)

        # if we are using a single coverage file, we need to translate the
        # coverage of lines1 so that it corresponds to its real lines.
        if self.cobertura1 == self.cobertura2:
            line_statuses1 = {}
            for l2, l1 in lineno_map.items():
                line_statuses1[l1] = line_statuses2.get(l2)

        lines = []
        for lineno, source in enumerate(lines2, start=1):
            status = None
            reason = None
            if lineno not in lineno_map:
                # line was added or removed, just use whatever coverage status
                # is available as there is nothing to compare against.
                status = line_statuses2.get(lineno)