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

Side by Side Diff: third_party/recipe_engine/expect_tests/cover.py

Issue 1151423002: Move recipe engine to third_party/recipe_engine. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/build
Patch Set: Moved field_composer_test with its buddies Created 5 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 | Annotate | Revision Log
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 from cStringIO import StringIO 5 from cStringIO import StringIO
6 6
7 import test_env # pylint: disable=W0611
8
9 import coverage 7 import coverage
10 8
11 # This is instead of a contextmanager because it causes old pylints to crash :( 9 # This is instead of a contextmanager because it causes old pylints to crash :(
12 class _Cover(object): 10 class _Cover(object):
13 def __init__(self, enabled, maybe_kwargs): 11 def __init__(self, enabled, maybe_kwargs):
14 self.enabled = enabled 12 self.enabled = enabled
15 self.kwargs = maybe_kwargs or {} 13 self.kwargs = maybe_kwargs or {}
16 self.c = None 14 self.c = None
17 15
18 def __call__(self, **kwargs): 16 def __call__(self, **kwargs):
(...skipping 30 matching lines...) Expand all
49 'data_suffix': True, 47 'data_suffix': True,
50 'branch': cover_branches, 48 'branch': cover_branches,
51 } 49 }
52 self.cov = coverage.coverage(**self.opts) 50 self.cov = coverage.coverage(**self.opts)
53 self.cov.erase() 51 self.cov.erase()
54 52
55 def cleanup(self): 53 def cleanup(self):
56 if self.enabled: 54 if self.enabled:
57 self.cov.combine() 55 self.cov.combine()
58 56
59 def report(self, verbose): 57 def report(self, verbose, omit=None):
60 fail = False 58 fail = False
61 59
62 if self.enabled: 60 if self.enabled:
63 if self.html_report: 61 if self.html_report:
64 self.cov.html_report(directory=self.html_report) 62 self.cov.html_report(directory=self.html_report, omit=None)
65 63
66 outf = StringIO() 64 outf = StringIO()
67 fail = self.cov.report(file=outf) != 100.0 65 fail = self.cov.report(file=outf, omit=omit) != 100.0
68 summary = outf.getvalue().replace('%- 15s' % 'Name', 'Coverage Report', 1) 66 summary = outf.getvalue().replace('%- 15s' % 'Name', 'Coverage Report', 1)
69 if verbose: 67 if verbose:
70 print 68 print
71 print summary 69 print summary
72 elif fail: 70 elif fail:
73 print 71 print
74 lines = summary.splitlines() 72 lines = summary.splitlines()
75 lines[2:-2] = [l for l in lines[2:-2] 73 lines[2:-2] = [l for l in lines[2:-2]
76 if not l.strip().endswith('100%')] 74 if not l.strip().endswith('100%')]
77 print '\n'.join(lines) 75 print '\n'.join(lines)
78 print 76 print
79 print 'FATAL: Test coverage is not at 100%.' 77 print 'FATAL: Test coverage is not at 100%.'
80 78
81 return not fail 79 return not fail
82 80
83 def create_subprocess_context(self): 81 def create_subprocess_context(self):
84 # Can't have this method be the contextmanager because otherwise 82 # Can't have this method be the contextmanager because otherwise
85 # self (and self.cov) will get pickled to the subprocess, and we don't want 83 # self (and self.cov) will get pickled to the subprocess, and we don't want
86 # that :( 84 # that :(
87 return _Cover(self.enabled, self.opts) 85 return _Cover(self.enabled, self.opts)
OLDNEW
« no previous file with comments | « third_party/recipe_engine/expect_tests/__init__.py ('k') | third_party/recipe_engine/expect_tests/handle_debug.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698