2017-11-29 16:30:09 -05:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import unittest
|
2017-11-29 19:48:11 -05:00
|
|
|
import argparse
|
2017-11-29 16:30:09 -05:00
|
|
|
|
|
|
|
from importlib import import_module
|
|
|
|
|
2017-11-29 19:48:11 -05:00
|
|
|
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()
|
|
|
|
|
2017-11-29 16:30:09 -05:00
|
|
|
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)
|
|
|
|
|
2017-11-29 19:48:11 -05:00
|
|
|
options = parse_args()
|
|
|
|
|
|
|
|
if options.coverage:
|
|
|
|
import coverage
|
|
|
|
cov = coverage.Coverage(config_file="tools/.coveragerc")
|
|
|
|
if options.coverage == 'combine':
|
|
|
|
cov.load()
|
|
|
|
cov.start()
|
2017-11-29 16:30:09 -05:00
|
|
|
|
|
|
|
module = import_module('zulip_bots.lib_tests')
|
|
|
|
suite = unittest.defaultTestLoader.loadTestsFromModule(module)
|
|
|
|
|
|
|
|
suite = unittest.TestSuite([suite])
|
|
|
|
runner = unittest.TextTestRunner(verbosity=2)
|
|
|
|
result = runner.run(suite)
|
|
|
|
if result.failures or result.errors:
|
|
|
|
sys.exit(1)
|
|
|
|
|
2017-11-29 19:48:11 -05:00
|
|
|
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'.")
|
2017-11-29 16:30:09 -05:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
run_all()
|