From 4da9b8c49592a28678cb24a09636077833d04a4d Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Fri, 15 Sep 2017 10:41:12 +0200 Subject: [PATCH] check_coverage: Truncate long floats --- scripts/dev/check_coverage.py | 2 +- tests/unit/scripts/test_check_coverage.py | 33 +++++++++++++++++++++-- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/scripts/dev/check_coverage.py b/scripts/dev/check_coverage.py index 977ac0d8b..f53769f8b 100644 --- a/scripts/dev/check_coverage.py +++ b/scripts/dev/check_coverage.py @@ -239,7 +239,7 @@ def check(fileobj, perfect_files): is_bad = line_cov < 100 or branch_cov < 100 if filename in perfect_src_files and is_bad: - text = "{} has {}% line and {}% branch coverage!".format( + text = "{} has {:.2f}% line and {:.2f}% branch coverage!".format( filename, line_cov, branch_cov) messages.append(Message(MsgType.insufficent_coverage, filename, text)) diff --git a/tests/unit/scripts/test_check_coverage.py b/tests/unit/scripts/test_check_coverage.py index 8b80d6e44..440c743cf 100644 --- a/tests/unit/scripts/test_check_coverage.py +++ b/tests/unit/scripts/test_check_coverage.py @@ -131,7 +131,36 @@ def test_untested(covtest): expected = check_coverage.Message( check_coverage.MsgType.insufficent_coverage, 'module.py', - 'module.py has 75.0% line and 100.0% branch coverage!') + 'module.py has 75.00% line and 100.00% branch coverage!') + assert covtest.check() == [expected] + + +def test_untested_floats(covtest): + """Make sure we don't report 58.330000000000005% coverage.""" + covtest.makefile(""" + def func(): + pass + + def untested(): + pass + + def untested2(): + pass + + def untested3(): + pass + + def untested4(): + pass + + def untested5(): + pass + """) + covtest.run() + expected = check_coverage.Message( + check_coverage.MsgType.insufficent_coverage, + 'module.py', + 'module.py has 58.33% line and 100.00% branch coverage!') assert covtest.check() == [expected] @@ -150,7 +179,7 @@ def test_untested_branches(covtest): expected = check_coverage.Message( check_coverage.MsgType.insufficent_coverage, 'module.py', - 'module.py has 100.0% line and 50.0% branch coverage!') + 'module.py has 100.00% line and 50.00% branch coverage!') assert covtest.check() == [expected]