-
Notifications
You must be signed in to change notification settings - Fork 32
/
test_all.py
executable file
·82 lines (58 loc) · 2.7 KB
/
test_all.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys
if sys.hexversion < 0x3040000:
print('Python >= 3.4 required')
sys.exit(1)
import os
import re
import importlib.util
import importlib.machinery
generators_dir = os.path.dirname(os.path.realpath(__file__))
def create_generators_module():
if sys.hexversion < 0x3050000:
generators_module = importlib.machinery.SourceFileLoader('generators', os.path.join(generators_dir, '__init__.py')).load_module()
else:
generators_spec = importlib.util.spec_from_file_location('generators', os.path.join(generators_dir, '__init__.py'))
generators_module = importlib.util.module_from_spec(generators_spec)
generators_spec.loader.exec_module(generators_module)
sys.modules['generators'] = generators_module
if 'generators' not in sys.modules:
create_generators_module()
from generators import common
# FIXME: test custom bindings too
def main(args):
all_bindings = []
for binding in os.listdir(generators_dir):
if not os.path.isdir(binding) or os.path.exists(os.path.join(generators_dir, binding, 'skip_test_all')):
continue
if binding not in ['.git', '.m2', '.vscode', '__pycache__', 'configs', 'docker']:
all_bindings.append(binding)
all_bindings = sorted(all_bindings)
active_bindings = set(all_bindings)
if args.bindings != None:
try:
active_bindings = common.apply_item_changes('binding', active_bindings, all_bindings, args.bindings[0].split(','))
except Exception as e:
print('error: {0}'.format(e))
return 1
for binding in all_bindings:
if binding not in active_bindings:
continue
print('\033[01;32m>>> running tests for {0} bindings\033[0m'.format(binding))
try:
module = importlib.import_module('generators.{0}.test_{0}_bindings'.format(binding))
except ImportError: # FIXME: Python 3.6 has ModuleNotFoundError, which would be better to use here, but Debian Stretch has only Python 3.5
print('\033[01;36m### tests missing\033[0m')
else:
success = module.test(os.path.join(generators_dir, binding))
if not isinstance(success, bool):
print('error: test_{0}_bindings.py returns wrong type from its test() function'.format(binding))
if not success:
return 1
print('\033[01;35m>>> done\033[0m')
return 0
if __name__ == '__main__':
def add_arguments(parser):
parser.add_argument('-b', '--bindings', nargs=1, help='comma separated list of bindings, each prefixed by +/-/>=/>/<=/<')
sys.exit(main(common.dockerize('', __file__, add_arguments=add_arguments)))