From 81cd2ede819c59fd231ed2eaf71c48f5339751f1 Mon Sep 17 00:00:00 2001 From: Sylvain MARIE Date: Tue, 18 May 2021 11:25:07 +0200 Subject: [PATCH] Fixed error in edge cases for coverage rate verification --- genbadge/utils_coverage.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/genbadge/utils_coverage.py b/genbadge/utils_coverage.py index a769b7e..d0a29d9 100644 --- a/genbadge/utils_coverage.py +++ b/genbadge/utils_coverage.py @@ -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)) @@ -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