-
Notifications
You must be signed in to change notification settings - Fork 71
/
alltests.py
executable file
·66 lines (55 loc) · 2.26 KB
/
alltests.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
64
65
66
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright 2017, Data61, CSIRO (ABN 41 687 119 230)
#
# SPDX-License-Identifier: BSD-2-Clause
#
'''
This script is a quick way to execute the tests for all CAmkES modules.
'''
from __future__ import absolute_import, division, print_function, \
unicode_literals
from concurrencytest import ConcurrentTestSuite, fork_for_tests
import capdl
import camkes.ast
import camkes.internal
import camkes.parser
import camkes.runner
import camkes.templates
import argparse, multiprocessing, os, subprocess, sys, unittest
ME = os.path.abspath(__file__)
# Available tests. The keys to this dictionary should be names of packages containing tests
# packages must be imported in this file and the directory with tests must be a valid
# python module (--> contains an __init__.py)
TESTS = ['ast', 'internal', 'parser','runner','templates']
def main(argv):
parser = argparse.ArgumentParser(prog=argv[0],
description='run CAmkES tests')
parser.add_argument('--jobs', '-j', nargs='?', type=int,
help='parallelise test execution')
parser.add_argument('--verbosity', '-v', default=1, type=int, help="Verbosity to run tests. 0 = quiet. 1 = default. 2 = verbose")
parser.add_argument('test', nargs='*', choices=TESTS+['all'], default='all', help='run a specific category of tests')
parser.add_argument('--capdl-python', help='Deprecated. Using this argument has no effect.')
options = parser.parse_args(argv[1:])
if options.jobs is None:
# Maximum parallelism.
options.jobs = multiprocessing.cpu_count()
# work out which tests to run
if options.test == 'all' or 'all' in options.test:
test_packages = TESTS
else:
test_packages = options.test
# load the tests we want to run
loader = unittest.TestLoader()
test_suite = unittest.TestSuite()
for v in test_packages:
test_suite.addTests(loader.discover('camkes.' + v, top_level_dir=os.path.dirname(ME)))
concurrent_suite = ConcurrentTestSuite(test_suite, fork_for_tests(options.jobs))
runner = unittest.TextTestRunner(verbosity=options.verbosity)
result = runner.run(concurrent_suite)
if result.wasSuccessful():
return 0
return 1
if __name__ == '__main__':
sys.exit(main(sys.argv))