-
Notifications
You must be signed in to change notification settings - Fork 0
/
runtests.py
executable file
·65 lines (50 loc) · 2.06 KB
/
runtests.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
#!/usr/bin/env python
##!/usr/bin/env python2.4
import logging
import sys
from tests import unittest, importSuite, importString
if __name__== '__main__':
from util.constants import setAggressiveTests
setAggressiveTests()
#set up logging
logging.basicConfig()
#want to suppress warnings if they show up.
# -currently just synth has WARNINGs that show up in unit tests
logging.getLogger('engine_utils').setLevel(logging.ERROR)
#set help message
help = """
Usage: runtests MODULE_NAME [LOGGER_NAME1 [LOGGER_NAME2 ...]
If MODULE_NAME is specified as 'all', it runs all tests.
Otherwise it just runs the tests for the specified module/
-Example module names: regressor, engine, engine.EngineUtils
For each LOGGER_NAME specified, it sets that logger to INFO.
-Example logger names: cyt, synth, pwl
"""
#got the right number of args? If not, output help
num_args = len(sys.argv)
if num_args in [1]:
print help
sys.exit(0)
if num_args >= 3:
logger_names = sys.argv[2:]
for logger_name in logger_names:
logging.getLogger(logger_name).setLevel(logging.INFO)
else:
pass
if sys.argv[1] == 'all':
from tests import test_suite
test_suite_obj = test_suite()
unittest.TextTestRunner().run(test_suite_obj)
else:
module_name = sys.argv[1]
if '.' in module_name:
major_module_name = module_name.split('.')[0] #e.g. 'regressor'
minor_module_name = module_name.split('.')[1] #e.g. 'Pwl'
test_class_name = major_module_name + '.test.' + minor_module_name + 'Test' #e.g. 'regressor.test.PwlTest
test_class = importString(test_class_name) #e.g. eval('import regressor.test.PwlTest')
unittest_suite = unittest.makeSuite(test_class, 'test')
test_suite = unittest_suite
else:
test_suite_name = module_name + '.test.test_suite'
test_suite = importSuite(test_suite_name)
result = unittest.TextTestRunner().run(test_suite)