forked from zulip/zulip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-tools
executable file
·45 lines (34 loc) · 1.19 KB
/
test-tools
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env python3
import argparse
import os
import sys
import unittest
tools_dir = os.path.dirname(os.path.abspath(__file__))
root_dir = os.path.abspath(os.path.join(tools_dir, ".."))
tools_test_dir = os.path.join(tools_dir, "tests")
sys.path.insert(0, root_dir)
# check for the venv
from tools.lib import sanity_check
sanity_check.check_venv(__file__)
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--coverage", action="store_true", help="compute test coverage")
args = parser.parse_args()
loader = unittest.TestLoader()
if args.coverage:
import coverage
cov = coverage.Coverage(
branch=True, omit=["*/zulip-venv-cache/*", os.path.join(tools_test_dir, "*")]
)
cov.start()
suite = loader.discover(start_dir=tools_test_dir, top_level_dir=root_dir)
runner = unittest.TextTestRunner(verbosity=2)
result = runner.run(suite)
if result.errors or result.failures:
raise Exception("Test failed!")
if args.coverage:
cov.stop()
cov.save()
cov.html_report(directory="var/tools_coverage")
print("HTML report saved to var/tools_coverage")
print("SUCCESS")