Exemplo n.º 1
0
    def restrict_to_files(self, files: Iterable[str]) -> 'TestCoverage':
        """Returns a variant of this coverage, restricted to given files.

        Parameters
        ----------
        files: Iterable[str]
            A list of filenames (that may or may not contain Unix wildcards)
        """
        lines: List[FileLine] = []
        # NOTE this could be _much_ more efficient, but for now, performance
        # isnt really a concern
        for line in self:
            filename = line.filename
            if any(True for pattern in files if fnmatch.fnmatch(filename, pattern)):
                lines.append(line)
        return TestCoverage(self.test, self.outcome, FileLineSet.from_iter(lines))
Exemplo n.º 2
0
 def locations(self) -> Set[FileLine]:
     """Returns the set of all locations that are covered in this map."""
     locs: Set[FileLine] = FileLineSet()
     if not self.__mapping:
         return locs
     return locs.union(*self.values())
Exemplo n.º 3
0
 def from_dict(d: Dict[str, Any]) -> 'TestCoverage':
     name = d['name']
     outcome = TestOutcome.from_dict(d['outcome'])
     lines = FileLineSet.from_dict(d['lines'])
     return TestCoverage(name, outcome, lines)
Exemplo n.º 4
0
def contiguous_line_set(start: int, stop: int) -> FileLineSet:
    return FileLineSet.from_iter(ln(i) for i in range(start, stop))