OLD | NEW |
---|---|
(Empty) | |
1 # Copyright (c) 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. | |
4 | |
5 import os | |
6 import sys | |
7 import unittest | |
8 | |
9 | |
10 def covered_main(includes): | |
11 """Equivalent of unittest.main(), except that it gathers coverage data, and | |
12 asserts if the test is not at 100% coverage. | |
13 | |
14 Args: | |
15 includes (list(str) or str) - List of paths to include in coverage report. | |
16 May also be a single path instead of a list. | |
17 """ | |
18 try: | |
19 import coverage | |
20 except ImportError: | |
21 sys.path.insert(0, | |
22 os.path.abspath(os.path.join( | |
23 os.path.dirname(os.path.dirname(__file__)), 'third_party'))) | |
M-A Ruel
2013/11/14 17:27:24
I still prefer this to be a global variable.
iannucci
2013/11/15 02:12:58
Aw, nuts, I thought I did that.
| |
24 import coverage | |
25 COVERAGE = coverage.coverage(include=includes) | |
26 COVERAGE.start() | |
27 | |
28 retcode = 0 | |
29 try: | |
30 unittest.main() | |
31 except SystemExit as e: | |
32 retcode = e.code or retcode | |
33 | |
34 COVERAGE.stop() | |
35 if COVERAGE.report() != 100.0: | |
36 print "FATAL: not at 100% coverage." | |
37 retcode = 2 | |
38 | |
39 return retcode | |
OLD | NEW |