Chromium Code Reviews| Index: tools/telemetry/telemetry/test_runner.py |
| diff --git a/tools/telemetry/telemetry/test_runner.py b/tools/telemetry/telemetry/test_runner.py |
| index 6d43391da228724036379f6fb32cd4244a3e4b26..dead322e723d685c868e3c22cf71beaf5703d3e1 100644 |
| --- a/tools/telemetry/telemetry/test_runner.py |
| +++ b/tools/telemetry/telemetry/test_runner.py |
| @@ -19,14 +19,14 @@ from telemetry.core import browser_finder |
| from telemetry.core import browser_options |
| from telemetry.core import command_line |
| from telemetry.core import discover |
| -from telemetry.core import environment |
| -from telemetry.core import util |
| from telemetry.page import page_set |
| from telemetry.page import page_test |
| -from telemetry.page import profile_creator |
| from telemetry.util import find_dependencies |
| +test_class_types = [benchmark.Benchmark, page_test.PageTest] |
|
nednguyen
2014/09/04 03:31:37
May better be explicit about this: _BENCHMARK_AND_
|
| + |
| + |
| class Deps(find_dependencies.FindDependenciesCommand): |
| """Prints all dependencies""" |
| @@ -80,7 +80,7 @@ class List(command_line.OptparseCommand): |
| @classmethod |
| def ProcessCommandLineArgs(cls, parser, args): |
| if not args.positional_args: |
| - args.tests = _Tests() |
| + args.tests = _GetAllTests() |
| elif len(args.positional_args) == 1: |
| args.tests = _MatchTestName(args.positional_args[0], exact_matches=False) |
| else: |
| @@ -127,7 +127,7 @@ class Run(command_line.OptparseCommand): |
| @classmethod |
| def ProcessCommandLineArgs(cls, parser, args): |
| if not args.positional_args: |
| - _PrintTestList(_Tests()) |
| + _PrintTestList(output_stream=sys.stderr) |
| sys.exit(-1) |
| input_test_name = args.positional_args[0] |
| @@ -135,14 +135,14 @@ class Run(command_line.OptparseCommand): |
| if not matching_tests: |
| print >> sys.stderr, 'No test named "%s".' % input_test_name |
| print >> sys.stderr |
| - _PrintTestList(_Tests()) |
| + _PrintTestList(output_stream=sys.stderr) |
| sys.exit(-1) |
| if len(matching_tests) > 1: |
| print >> sys.stderr, 'Multiple tests named "%s".' % input_test_name |
| print >> sys.stderr, 'Did you mean one of these?' |
| print >> sys.stderr |
| - _PrintTestList(matching_tests) |
| + _PrintTestList(matching_tests, output_stream=sys.stderr) |
| sys.exit(-1) |
| test_class = matching_tests.pop() |
| @@ -195,48 +195,22 @@ def _Commands(): |
| continue |
| yield cls |
| + |
| def _MatchingCommands(string): |
| return [command for command in _Commands() |
| if command.Name().startswith(string)] |
| -@decorators.Cache |
| -def _Tests(): |
| - tests = [] |
| - for base_dir in config.base_paths: |
| - tests += discover.DiscoverClasses(base_dir, base_dir, benchmark.Benchmark, |
| - index_by_class_name=True).values() |
| - page_tests = discover.DiscoverClasses(base_dir, base_dir, |
| - page_test.PageTest, |
| - index_by_class_name=True).values() |
| - tests += [test_class for test_class in page_tests |
| - if not issubclass(test_class, profile_creator.ProfileCreator)] |
| - return tests |
| - |
| - |
| -def _MatchTestName(input_test_name, exact_matches=True): |
| - def _Matches(input_string, search_string): |
| - if search_string.startswith(input_string): |
| - return True |
| - for part in search_string.split('.'): |
| - if part.startswith(input_string): |
| - return True |
| - return False |
| - |
| - # Exact matching. |
| - if exact_matches: |
| - # Don't add aliases to search dict, only allow exact matching for them. |
| - if input_test_name in config.test_aliases: |
| - exact_match = config.test_aliases[input_test_name] |
| - else: |
| - exact_match = input_test_name |
| - for test_class in _Tests(): |
| - if exact_match == test_class.Name(): |
| - return [test_class] |
| +def _GetAllTests(): |
| + return discover.GetValidSubclassesOfClasses(test_class_types) |
| + |
| + |
| +def _MatchTestName(input_name, exact_matches=True): |
| + return discover.MatchName(test_class_types, input_name, exact_matches) |
| + |
| - # Fuzzy matching. |
| - return [test_class for test_class in _Tests() |
| - if _Matches(input_test_name, test_class.Name())] |
| +def _PrintTestList(class_list=None, output_stream=sys.stdout): |
| + discover.PrintAvailableClasses(test_class_types, class_list, output_stream) |
| def _GetJsonTestList(possible_browser, test_classes, num_shards): |
| @@ -281,36 +255,6 @@ def _GetJsonTestList(possible_browser, test_classes, num_shards): |
| return json.dumps(output, indent=2, sort_keys=True) |
| -def _PrintTestList(tests): |
| - if not tests: |
| - print >> sys.stderr, 'No tests found!' |
| - return |
| - |
| - # Align the test names to the longest one. |
| - format_string = ' %%-%ds %%s' % max(len(t.Name()) for t in tests) |
| - |
| - filtered_tests = [test_class for test_class in tests |
| - if issubclass(test_class, benchmark.Benchmark)] |
| - if filtered_tests: |
| - print >> sys.stderr, 'Available tests are:' |
| - for test_class in sorted(filtered_tests, key=lambda t: t.Name()): |
| - print >> sys.stderr, format_string % ( |
| - test_class.Name(), test_class.Description()) |
| - print >> sys.stderr |
| - |
| - filtered_tests = [test_class for test_class in tests |
| - if issubclass(test_class, page_test.PageTest)] |
| - if filtered_tests: |
| - print >> sys.stderr, 'Available page tests are:' |
| - for test_class in sorted(filtered_tests, key=lambda t: t.Name()): |
| - print >> sys.stderr, format_string % ( |
| - test_class.Name(), test_class.Description()) |
| - print >> sys.stderr |
| - |
| - |
| -config = environment.Environment([util.GetBaseDir()]) |
| - |
| - |
| def main(): |
| # Get the command name from the command line. |
| if len(sys.argv) > 1 and sys.argv[1] == '--help': |