2017-05-21 23:14:56 -04:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
from __future__ import absolute_import
|
|
|
|
from __future__ import print_function
|
|
|
|
|
2017-05-25 16:52:01 -04:00
|
|
|
import argparse
|
2017-05-21 23:14:56 -04:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import unittest
|
|
|
|
from unittest import TestCase
|
|
|
|
|
2017-05-25 16:52:01 -04:00
|
|
|
def dir_join(dir1, dir2):
|
|
|
|
# type: (str, str) -> str
|
|
|
|
return os.path.abspath(os.path.join(dir1, dir2))
|
|
|
|
|
2017-05-21 23:14:56 -04:00
|
|
|
|
2017-05-25 16:52:01 -04:00
|
|
|
if __name__ == '__main__':
|
|
|
|
description = 'Script to run test_<bot>.py files in bots/<bot> directories'
|
|
|
|
parser = argparse.ArgumentParser(description=description)
|
|
|
|
parser.add_argument('--bot',
|
|
|
|
nargs=1,
|
|
|
|
type=str,
|
|
|
|
action='store',
|
|
|
|
help='test specified single bot')
|
|
|
|
args = parser.parse_args()
|
2017-05-21 23:14:56 -04:00
|
|
|
|
|
|
|
bots_dir = os.path.dirname(os.path.abspath(__file__))
|
|
|
|
root_dir = dir_join(bots_dir, '..')
|
2017-05-30 02:10:19 -04:00
|
|
|
bots_test_dir = dir_join(bots_dir, '../bots')
|
2017-05-21 23:14:56 -04:00
|
|
|
|
|
|
|
sys.path.insert(0, root_dir)
|
2017-05-30 02:10:19 -04:00
|
|
|
sys.path.insert(0, bots_test_dir)
|
2017-05-21 23:14:56 -04:00
|
|
|
|
2017-05-26 00:58:19 -04:00
|
|
|
# mypy doesn't recognize the TestLoader attribute, even though the code
|
|
|
|
# is executable
|
2017-06-04 05:30:58 -04:00
|
|
|
loader = unittest.TestLoader() # type: ignore
|
2017-05-25 16:52:01 -04:00
|
|
|
if args.bot is not None:
|
|
|
|
bots_test_dir = dir_join(bots_test_dir, args.bot[0])
|
2017-05-21 23:14:56 -04:00
|
|
|
suite = loader.discover(start_dir=bots_test_dir, top_level_dir=root_dir)
|
|
|
|
runner = unittest.TextTestRunner(verbosity=2)
|
2017-05-26 00:58:19 -04:00
|
|
|
# same issue as for TestLoader
|
2017-06-04 05:30:58 -04:00
|
|
|
result = runner.run(suite) # type: ignore
|
2017-05-21 23:14:56 -04:00
|
|
|
if result.errors or result.failures:
|
|
|
|
raise Exception('Test failed!')
|