| 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..4862945a3d6d46c2b665d20a89e2e0eddcb84892
|
| --- /dev/null
|
| +++ b/testing_support/coverage_utils.py
|
| @@ -0,0 +1,39 @@
|
| +# 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 os
|
| +import sys
|
| +import unittest
|
| +
|
| +
|
| +def covered_main(includes):
|
| + """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.
|
| + """
|
| + try:
|
| + import coverage
|
| + except ImportError:
|
| + sys.path.insert(0,
|
| + os.path.abspath(os.path.join(
|
| + os.path.dirname(os.path.dirname(__file__)), 'third_party')))
|
| + import coverage
|
| + 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
|
|
|