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

Unified Diff: testing_support/coverage_utils.py

Issue 26109002: Add git-number script to calculate generation numbers for commits. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Add version checking for coverage module Created 7 years, 1 month 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
« no previous file with comments | « git_number.py ('k') | testing_support/git_test_utils.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: testing_support/coverage_utils.py
diff --git a/testing_support/coverage_utils.py b/testing_support/coverage_utils.py
new file mode 100644
index 0000000000000000000000000000000000000000..e5c5e1c5e49634bf0bf1bf8bcb250848769f2269
--- /dev/null
+++ b/testing_support/coverage_utils.py
@@ -0,0 +1,69 @@
+# Copyright (c) 2013 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 distutils.version
+import os
+import sys
+import textwrap
+import unittest
+
+ROOT_PATH = os.path.abspath(os.path.join(
+ os.path.dirname(os.path.dirname(__file__))))
+
+
+def native_error(msg, version):
+ print textwrap.dedent("""\
+ ERROR: Native python-coverage (version: %s) is required to be
+ installed on your PYTHONPATH to run this test. Recommendation:
+ sudo pip install python-coverage
+ %s""") % (version, msg)
+ sys.exit(1)
+
+def covered_main(includes, require_native=None):
+ """Equivalent of unittest.main(), except that it gathers coverage data, and
+ asserts if the test is not at 100% coverage.
+
+ Args:
+ includes (list(str) or str) - List of paths to include in coverage report.
+ May also be a single path instead of a list.
+ require_native (str) - If non-None, will require that
+ at least |require_native| version of coverage is installed on the
+ system with CTracer.
+ """
+ try:
+ import coverage
+ if require_native is not None:
+ got_ver = coverage.__version__
+ if not coverage.collector.CTracer:
+ native_error((
+ "Native python-coverage module required.\n"
+ "Pure-python implementation (version: %s) found: %s"
+ ) % (got_ver, coverage), require_native)
+ if got_ver < distutils.version.LooseVersion(require_native):
+ native_error("Wrong version (%s) found: %s" % (got_ver, coverage),
+ require_native)
+ except ImportError:
+ if require_native is None:
+ sys.path.insert(0, os.path.join(ROOT_PATH, 'third_party'))
+ import coverage
+ else:
+ print ("ERROR: python-coverage (%s) is required to be installed on your "
+ "PYTHONPATH to run this test." % require_native)
+ sys.exit(1)
+
+ COVERAGE = coverage.coverage(include=includes)
+ COVERAGE.start()
+
+ retcode = 0
+ try:
+ unittest.main()
+ except SystemExit as e:
+ retcode = e.code or retcode
+
+ COVERAGE.stop()
+ if COVERAGE.report() != 100.0:
+ print 'FATAL: not at 100% coverage.'
+ retcode = 2
+
+ return retcode
« no previous file with comments | « git_number.py ('k') | testing_support/git_test_utils.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698