Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(316)

Side by Side Diff: expect_tests/cover.py

Issue 2031013002: Reland of expect_tests > coverage: no data, no fail (patchset #1 id:1 of https://codereview.chromium (Closed) Base URL: https://chromium.googlesource.com/infra/testing/expect_tests.git@master
Patch Set: Fix Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 coverage_percent = self.cov.report(file=outf, show_missing=True) 113
114 try:
115 coverage_percent = self.cov.report(file=outf, show_missing=True)
116 except coverage.CoverageException as ce:
117 if ce.message != 'No data to report.':
118 raise
119 # If we have no data to report, this means that coverage has found no
120 # tests in the module. Earlier version of coverage used to return 100 in
121 # this case, so we simulate it to keep backward compatibility.
122 coverage_percent = 100.0
123 if verbose:
124 print 'No data to report, setting coverage to 100%'
125
114 fail = coverage_percent < self.expected_coverage_min 126 fail = coverage_percent < self.expected_coverage_min
115 summary = outf.getvalue().replace('%- 15s' % 'Name', 'Coverage Report', 1) 127 summary = outf.getvalue().replace('%- 15s' % 'Name', 'Coverage Report', 1)
116 if verbose: 128 if verbose:
117 print 129 print
118 print summary 130 print summary
119 elif fail: 131 elif fail:
120 print 132 print
121 lines = summary.splitlines() 133 lines = summary.splitlines()
122 lines[2:-2] = [l for l in lines[2:-2] 134 lines[2:-2] = [l for l in lines[2:-2]
123 if not l.strip().endswith('100%')] 135 if not l.strip().endswith('100%')]
124 print '\n'.join(lines) 136 print '\n'.join(lines)
125 print 137 print
126 print ('FATAL: Test coverage is %.1f%%, target is %d%%.' % 138 print ('FATAL: Test coverage is %.1f%%, target is %d%%.' %
127 (coverage_percent, self.expected_coverage_min)) 139 (coverage_percent, self.expected_coverage_min))
128 else: 140 else:
129 print ('Code coverage is %.1f%%, target is %d%%.' % 141 print ('Code coverage is %.1f%%, target is %d%%.' %
130 (coverage_percent, self.expected_coverage_min)) 142 (coverage_percent, self.expected_coverage_min))
131 return not fail 143 return not fail
132 144
133 def create_subprocess_context(self): 145 def create_subprocess_context(self):
134 # Can't have this method be the contextmanager because otherwise 146 # Can't have this method be the contextmanager because otherwise
135 # self (and self.cov) will get pickled to the subprocess, and we don't want 147 # self (and self.cov) will get pickled to the subprocess, and we don't want
136 # that :( 148 # that :(
137 return _Cover(self.enabled, self.opts) 149 return _Cover(self.enabled, self.opts)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698