OLD | NEW |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 import fnmatch | 4 import fnmatch |
5 import logging | 5 import logging |
6 import os | 6 import os |
7 import traceback | 7 import traceback |
8 import unittest | 8 import unittest |
9 | 9 |
10 from telemetry import browser_options | 10 from telemetry import browser_options |
11 from telemetry import options_for_unittests | 11 from telemetry import options_for_unittests |
12 | 12 |
13 def RequiresBrowserOfType(*types): | 13 def RequiresBrowserOfType(*types): |
14 def wrap(func): | 14 def wrap(func): |
15 func._requires_browser_types = types | 15 func._requires_browser_types = types |
16 return func | 16 return func |
17 return wrap | 17 return wrap |
18 | 18 |
19 def Discover(start_dir, pattern = 'test*.py', top_level_dir = None): | 19 def Discover(start_dir, pattern = 'test*.py', top_level_dir = None): |
20 if hasattr(unittest.defaultTestLoader, 'discover'): | |
21 return unittest.defaultTestLoader.discover( # pylint: disable=E1101 | |
22 start_dir, | |
23 pattern, | |
24 top_level_dir) | |
25 | |
26 modules = [] | 20 modules = [] |
27 for dirpath, _, filenames in os.walk(start_dir): | 21 for dirpath, _, filenames in os.walk(start_dir): |
28 for filename in filenames: | 22 for filename in filenames: |
29 if not filename.endswith('.py'): | 23 if not filename.endswith('.py'): |
30 continue | 24 continue |
31 | 25 |
32 if not fnmatch.fnmatch(filename, pattern): | 26 if not fnmatch.fnmatch(filename, pattern): |
33 continue | 27 continue |
34 | 28 |
35 if filename.startswith('.') or filename.startswith('_'): | 29 if filename.startswith('.') or filename.startswith('_'): |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 try: | 128 try: |
135 os.chdir(top_level_dir) | 129 os.chdir(top_level_dir) |
136 for _ in range( | 130 for _ in range( |
137 default_options.run_test_repeat_count): # pylint: disable=E1101 | 131 default_options.run_test_repeat_count): # pylint: disable=E1101 |
138 num_errors += DiscoverAndRunTests(start_dir, args, top_level_dir) | 132 num_errors += DiscoverAndRunTests(start_dir, args, top_level_dir) |
139 finally: | 133 finally: |
140 os.chdir(olddir) | 134 os.chdir(olddir) |
141 options_for_unittests.Set(None, None) | 135 options_for_unittests.Set(None, None) |
142 | 136 |
143 return min(num_errors, 255) | 137 return min(num_errors, 255) |
OLD | NEW |