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

Side by Side Diff: testing_support/coverage_utils.py

Issue 939523004: Copied files from depot_tools. (Closed) Base URL: https://chromium.googlesource.com/infra/testing/testing_support.git@master
Patch Set: Created 5 years, 10 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
OLDNEW
(Empty)
1 # Copyright 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
iannucci 2015/02/19 00:22:39 Let's move this to infra_internal/commit_queue ins
pgervais 2015/02/19 00:45:57 It's not used by the CQ either. I'll just drop thi
4
5 import distutils.version
6 import os
7 import sys
8 import textwrap
9 import unittest
10
11 ROOT_PATH = os.path.abspath(os.path.join(
12 os.path.dirname(os.path.dirname(__file__))))
13
14
15 def native_error(msg, version):
16 print textwrap.dedent("""\
17 ERROR: Native python-coverage (version: %s) is required to be
18 installed on your PYTHONPATH to run this test. Recommendation:
19 sudo apt-get install pip
20 sudo pip install --upgrade coverage
21 %s""") % (version, msg)
22 sys.exit(1)
23
24 def covered_main(includes, require_native=None):
25 """Equivalent of unittest.main(), except that it gathers coverage data, and
26 asserts if the test is not at 100% coverage.
27
28 Args:
29 includes (list(str) or str) - List of paths to include in coverage report.
30 May also be a single path instead of a list.
31 require_native (str) - If non-None, will require that
32 at least |require_native| version of coverage is installed on the
33 system with CTracer.
34 """
35 try:
36 import coverage
37 if require_native is not None:
38 got_ver = coverage.__version__
39 if not getattr(coverage.collector, 'CTracer', None):
40 native_error((
41 "Native python-coverage module required.\n"
42 "Pure-python implementation (version: %s) found: %s"
43 ) % (got_ver, coverage), require_native)
44 if got_ver < distutils.version.LooseVersion(require_native):
45 native_error("Wrong version (%s) found: %s" % (got_ver, coverage),
46 require_native)
47 except ImportError:
48 if require_native is None:
49 sys.path.insert(0, os.path.join(ROOT_PATH, 'third_party'))
50 import coverage
51 else:
52 print ("ERROR: python-coverage (%s) is required to be installed on your "
53 "PYTHONPATH to run this test." % require_native)
54 sys.exit(1)
55
56 COVERAGE = coverage.coverage(include=includes)
57 COVERAGE.start()
58
59 retcode = 0
60 try:
61 unittest.main()
62 except SystemExit as e:
63 retcode = e.code or retcode
64
65 COVERAGE.stop()
66 if COVERAGE.report() != 100.0:
67 print 'FATAL: not at 100% coverage.'
68 retcode = 2
69
70 return retcode
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698