[checker] ensure empty python files are reported as 100% covered
authorDavid Douard <david.douard@logilab.fr>
Tue, 22 Dec 2015 10:25:34 +0100
changeset 1847 18c144a672f8
parent 1844 a492f8269ee9
child 1853 746d21ef4c02
[checker] ensure empty python files are reported as 100% covered do this by monkey patching coverage.xmlreport since it report 0/0 (hit/miss) as 0% instead of 100%...
_narval/checkers/apycot/python.py
--- a/_narval/checkers/apycot/python.py	Wed Jul 29 23:44:43 2015 +0200
+++ b/_narval/checkers/apycot/python.py	Tue Dec 22 10:25:34 2015 +0100
@@ -31,6 +31,14 @@
 from preprocessors.apycot.distutils import INSTALL_PREFIX, pyversions
 from checkers.apycot import BaseChecker, AbstractFilteredFileChecker
 
+# monkeypatch coverage.xmlreport since it reports 0/0 as 0% instead of 100%
+def rate(hit, num):
+    if not num: return "1.0"
+    return "%.4g" % (float(hit) / (num or 1.0))
+
+import coverage.xmlreport
+coverage.xmlreport.rate = rate
+
 def pyinstall_path(test):
     path = _pyinstall_path(test)
     if not exists(path):