-
Notifications
You must be signed in to change notification settings - Fork 12
/
run_tests.py
54 lines (42 loc) · 1.31 KB
/
run_tests.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
from __future__ import print_function
import sys
import subprocess
import os
def is_test_file(name, path):
"""
Return True if the given path/file name is a test file.
"""
if os.name == 'nt':
return os.path.isfile(path) and path.endswith('.exe')
return os.path.isfile(path) and name.startswith('test_')
def main(args):
"""
Run all test files in the given test directory.
"""
if len(args) != 2:
raise SyntaxError(
'Invalid syntax: python run_tests.py <path to test directory>')
test_dir = args[1]
test_count = 0
success_count = 0
for name in os.listdir(test_dir):
f = os.path.join(test_dir, name)
if not is_test_file(name, f):
continue
test_count += 1
print('Testing {0}...'.format(name), end=' ')
try:
output = subprocess.check_output(f)
except subprocess.CalledProcessError as e:
print('Failed with return code {0}!'.format(e.returncode))
print('Output:\n')
print(e.output)
else:
print('OK!')
success_count += 1
print('{0} of {1} tests finished sucessfully.'.format(
success_count, test_count))
if test_count != success_count:
sys.exit(1)
if __name__ == '__main__':
main(sys.argv)