forked from CLIMADA-project/climada_python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests_runner.py
executable file
·48 lines (43 loc) · 1.85 KB
/
tests_runner.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
import sys
from pathlib import Path
import unittest
import matplotlib
from climada.util.config import SOURCE_DIR
def find_unit_tests():
"""select unit tests."""
suite = unittest.TestLoader().discover('climada.entity.exposures.test')
suite.addTest(unittest.TestLoader().discover('climada.entity.disc_rates.test'))
suite.addTest(unittest.TestLoader().discover('climada.entity.impact_funcs.test'))
suite.addTest(unittest.TestLoader().discover('climada.entity.measures.test'))
suite.addTest(unittest.TestLoader().discover('climada.entity.test'))
suite.addTest(unittest.TestLoader().discover('climada.hazard.test'))
suite.addTest(unittest.TestLoader().discover('climada.hazard.centroids.test'))
suite.addTest(unittest.TestLoader().discover('climada.hazard.emulator.test'))
suite.addTest(unittest.TestLoader().discover('climada.engine.test'))
suite.addTest(unittest.TestLoader().discover('climada.util.test'))
return suite
def find_integ_tests():
"""select integration tests."""
suite = unittest.TestLoader().discover('climada.test')
return suite
def main():
"""parse input argument: None, 'unit' or 'integ'. Execute accordingly."""
if sys.argv[1:]:
import xmlrunner
arg = sys.argv[1]
output = str(Path(__file__).parent.joinpath('tests_xml'))
if arg == 'unit':
xmlrunner.XMLTestRunner(output=output).run(find_unit_tests())
elif arg == 'integ':
xmlrunner.XMLTestRunner(output=output).run(find_integ_tests())
else:
xmlrunner.XMLTestRunner(output=output).run(
unittest.TestLoader().discover(arg)
)
else:
# execute without xml reports
unittest.TextTestRunner(verbosity=2).run(find_unit_tests())
if __name__ == '__main__':
matplotlib.use("Agg")
sys.path.append(str(SOURCE_DIR))
main()