From 95021ebd5699dba989d09da1cfbbef0dc0d5b6c7 Mon Sep 17 00:00:00 2001 From: derAnfaenger Date: Mon, 21 Aug 2017 15:01:15 +0200 Subject: [PATCH] testing: Add script for executing zulip_botserver tests. --- tools/test-botserver | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100755 tools/test-botserver diff --git a/tools/test-botserver b/tools/test-botserver new file mode 100755 index 0000000..34776f0 --- /dev/null +++ b/tools/test-botserver @@ -0,0 +1,43 @@ +#!/usr/bin/env python + +from importlib import import_module + +import os +import sys +import argparse +import unittest + +def main(): + TOOLS_DIR = os.path.dirname(os.path.abspath(__file__)) + os.chdir(os.path.dirname(TOOLS_DIR)) + + parser = argparse.ArgumentParser(description="Run tests for the zulip_botserver package.") + parser.add_argument('--coverage', + action='store_true', + help='compute test coverage') + options = parser.parse_args() + + if options.coverage: + import coverage + cov = coverage.Coverage(config_file="tools/.coveragerc") + cov.start() + + test_suites = unittest.defaultTestLoader.discover('zulip_botserver') + suite = unittest.TestSuite(test_suites) + 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.save() + cov.combine() + cov.data_suffix = False # Disable suffix so that filename is .coverage + cov.save() + cov.html_report() + print("HTML report saved in directory 'htmlcov'.") + + +if __name__ == '__main__': + main()