From 2fd91620302fb4ad252aa462cbdb0e0953b57955 Mon Sep 17 00:00:00 2001 From: "neiljp (Neil Pilgrim)" Date: Sat, 9 Jun 2018 11:32:19 -0700 Subject: [PATCH] test-lib: Drastically simplify by using test_handler function. This automatically enables use of the pytest runner using common code. --- tools/test-lib | 51 +++----------------------------------------------- 1 file changed, 3 insertions(+), 48 deletions(-) diff --git a/tools/test-lib b/tools/test-lib index 18cc6f7..3a124ee 100755 --- a/tools/test-lib +++ b/tools/test-lib @@ -1,51 +1,6 @@ -#!/usr/bin/env python3 +#!/usr/bin/env python -import os -import sys -import unittest -import argparse - -from importlib import import_module - -def parse_args(): - parser = argparse.ArgumentParser() - parser.add_argument('--coverage', - nargs='?', - const=True, - default=False, - help='compute test coverage ("--coverage combine" to combine with previous reports)') - return parser.parse_args() - -def run_all(): - TOOLS_DIR = os.path.dirname(os.path.abspath(__file__)) - ROOT_DIR = os.path.abspath(os.path.join(TOOLS_DIR, '..')) - BOTS_DIR = os.path.join(ROOT_DIR, 'zulib_bots') - sys.path.insert(0, BOTS_DIR) - - options = parse_args() - - if options.coverage: - import coverage - cov = coverage.Coverage(config_file="tools/.coveragerc") - if options.coverage == 'combine': - cov.load() - cov.start() - - module = 'zulip_bots/zulip_bots/tests/' - suite = unittest.defaultTestLoader.discover(module) - - suite = unittest.TestSuite([suite]) - runner = unittest.TextTestRunner(verbosity=2) - result = runner.run(suite) - if result.failures or result.errors: - sys.exit(1) - - if not result.failures and options.coverage: - cov.stop() - cov.data_suffix = False # Disable suffix so that filename is .coverage - cov.save() - cov.html_report() - print("HTML report saved under directory 'htmlcov'.") +from server_lib.test_handler import handle_input_and_run_tests_for_package if __name__ == '__main__': - run_all() + handle_input_and_run_tests_for_package('Bot library', ['zulip_bots', 'zulip_bots', 'tests'])