| OLD | NEW |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import ConfigParser | 5 import ConfigParser |
| 6 from cStringIO import StringIO | 6 from cStringIO import StringIO |
| 7 import os | 7 import os |
| 8 import socket | 8 import socket |
| 9 import sys | 9 import sys |
| 10 import threading | 10 import threading |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 self.cov.combine() | 103 self.cov.combine() |
| 104 | 104 |
| 105 def report(self, verbose): | 105 def report(self, verbose): |
| 106 fail = False | 106 fail = False |
| 107 | 107 |
| 108 if self.enabled: | 108 if self.enabled: |
| 109 if self.html_report: | 109 if self.html_report: |
| 110 self.cov.html_report(directory=self.html_report) | 110 self.cov.html_report(directory=self.html_report) |
| 111 | 111 |
| 112 outf = StringIO() | 112 outf = StringIO() |
| 113 | 113 coverage_percent = self.cov.report(file=outf, show_missing=True) |
| 114 try: | |
| 115 coverage_percent = self.cov.report(file=outf, show_missing=True) | |
| 116 except CoverageException as ce: | |
| 117 # If we have no data to report, this means that coverage has found no | |
| 118 # tests in the module. This is not nice, but we shouldn't fail. | |
| 119 if ce.message == 'No data to report.': | |
| 120 return | |
| 121 raise | |
| 122 | |
| 123 fail = coverage_percent < self.expected_coverage_min | 114 fail = coverage_percent < self.expected_coverage_min |
| 124 summary = outf.getvalue().replace('%- 15s' % 'Name', 'Coverage Report', 1) | 115 summary = outf.getvalue().replace('%- 15s' % 'Name', 'Coverage Report', 1) |
| 125 if verbose: | 116 if verbose: |
| 126 print | 117 print |
| 127 print summary | 118 print summary |
| 128 elif fail: | 119 elif fail: |
| 129 print | 120 print |
| 130 lines = summary.splitlines() | 121 lines = summary.splitlines() |
| 131 lines[2:-2] = [l for l in lines[2:-2] | 122 lines[2:-2] = [l for l in lines[2:-2] |
| 132 if not l.strip().endswith('100%')] | 123 if not l.strip().endswith('100%')] |
| 133 print '\n'.join(lines) | 124 print '\n'.join(lines) |
| 134 print | 125 print |
| 135 print ('FATAL: Test coverage is %.1f%%, target is %d%%.' % | 126 print ('FATAL: Test coverage is %.1f%%, target is %d%%.' % |
| 136 (coverage_percent, self.expected_coverage_min)) | 127 (coverage_percent, self.expected_coverage_min)) |
| 137 else: | 128 else: |
| 138 print ('Code coverage is %.1f%%, target is %d%%.' % | 129 print ('Code coverage is %.1f%%, target is %d%%.' % |
| 139 (coverage_percent, self.expected_coverage_min)) | 130 (coverage_percent, self.expected_coverage_min)) |
| 140 return not fail | 131 return not fail |
| 141 | 132 |
| 142 def create_subprocess_context(self): | 133 def create_subprocess_context(self): |
| 143 # Can't have this method be the contextmanager because otherwise | 134 # Can't have this method be the contextmanager because otherwise |
| 144 # self (and self.cov) will get pickled to the subprocess, and we don't want | 135 # self (and self.cov) will get pickled to the subprocess, and we don't want |
| 145 # that :( | 136 # that :( |
| 146 return _Cover(self.enabled, self.opts) | 137 return _Cover(self.enabled, self.opts) |
| OLD | NEW |