Skip to content

Commit

Permalink
Fixed error in edge cases for coverage rate verification
Browse files Browse the repository at this point in the history
  • Loading branch information
Sylvain MARIE committed May 18, 2021
1 parent 614cead commit 81cd2ed
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions genbadge/utils_coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,10 @@ def parse_root(self, root):
branch_rate = float(root.attrib.get('branch-rate'))
line_rate = float(root.attrib.get('line-rate'))

if round(cov.branch_rate * 1000) != round(branch_rate * 1000):
if not is_close(cov.branch_rate, branch_rate):
raise ValueError("Computed branch rate (%s) is different from the one in the file (%s)"
% (cov.branch_rate, branch_rate))
if round(cov.line_rate * 1000) != round(line_rate * 1000):
if not is_close(cov.line_rate, line_rate):
raise ValueError("Computed line rate (%s) is different from the one in the file (%s)"
% (cov.line_rate, line_rate))

Expand All @@ -155,3 +155,8 @@ def parse_root(self, root):
# self.parse_packages(el, ts)

return cov


def is_close(a, b):
"""Return True if there is at most a difference of 1 at the 2d decimal"""
return abs(a - b) <= 0.01

0 comments on commit 81cd2ed

Please sign in to comment.