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

Unified Diff: scripts/slave/unittests/expect_tests/cover.py

Issue 220353003: Replace recipes_test.py with a new parallel expectation-based test runner. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/build
Patch Set: refactor Created 6 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: scripts/slave/unittests/expect_tests/cover.py
diff --git a/scripts/slave/unittests/expect_tests/cover.py b/scripts/slave/unittests/expect_tests/cover.py
new file mode 100644
index 0000000000000000000000000000000000000000..7ad52df662b67603a6ed2e76c50936987413c94e
--- /dev/null
+++ b/scripts/slave/unittests/expect_tests/cover.py
@@ -0,0 +1,73 @@
+# Copyright 2014 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import contextlib
+
+from cStringIO import StringIO
+
+import test_env # pylint: disable=unused-import
+
+import coverage
+
+@contextlib.contextmanager
+def _cover(**kwargs):
+ c = coverage.coverage(**kwargs)
+ c._warn_no_data = False # pylint: disable=protected-access
+ c.start()
+ try:
+ yield
+ finally:
+ c.stop()
+ c.save()
+
+
+@contextlib.contextmanager
+def _nop_cover():
+ yield
+
+class CoverageContext(object):
+ def __init__(self, includes, omits, enabled=True):
+ self.opts = None
+ self.cov = None
+ self.enabled = enabled
+
+ if enabled:
+ self.opts = {
+ 'include': includes,
+ 'omit': omits,
+ 'data_suffix': True
+ }
+ self.cov = coverage.coverage(**self.opts)
+ self.cov.erase()
+
+ def cleanup(self):
+ if self.enabled:
+ self.cov.combine()
+
+ def report(self, verbose):
+ fail = False
+
+ if self.enabled:
+ outf = StringIO()
+ fail = self.cov.report(file=outf) != 100.0
+ summary = outf.getvalue().replace('%- 15s' % 'Name', 'Coverage Report', 1)
+ if verbose:
+ print
+ print summary
+ elif fail:
+ print
+ lines = summary.splitlines()
+ lines[2:-2] = [l for l in lines[2:-2]
+ if not l.strip().endswith('100%')]
+ print '\n'.join(lines)
+ print
+ print 'FATAL: Test coverage is not at 100%.'
+
+ return not fail
+
+ def create_subprocess_context(self):
Vadim Sh. 2014/04/02 22:37:59 @contextlib.contextmanager def create_subprocess_c
iannucci 2014/04/03 00:03:49 added comment and merged _cover and _nop_cover
+ if self.enabled:
+ return _cover(**self.opts)
+ else:
+ return _nop_cover()

Powered by Google App Engine
This is Rietveld 408576698