forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
coveragetest.py
executable file
·63 lines (50 loc) · 1.88 KB
/
coveragetest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env vpython3
# Copyright 2017 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Ensure files in the directory are thoroughly tested."""
import importlib
import io
import os
import sys
import unittest
import coverage # pylint: disable=import-error
# The files need to have sufficient coverages.
COVERED_FILES = [
'compatible_utils.py', 'deploy_to_fuchsia.py', 'flash_device.py',
'log_manager.py', 'publish_package.py', 'serve_repo.py'
]
# The files will be tested without coverage requirements.
TESTED_FILES = [
'bundled_test_runner.py', 'common.py', 'ffx_emulator.py',
'modification_waiter.py', 'monitors.py', 'serial_boot_device.py',
'test_env_setup.py', 'test_server.py'
]
def main():
"""Gather coverage data, ensure included files are 100% covered."""
# Fuchsia tests not supported on Windows
if os.name == 'nt':
return 0
cov = coverage.coverage(data_file=None,
include=COVERED_FILES,
config_file=True)
cov.start()
for file in COVERED_FILES + TESTED_FILES:
print('Testing ' + file + ' ...')
# pylint: disable=import-outside-toplevel
# import tests after coverage start to also cover definition lines.
module = importlib.import_module(file.replace('.py', '_unittests'))
# pylint: enable=import-outside-toplevel
tests = unittest.TestLoader().loadTestsFromModule(module)
if not unittest.TextTestRunner().run(tests).wasSuccessful():
return 1
cov.stop()
outf = io.StringIO()
percentage = cov.report(file=outf, show_missing=True)
if int(percentage) != 100:
print(outf.getvalue())
print('FATAL: Insufficient coverage (%.f%%)' % int(percentage))
return 1
return 0
if __name__ == '__main__':
sys.exit(main())