2016-08-04 00:35:53 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
from __future__ import absolute_import
|
|
|
|
from __future__ import print_function
|
|
|
|
|
2016-08-29 00:52:31 +02:00
|
|
|
import argparse
|
2016-08-04 00:35:53 +02:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import unittest
|
|
|
|
|
2017-02-05 21:24:28 +01:00
|
|
|
# check for the venv
|
|
|
|
from lib import sanity_check
|
|
|
|
sanity_check.check_venv(__file__)
|
|
|
|
|
2016-08-04 00:35:53 +02:00
|
|
|
if __name__ == '__main__':
|
2016-08-29 00:52:31 +02:00
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
parser.add_argument('--coverage', dest='coverage',
|
2016-12-11 14:30:45 +01:00
|
|
|
action="store_true",
|
|
|
|
default=False, help='compute test coverage')
|
2016-08-29 00:52:31 +02:00
|
|
|
args = parser.parse_args()
|
2016-08-04 00:35:53 +02:00
|
|
|
|
|
|
|
def dir_join(dir1, dir2):
|
|
|
|
# type: (str, str) -> str
|
|
|
|
return os.path.abspath(os.path.join(dir1, dir2))
|
|
|
|
|
|
|
|
tools_dir = os.path.dirname(os.path.abspath(__file__))
|
|
|
|
root_dir = dir_join(tools_dir, '..')
|
|
|
|
tools_test_dir = dir_join(tools_dir, 'tests')
|
|
|
|
|
|
|
|
sys.path.insert(0, root_dir)
|
|
|
|
|
|
|
|
loader = unittest.TestLoader() # type: ignore # https://github.com/python/typeshed/issues/372
|
|
|
|
|
2016-08-29 00:52:31 +02:00
|
|
|
if args.coverage:
|
2016-08-04 00:35:53 +02:00
|
|
|
import coverage
|
2016-12-02 06:22:52 +01:00
|
|
|
cov = coverage.Coverage(branch=True, omit=["*/zulip-venv-cache/*", dir_join(tools_test_dir, "*")])
|
2016-08-04 00:35:53 +02:00
|
|
|
cov.start()
|
|
|
|
|
|
|
|
suite = loader.discover(start_dir=tools_test_dir, top_level_dir=root_dir)
|
|
|
|
runner = unittest.TextTestRunner(verbosity=2)
|
|
|
|
result = runner.run(suite) # type: ignore # https://github.com/python/typeshed/issues/372
|
|
|
|
if result.errors or result.failures:
|
|
|
|
raise Exception('Test failed!')
|
|
|
|
|
2016-08-29 00:52:31 +02:00
|
|
|
if args.coverage:
|
2016-08-04 00:35:53 +02:00
|
|
|
cov.stop()
|
|
|
|
cov.save()
|
|
|
|
cov.html_report(directory='var/tools_coverage')
|
|
|
|
print("HTML report saved to var/tools_coverage")
|
|
|
|
|
|
|
|
print('SUCCESS')
|