From b31cf2f9a990d22744c72bb15b7af4ef94307dac Mon Sep 17 00:00:00 2001 From: derAnfaenger Date: Mon, 4 Sep 2017 20:21:24 +0200 Subject: [PATCH] zulip package: Add test runner script. --- tools/test-zulip | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100755 tools/test-zulip diff --git a/tools/test-zulip b/tools/test-zulip new file mode 100755 index 0000000..a676d28 --- /dev/null +++ b/tools/test-zulip @@ -0,0 +1,47 @@ +#!/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 package.") + parser.add_argument('--coverage', + nargs='?', + const=True, + default=False, + help='compute test coverage (--coverage combine to combine with previous reports)') + options = parser.parse_args() + + if options.coverage: + import coverage + cov = coverage.Coverage(config_file="tools/.coveragerc") + if options.coverage == 'combine': + cov.load() + cov.start() + + # Codecov seems to work only when using loader.discover. It failed to capture line executions + # for functions like loader.loadTestFromModule or loader.loadTestFromNames. + test_suites = unittest.defaultTestLoader.discover('zulip') + 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.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()