OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2015 The Chromium Authors. All rights reserved. | 2 # Copyright 2015 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """A wrapper around typ (test your projects).""" | 6 """A wrapper around typ (test your projects).""" |
7 | 7 |
8 import os | 8 import os |
9 import sys | 9 import sys |
10 | 10 |
11 | 11 |
12 def Run(top_level_dir, path=None): | 12 def Run(top_level_dir, path=None, suffixes=None): |
13 """Runs a set of Python tests using typ. | 13 """Runs a set of Python tests using typ. |
14 | 14 |
15 Args: | 15 Args: |
16 top_level_dir: Directory to look for Python unit tests in. | 16 top_level_dir: Directory to look for Python unit tests in. |
17 path: A list of extra paths to add to sys.path when running the tests. | 17 path: A list of extra paths to add to sys.path when running the tests. |
18 | 18 |
19 Returns: | 19 Returns: |
20 An exit code (0 for success, otherwise non-zero). | 20 An exit code (0 for success, otherwise non-zero). |
21 """ | 21 """ |
| 22 if not suffixes: |
| 23 suffixes = ['*_test.py', '*_unittest.py'] |
22 typ_path = os.path.abspath(os.path.join( | 24 typ_path = os.path.abspath(os.path.join( |
23 os.path.dirname(__file__), os.path.pardir, 'third_party', 'typ')) | 25 os.path.dirname(__file__), os.path.pardir, 'third_party', 'typ')) |
24 _AddToPathIfNeeded(typ_path) | 26 _AddToPathIfNeeded(typ_path) |
25 import typ | 27 import typ |
26 return typ.main( | 28 return typ.main( |
27 top_level_dir=top_level_dir, | 29 top_level_dir=top_level_dir, |
28 path=(path or []), | 30 path=(path or []), |
29 coverage_source=[top_level_dir]) | 31 coverage_source=[top_level_dir], |
| 32 suffixes=suffixes) |
30 | 33 |
31 | 34 |
32 def _AddToPathIfNeeded(path): | 35 def _AddToPathIfNeeded(path): |
33 if path not in sys.path: | 36 if path not in sys.path: |
34 sys.path.insert(0, path) | 37 sys.path.insert(0, path) |
OLD | NEW |