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

Side by Side Diff: expect_tests/cover.py

Issue 2036823002: expect_tests > coverage: no data, no fail (Closed) Base URL: https://chromium.googlesource.com/infra/testing/expect_tests.git@master
Patch Set: 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 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
114 fail = coverage_percent < self.expected_coverage_min 123 fail = coverage_percent < self.expected_coverage_min
115 summary = outf.getvalue().replace('%- 15s' % 'Name', 'Coverage Report', 1) 124 summary = outf.getvalue().replace('%- 15s' % 'Name', 'Coverage Report', 1)
116 if verbose: 125 if verbose:
117 print 126 print
118 print summary 127 print summary
119 elif fail: 128 elif fail:
120 print 129 print
121 lines = summary.splitlines() 130 lines = summary.splitlines()
122 lines[2:-2] = [l for l in lines[2:-2] 131 lines[2:-2] = [l for l in lines[2:-2]
123 if not l.strip().endswith('100%')] 132 if not l.strip().endswith('100%')]
124 print '\n'.join(lines) 133 print '\n'.join(lines)
125 print 134 print
126 print ('FATAL: Test coverage is %.1f%%, target is %d%%.' % 135 print ('FATAL: Test coverage is %.1f%%, target is %d%%.' %
127 (coverage_percent, self.expected_coverage_min)) 136 (coverage_percent, self.expected_coverage_min))
128 else: 137 else:
129 print ('Code coverage is %.1f%%, target is %d%%.' % 138 print ('Code coverage is %.1f%%, target is %d%%.' %
130 (coverage_percent, self.expected_coverage_min)) 139 (coverage_percent, self.expected_coverage_min))
131 return not fail 140 return not fail
132 141
133 def create_subprocess_context(self): 142 def create_subprocess_context(self):
134 # Can't have this method be the contextmanager because otherwise 143 # 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 144 # self (and self.cov) will get pickled to the subprocess, and we don't want
136 # that :( 145 # that :(
137 return _Cover(self.enabled, self.opts) 146 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