-
Notifications
You must be signed in to change notification settings - Fork 1
/
run-tests.py
83 lines (68 loc) · 1.73 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
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
83
"""Run tests for all models.
"""
import argparse
import os
import subprocess
import sys
import unittest
def run_unit_tests():
"""
Runs unit tests (without subprocesses).
"""
model_dirs = ['streamflow/pystreamflow']
for dir in model_dirs:
tests = os.path.join(dir, 'tests')
suite = unittest.defaultTestLoader.discover(tests, pattern='test*.py')
res = unittest.TextTestRunner(verbosity=2).run(suite)
sys.exit(0 if res.wasSuccessful() else 1)
def run_flake8():
"""
Runs flake8 in a subprocess, exits if it doesn't finish.
"""
print('Running flake8 ... ')
sys.stdout.flush()
p = subprocess.Popen(
[sys.executable, '-m', 'flake8'], stderr=subprocess.PIPE
)
try:
ret = p.wait()
except KeyboardInterrupt:
try:
p.terminate()
except OSError:
pass
p.wait()
print('')
sys.exit(1)
if ret == 0:
print('ok')
else:
print('FAILED')
sys.exit(ret)
if __name__ == '__main__':
# Parse command line arguments
parser = argparse.ArgumentParser(
description='Run unit tests for pints-models.',
)
parser.add_argument(
'--unit',
action='store_true',
help='Run all unit tests using the `python` interpreter.',
)
parser.add_argument(
'--style',
action='store_true',
help='Run style checks using flake8.',
)
args = parser.parse_args()
# Run tests based on parsed arguments
has_run = False
if args.unit:
has_run = True
run_unit_tests()
if args.style:
has_run = True
run_flake8()
# Help if nothing ran
if not has_run:
parser.print_help()