DebugClients/Python/coverage/results.py

branch
maintenance
changeset 6273
0daf79d65080
parent 6219
d6c795b5ce33
equal deleted inserted replaced
6207:0a74c1efab70 6273:0daf79d65080
4 """Results of coverage measurement.""" 4 """Results of coverage measurement."""
5 5
6 import collections 6 import collections
7 7
8 from coverage.backward import iitems 8 from coverage.backward import iitems
9 from coverage.misc import format_lines 9 from coverage.misc import contract, format_lines, SimpleRepr
10 10
11 11
12 class Analysis(object): 12 class Analysis(object):
13 """The results of analyzing a FileReporter.""" 13 """The results of analyzing a FileReporter."""
14 14
155 missing = 0 155 missing = 0
156 stats[lnum] = (exits, exits - missing) 156 stats[lnum] = (exits, exits - missing)
157 return stats 157 return stats
158 158
159 159
160 class Numbers(object): 160 class Numbers(SimpleRepr):
161 """The numerical results of measuring coverage. 161 """The numerical results of measuring coverage.
162 162
163 This holds the basic statistics from `Analysis`, and is used to roll 163 This holds the basic statistics from `Analysis`, and is used to roll
164 up statistics across files. 164 up statistics across files.
165 165
267 def __radd__(self, other): 267 def __radd__(self, other):
268 # Implementing 0+Numbers allows us to sum() a list of Numbers. 268 # Implementing 0+Numbers allows us to sum() a list of Numbers.
269 if other == 0: 269 if other == 0:
270 return self 270 return self
271 return NotImplemented 271 return NotImplemented
272
273
274 @contract(total='number', fail_under='number', precision=int, returns=bool)
275 def should_fail_under(total, fail_under, precision):
276 """Determine if a total should fail due to fail-under.
277
278 `total` is a float, the coverage measurement total. `fail_under` is the
279 fail_under setting to compare with. `precision` is the number of digits
280 to consider after the decimal point.
281
282 Returns True if the total should fail.
283
284 """
285 # Special case for fail_under=100, it must really be 100.
286 if fail_under == 100.0 and total != 100.0:
287 return True
288
289 return round(total, precision) < fail_under

eric ide

mercurial