diff options
Diffstat (limited to 'coverage')
-rw-r--r-- | coverage/html.py | 5 | ||||
-rw-r--r-- | coverage/htmlfiles/coverage_html.js | 23 | ||||
-rw-r--r-- | coverage/htmlfiles/index.html | 4 | ||||
-rw-r--r-- | coverage/results.py | 11 |
4 files changed, 35 insertions, 8 deletions
diff --git a/coverage/html.py b/coverage/html.py index 91ae2c27..0829f219 100644 --- a/coverage/html.py +++ b/coverage/html.py @@ -67,6 +67,7 @@ class HtmlReporter(Reporter): self.directory = None self.template_globals = { 'escape': escape, + 'pair': pair, 'title': self.config.html_title, '__url__': coverage.__url__, '__version__': coverage.__version__, @@ -379,3 +380,7 @@ def spaceless(html): """ html = re.sub(r">\s+<p ", ">\n<p ", html) return html + +def pair(ratio): + """Format a pair of numbers so JavaScript can read them in an attribute.""" + return "%s %s" % ratio diff --git a/coverage/htmlfiles/coverage_html.js b/coverage/htmlfiles/coverage_html.js index 6eb23fee..336b97b4 100644 --- a/coverage/htmlfiles/coverage_html.js +++ b/coverage/htmlfiles/coverage_html.js @@ -116,9 +116,17 @@ coverage.wire_up_filter = function () { break; } - var sum = 0; + var sum = 0, numer = 0, denom = 0; $.each(cells.filter(':visible'), function () { - sum += parseInt(this.innerHTML, 10); + var ratio = $(this).data("ratio"); + if (ratio) { + var splitted = ratio.split(" "); + numer += parseInt(splitted[0], 10); + denom += parseInt(splitted[1], 10); + } + else { + sum += parseInt(this.innerHTML, 10); + } }); // Get footer cell element. @@ -126,8 +134,15 @@ coverage.wire_up_filter = function () { // Set value into dynamic footer cell element. if (cells[0].innerHTML.indexOf('%') > -1) { - // Value of "coverage" column is expressed as a percentage - footer_cell.text(parseInt((sum / show.length), 10) + '%'); + // Percentage columns use the numerator and denominator, + // and adapt to the number of decimal places. + var match = /\.([0-9]+)/.exec(cells[0].innerHTML); + var places = 0; + if (match) { + places = match[1].length; + } + var pct = numer * 100 / denom; + footer_cell.text(pct.toFixed(places) + '%'); } else { footer_cell.text(sum); diff --git a/coverage/htmlfiles/index.html b/coverage/htmlfiles/index.html index 4b572711..bea715e1 100644 --- a/coverage/htmlfiles/index.html +++ b/coverage/htmlfiles/index.html @@ -78,7 +78,7 @@ <td>{{totals.n_branches}}</td> <td>{{totals.n_partial_branches}}</td> {% endif %} - <td class='right'>{{totals.pc_covered_str}}%</td> + <td class='right' data-ratio='{{totals.ratio_covered|pair}}'>{{totals.pc_covered_str}}%</td> </tr> </tfoot> <tbody> @@ -92,7 +92,7 @@ <td>{{file.nums.n_branches}}</td> <td>{{file.nums.n_partial_branches}}</td> {% endif %} - <td class='right'>{{file.nums.pc_covered_str}}%</td> + <td class='right' data-ratio='{{file.nums.ratio_covered|pair}}'>{{file.nums.pc_covered_str}}%</td> </tr> {% endfor %} </tbody> diff --git a/coverage/results.py b/coverage/results.py index 6c41a944..5eff0f3e 100644 --- a/coverage/results.py +++ b/coverage/results.py @@ -204,8 +204,8 @@ class Numbers(object): def pc_covered(self): """Returns a single percentage value for coverage.""" if self.n_statements > 0: - pc_cov = (100.0 * (self.n_executed + self.n_executed_branches) / - (self.n_statements + self.n_branches)) + numerator, denominator = self.ratio_covered + pc_cov = (100.0 * numerator) / denominator else: pc_cov = 100.0 return pc_cov @@ -236,6 +236,13 @@ class Numbers(object): width += 1 + cls._precision return width + @property + def ratio_covered(self): + """Return a numerator and denominator for the coverage ratio.""" + numerator = self.n_executed + self.n_executed_branches + denominator = self.n_statements + self.n_branches + return numerator, denominator + def __add__(self, other): nums = Numbers() nums.n_files = self.n_files + other.n_files |