From ab2dcb869ddd34f450e735ef2d6749f4ab9f82a3 Mon Sep 17 00:00:00 2001 From: Theodore Chen Date: Thu, 25 May 2017 20:52:01 +0000 Subject: [PATCH] test-bots: Add support for testing a single bot. --- contrib_bots/test-bots | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/contrib_bots/test-bots b/contrib_bots/test-bots index 1ad09c2..c137bf1 100755 --- a/contrib_bots/test-bots +++ b/contrib_bots/test-bots @@ -3,16 +3,26 @@ from __future__ import absolute_import from __future__ import print_function +import argparse import os import sys import unittest from unittest import TestCase -if __name__ == '__main__': +def dir_join(dir1, dir2): + # type: (str, str) -> str + return os.path.abspath(os.path.join(dir1, dir2)) - def dir_join(dir1, dir2): - # type: (str, str) -> str - return os.path.abspath(os.path.join(dir1, dir2)) + +if __name__ == '__main__': + description = 'Script to run test_.py files in bots/ 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() bots_dir = os.path.dirname(os.path.abspath(__file__)) root_dir = dir_join(bots_dir, '..') @@ -23,6 +33,8 @@ if __name__ == '__main__': # mypy doesn't recognize the TestLoader attribute, even though the code # is executable loader = unittest.TestLoader() # type: ignore + if args.bot is not None: + bots_test_dir = dir_join(bots_test_dir, args.bot[0]) suite = loader.discover(start_dir=bots_test_dir, top_level_dir=root_dir) runner = unittest.TextTestRunner(verbosity=2) # same issue as for TestLoader