2017-08-21 09:01:15 -04:00
|
|
|
#!/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',
|
2017-08-21 09:03:08 -04:00
|
|
|
nargs='?',
|
|
|
|
const=True,
|
|
|
|
default=False,
|
|
|
|
help='compute test coverage (--coverage combine to combine with previous reports)')
|
2017-08-21 09:01:15 -04:00
|
|
|
options = parser.parse_args()
|
|
|
|
|
|
|
|
if options.coverage:
|
|
|
|
import coverage
|
|
|
|
cov = coverage.Coverage(config_file="tools/.coveragerc")
|
2017-08-21 09:03:08 -04:00
|
|
|
if options.coverage == 'combine':
|
|
|
|
cov.load()
|
2017-08-21 09:01:15 -04:00
|
|
|
cov.start()
|
|
|
|
|
2017-08-22 03:46:16 -04:00
|
|
|
# Codecov seems to work only when using loader.discover. It failed to capture line executions
|
|
|
|
# for functions like loader.loadTestFromModule or loader.loadTestFromNames.
|
2017-08-21 09:01:15 -04:00
|
|
|
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.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()
|