-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathrun_tests
executable file
·44 lines (37 loc) · 1.31 KB
/
run_tests
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
#!/usr/bin/env python
# Copyright (c) 2015 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import argparse
import os
import sys
import unittest
def _IterateTestCase(test):
if isinstance(test, unittest.TestCase):
yield test
else:
for t in test:
for u in _IterateTestCase(t):
yield u
def main(args):
parser = argparse.ArgumentParser(description='Run all vinn tests')
parser.add_argument('test_name', type=str, nargs='?',
help=('Specify a specific test to run. If this is empty, '
'all tests are run. (the name can be a substring '
' of test names)'))
options = parser.parse_args(args)
def _IsTestMatched(test):
if not options.test_name:
return True
return options.test_name in test.id()
suite = unittest.TestSuite()
vinn_dir = os.path.join(os.path.dirname(__file__), 'vinn')
discover_tests = unittest.TestLoader().discover(
start_dir=vinn_dir, pattern='*test.py')
for t in _IterateTestCase(discover_tests):
if _IsTestMatched(t):
suite.addTest(t)
results = unittest.TextTestRunner(verbosity=2).run(suite)
return len(results.failures)
if __name__ == '__main__':
sys.exit(main(sys.argv[1:]))