Skip to content

Commit cf183f6

Browse files
simonfagerholmdbrgn
authored andcommitted
Use coverage package for rounding the percentage (dbrgn#6)
1 parent 9c98800 commit cf183f6

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

coverage_badge/__main__.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,31 @@ def write(self, *args, **kwargs):
4646
pass
4747

4848

49+
class Precision(coverage.results.Numbers):
50+
"""
51+
A class for using the percentage rounding of the main coverage package,
52+
with any percentage.
53+
54+
_Precision.pc_covered_str is the string format of the percentage.
55+
"""
56+
def __init__(self, percent):
57+
self.percent = percent
58+
59+
@property
60+
def pc_covered(self):
61+
"""overriding the percentage calculation of the parent class"""
62+
return self.percent
63+
64+
4965
def get_total():
5066
"""
5167
Return the rounded total as properly rounded string.
5268
"""
5369
cov = coverage.Coverage()
5470
cov.load()
5571
total = cov.report(file=Devnull())
56-
return '{0:.0f}'.format(total)
72+
73+
return Precision(total).pc_covered_str
5774

5875

5976
def get_color(total):

0 commit comments

Comments
 (0)