check_coverage: Truncate long floats

This commit is contained in:
Florian Bruhin 2017-09-15 10:41:12 +02:00
parent c5c566aadc
commit 4da9b8c495
2 changed files with 32 additions and 3 deletions

View File

@ -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))

View File

@ -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]