| 152 | return filename.lstrip(".") |
| 153 | |
| 154 | class CoverageResults: |
| 155 | def __init__(self, counts=None, calledfuncs=None, infile=None, |
| 156 | callers=None, outfile=None): |
| 157 | self.counts = counts |
| 158 | if self.counts is None: |
| 159 | self.counts = {} |
| 160 | self.counter = self.counts.copy() # map (filename, lineno) to count |
| 161 | self.calledfuncs = calledfuncs |
| 162 | if self.calledfuncs is None: |
| 163 | self.calledfuncs = {} |
| 164 | self.calledfuncs = self.calledfuncs.copy() |
| 165 | self.callers = callers |
| 166 | if self.callers is None: |
| 167 | self.callers = {} |
| 168 | self.callers = self.callers.copy() |
| 169 | self.infile = infile |
| 170 | self.outfile = outfile |
| 171 | if self.infile: |
| 172 | # Try to merge existing counts file. |
| 173 | try: |
| 174 | with open(self.infile, 'rb') as f: |
| 175 | counts, calledfuncs, callers = pickle.load(f) |
| 176 | self.update(self.__class__(counts, calledfuncs, callers=callers)) |
| 177 | except (OSError, EOFError, ValueError) as err: |
| 178 | print(("Skipping counts file %r: %s" |
| 179 | % (self.infile, err)), file=sys.stderr) |
| 180 | |
| 181 | def is_ignored_filename(self, filename): |
| 182 | """Return True if the filename does not refer to a file |
| 183 | we want to have reported. |
| 184 | """ |
| 185 | return filename.startswith('<') and filename.endswith('>') |
| 186 | |
| 187 | def update(self, other): |
| 188 | """Merge in the data from another CoverageResults""" |
| 189 | counts = self.counts |
| 190 | calledfuncs = self.calledfuncs |
| 191 | callers = self.callers |
| 192 | other_counts = other.counts |
| 193 | other_calledfuncs = other.calledfuncs |
| 194 | other_callers = other.callers |
| 195 | |
| 196 | for key in other_counts: |
| 197 | counts[key] = counts.get(key, 0) + other_counts[key] |
| 198 | |
| 199 | for key in other_calledfuncs: |
| 200 | calledfuncs[key] = 1 |
| 201 | |
| 202 | for key in other_callers: |
| 203 | callers[key] = 1 |
| 204 | |
| 205 | def write_results(self, show_missing=True, summary=False, coverdir=None): |
| 206 | """ |
| 207 | Write the coverage results. |
| 208 | |
| 209 | :param show_missing: Show lines that had no hits. |
| 210 | :param summary: Include coverage summary per module. |
| 211 | :param coverdir: If None, the results of each module are placed in its |