def test_basic_single_environment(self): test_obj = { 'tests': ['test1', 'test2'], 'environments': [ { 'base_url': 'http://github.com', 'port': 80, }, ], } expected = [ { 'test': 'test1', 'configuration': {}, 'environment': { 'base_url': 'http://github.com', 'port': 80, }, }, { 'test': 'test2', 'configuration': {}, 'environment': { 'base_url': 'http://github.com', 'port': 80, }, }, ] flat_tests = AutoThreadedTestRunner._build_tests(test_obj) self.assertEqual(sorted(flat_tests), sorted(expected))
def test_basic(self): test_obj = { 'tests': ['test1', 'test2'], } expected = [ { 'test': 'test1', 'configuration': {}, 'environment': {}, }, { 'test': 'test2', 'configuration': {}, 'environment': {}, }, ] flat_tests = AutoThreadedTestRunner._build_tests(test_obj) self.assertEqual(sorted(flat_tests), sorted(expected))
def run(): """The command-line interface for the TestRunner class.""" # Parse arguments parser = ArgumentParser() args = parser.parse_args() test_json = { "tests": args.tests, "configuration": getattr(args, 'configuration', {}), "environments": getattr(args, 'environments', []), } log_level = args.log_level log_screen = args.log_screen # Set up the TestRunner and TestLogger if args.log: logger = HTMLLogger(log_dir=args.log, css_path=args.css_path) else: logger = SimpleTextLogger() logger.set_log_level(log_level) logger.set_log_scren(log_screen) if (args.log_display): logger.set_log_display(True) if args.user_defined_threads: runner = UserThreadedTestRunner(logger) else: if args.number_of_threads == 0: #AB assigns threads based on number of tests if 0 is provided args.number_of_threads = len(args.tests) runner = AutoThreadedTestRunner( logger, args.number_of_threads, ) runner.add_tests(test_json) # Run the tests exit_code = runner.run_tests() sys.exit(exit_code)
def test_nested_mixed(self): test_obj = { 'tests': [ { 'tests': [ 'test1', { 'tests': [ { 'tests': [ 'test4', 'test5', ], 'configuration': { 'base_url': 'http://localhost', 'password': '******' } }, ], 'configuration': { 'username': '******', 'password': '******', }, }, ], }, { 'tests': [ 'test2', 'test3', ], }, ], 'configuration': { 'base_url': 'http://github.com', 'port': 80, } } expected = [ { 'test': 'test1', 'configuration': { 'base_url': 'http://github.com', 'port': 80, }, 'environment': {}, }, { 'test': 'test2', 'configuration': { 'base_url': 'http://github.com', 'port': 80, }, 'environment': {}, }, { 'test': 'test3', 'configuration': { 'base_url': 'http://github.com', 'port': 80, }, 'environment': {}, }, { 'test': 'test4', 'configuration': { 'base_url': 'http://localhost', 'port': 80, 'username': '******', 'password': '******', }, 'environment': {}, }, { 'test': 'test5', 'configuration': { 'base_url': 'http://localhost', 'port': 80, 'username': '******', 'password': '******', }, 'environment': {}, }, ] flat_tests = AutoThreadedTestRunner._build_tests(test_obj) self.assertEqual(sorted(flat_tests), sorted(expected))
def test_nested_with_environments(self): test_obj = { 'tests': [ { 'tests': [ 'test1', ], 'environments': [ { 'base_url': 'http://staging', }, ] }, { 'tests': [ 'test2', 'test3', ], }, { 'tests': [ { 'tests': [ 'test4', 'test5', ], 'configuration': { 'base_url': 'http://localhost', 'password': '******' }, 'environments': [ { 'database': 'db1:5796', 'memcache': 'localhost:7777' }, { 'database': 'db2:5796', 'memcache': 'localhost:8888' }, ], }, ], 'configuration': { 'username': '******', 'password': '******', }, 'environments': [ { 'database': 'http://localhost:5796', 'number_of_clients': 10, }, { 'database': 'http://localhost:5796', 'number_of_clients': 50, }, ], }, ], 'configuration': { 'base_url': 'http://github.com', 'port': 80, } } expected = [ { 'test': 'test1', 'configuration': { 'base_url': 'http://github.com', 'port': 80, }, 'environment': { 'base_url': 'http://staging', }, }, { 'test': 'test2', 'configuration': { 'base_url': 'http://github.com', 'port': 80, }, 'environment': {}, }, { 'test': 'test3', 'configuration': { 'base_url': 'http://github.com', 'port': 80, }, 'environment': {}, }, { 'test': 'test4', 'configuration': { 'base_url': 'http://localhost', 'port': 80, 'username': '******', 'password': '******', }, 'environment': { 'number_of_clients': 10, 'database': 'db1:5796', 'memcache': 'localhost:7777' }, }, { 'test': 'test5', 'configuration': { 'base_url': 'http://localhost', 'port': 80, 'username': '******', 'password': '******', }, 'environment': { 'number_of_clients': 10, 'database': 'db1:5796', 'memcache': 'localhost:7777' }, }, { 'test': 'test4', 'configuration': { 'base_url': 'http://localhost', 'port': 80, 'username': '******', 'password': '******', }, 'environment': { 'number_of_clients': 50, 'database': 'db1:5796', 'memcache': 'localhost:7777' }, }, { 'test': 'test5', 'configuration': { 'base_url': 'http://localhost', 'port': 80, 'username': '******', 'password': '******', }, 'environment': { 'number_of_clients': 50, 'database': 'db1:5796', 'memcache': 'localhost:7777' }, }, { 'test': 'test4', 'configuration': { 'base_url': 'http://localhost', 'port': 80, 'username': '******', 'password': '******', }, 'environment': { 'number_of_clients': 50, 'database': 'db2:5796', 'memcache': 'localhost:8888' }, }, { 'test': 'test5', 'configuration': { 'base_url': 'http://localhost', 'port': 80, 'username': '******', 'password': '******', }, 'environment': { 'number_of_clients': 50, 'database': 'db2:5796', 'memcache': 'localhost:8888' }, }, { 'test': 'test4', 'configuration': { 'base_url': 'http://localhost', 'port': 80, 'username': '******', 'password': '******', }, 'environment': { 'number_of_clients': 10, 'database': 'db2:5796', 'memcache': 'localhost:8888' }, }, { 'test': 'test5', 'configuration': { 'base_url': 'http://localhost', 'port': 80, 'username': '******', 'password': '******', }, 'environment': { 'number_of_clients': 10, 'database': 'db2:5796', 'memcache': 'localhost:8888' }, }, ] flat_tests = AutoThreadedTestRunner._build_tests(test_obj) self.assertEqual(sorted(flat_tests), sorted(expected))
def test_multiple_environments_with_config(self): test_obj = { 'tests': ['test1', 'test2'], 'configuration': { 'username': '******', 'password': '******', }, 'environments': [ { 'base_url': 'http://github.com', 'port': 80, }, { 'base_url': 'http://localhost', 'port': 8080, }, { 'base_url': 'http://staging', 'port': 80, }, ], } expected = [ { 'test': 'test1', 'configuration': { 'username': '******', 'password': '******', }, 'environment': { 'base_url': 'http://github.com', 'port': 80, }, }, { 'test': 'test1', 'configuration': { 'username': '******', 'password': '******', }, 'environment': { 'base_url': 'http://localhost', 'port': 8080, }, }, { 'test': 'test1', 'configuration': { 'username': '******', 'password': '******', }, 'environment': { 'base_url': 'http://staging', 'port': 80, }, }, { 'test': 'test2', 'configuration': { 'username': '******', 'password': '******', }, 'environment': { 'base_url': 'http://github.com', 'port': 80, }, }, { 'test': 'test2', 'configuration': { 'username': '******', 'password': '******', }, 'environment': { 'base_url': 'http://localhost', 'port': 8080, }, }, { 'test': 'test2', 'configuration': { 'username': '******', 'password': '******', }, 'environment': { 'base_url': 'http://staging', 'port': 80, }, }, ] flat_tests = AutoThreadedTestRunner._build_tests(test_obj) self.assertEqual(sorted(flat_tests), sorted(expected))