| Index: tools/telemetry/telemetry/test_runner.py
|
| diff --git a/tools/telemetry/telemetry/test_runner.py b/tools/telemetry/telemetry/test_runner.py
|
| index 66b923bb192c7c266f4bd16df4a880e92b9e110f..40e2496e22b2432504352e29cec01a3273557277 100644
|
| --- a/tools/telemetry/telemetry/test_runner.py
|
| +++ b/tools/telemetry/telemetry/test_runner.py
|
| @@ -17,14 +17,42 @@ from telemetry import test
|
| 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
|
|
|
|
|
| +class Environment(object):
|
| + def __init__(self, top_level_dir, test_dirs=None, page_test_dirs=None,
|
| + page_set_dirs=None, test_aliases=None):
|
| + self._top_level_dir = top_level_dir
|
| + self._test_dirs = test_dirs or []
|
| + self._page_test_dirs = page_test_dirs or []
|
| + self._page_set_dirs = page_set_dirs or []
|
| + self._test_aliases = test_aliases or []
|
| +
|
| + @property
|
| + def top_level_dir(self):
|
| + return self._top_level_dir
|
| +
|
| + @property
|
| + def test_dirs(self):
|
| + return self._test_dirs
|
| +
|
| + @property
|
| + def page_test_dirs(self):
|
| + return self._page_test_dirs
|
| +
|
| + @property
|
| + def page_set_dirs(self):
|
| + return self._page_set_dirs
|
| +
|
| + @property
|
| + def test_aliases(self):
|
| + return self._test_aliases
|
| +
|
| +
|
| class Deps(find_dependencies.FindDependenciesCommand):
|
| """Prints all dependencies"""
|
|
|
| @@ -52,15 +80,17 @@ class List(command_line.OptparseCommand):
|
| usage = '[test_name] [<options>]'
|
|
|
| @classmethod
|
| - def AddCommandLineArgs(cls, parser):
|
| + def AddCommandLineArgs(cls, parser, _): # pylint: disable=W0221
|
| parser.add_option('-j', '--json', action='store_true')
|
|
|
| @classmethod
|
| - def ProcessCommandLineArgs(cls, parser, args):
|
| + def ProcessCommandLineArgs(cls, parser, args, environment):
|
| + # pylint: disable=W0221
|
| if not args.positional_args:
|
| - args.tests = _Tests()
|
| + args.tests = _Tests(environment)
|
| elif len(args.positional_args) == 1:
|
| - args.tests = _MatchTestName(args.positional_args[0], exact_matches=False)
|
| + args.tests = _MatchTestName(args.positional_args[0], environment,
|
| + exact_matches=False)
|
| else:
|
| parser.error('Must provide at most one test name.')
|
|
|
| @@ -91,13 +121,13 @@ class Run(command_line.OptparseCommand):
|
| return parser
|
|
|
| @classmethod
|
| - def AddCommandLineArgs(cls, parser):
|
| + def AddCommandLineArgs(cls, parser, environment): # pylint: disable=W0221
|
| test.AddCommandLineArgs(parser)
|
|
|
| # Allow tests to add their own command line options.
|
| matching_tests = []
|
| for arg in sys.argv[1:]:
|
| - matching_tests += _MatchTestName(arg)
|
| + matching_tests += _MatchTestName(arg, environment)
|
|
|
| if matching_tests:
|
| # TODO(dtu): After move to argparse, add command-line args for all tests
|
| @@ -108,17 +138,18 @@ class Run(command_line.OptparseCommand):
|
| matching_test.SetArgumentDefaults(parser)
|
|
|
| @classmethod
|
| - def ProcessCommandLineArgs(cls, parser, args):
|
| + def ProcessCommandLineArgs(cls, parser, args, environment):
|
| + # pylint: disable=W0221
|
| if not args.positional_args:
|
| - _PrintTestList(_Tests())
|
| + _PrintTestList(_Tests(environment))
|
| sys.exit(-1)
|
|
|
| input_test_name = args.positional_args[0]
|
| - matching_tests = _MatchTestName(input_test_name)
|
| + matching_tests = _MatchTestName(input_test_name, environment)
|
| if not matching_tests:
|
| print >> sys.stderr, 'No test named "%s".' % input_test_name
|
| print >> sys.stderr
|
| - _PrintTestList(_Tests())
|
| + _PrintTestList(_Tests(environment))
|
| sys.exit(-1)
|
|
|
| if len(matching_tests) > 1:
|
| @@ -179,12 +210,14 @@ def _Commands():
|
|
|
|
|
| @decorators.Cache
|
| -def _Tests():
|
| +def _Tests(environment):
|
| tests = []
|
| - for base_dir in config.base_paths:
|
| - tests += discover.DiscoverClasses(base_dir, base_dir, test.Test,
|
| + for search_dir in environment.test_dirs:
|
| + tests += discover.DiscoverClasses(search_dir, environment.top_level_dir,
|
| + test.Test,
|
| index_by_class_name=True).values()
|
| - page_tests = discover.DiscoverClasses(base_dir, base_dir,
|
| + for search_dir in environment.page_test_dirs:
|
| + page_tests = discover.DiscoverClasses(search_dir, environment.top_level_dir,
|
| page_test.PageTest,
|
| index_by_class_name=True).values()
|
| tests += [test_class for test_class in page_tests
|
| @@ -192,7 +225,7 @@ def _Tests():
|
| return tests
|
|
|
|
|
| -def _MatchTestName(input_test_name, exact_matches=True):
|
| +def _MatchTestName(input_test_name, environment, exact_matches=True):
|
| def _Matches(input_string, search_string):
|
| if search_string.startswith(input_string):
|
| return True
|
| @@ -204,17 +237,17 @@ def _MatchTestName(input_test_name, exact_matches=True):
|
| # 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]
|
| + if input_test_name in environment.test_aliases:
|
| + exact_match = environment.test_aliases[input_test_name]
|
| else:
|
| exact_match = input_test_name
|
|
|
| - for test_class in _Tests():
|
| + for test_class in _Tests(environment):
|
| if exact_match == test_class.Name():
|
| return [test_class]
|
|
|
| # Fuzzy matching.
|
| - return [test_class for test_class in _Tests()
|
| + return [test_class for test_class in _Tests(environment)
|
| if _Matches(input_test_name, test_class.Name())]
|
|
|
|
|
| @@ -245,10 +278,7 @@ def _PrintTestList(tests):
|
| print >> sys.stderr
|
|
|
|
|
| -config = environment.Environment([util.GetBaseDir()])
|
| -
|
| -
|
| -def main():
|
| +def main(environment):
|
| # Get the command name from the command line.
|
| if len(sys.argv) > 1 and sys.argv[1] == '--help':
|
| sys.argv[1] = 'help'
|
| @@ -276,10 +306,10 @@ def main():
|
|
|
| # Parse and run the command.
|
| parser = command.CreateParser()
|
| - command.AddCommandLineArgs(parser)
|
| + command.AddCommandLineArgs(parser, environment)
|
| options, args = parser.parse_args()
|
| if commands:
|
| args = args[1:]
|
| options.positional_args = args
|
| - command.ProcessCommandLineArgs(parser, options)
|
| + command.ProcessCommandLineArgs(parser, options, environment)
|
| return command().Run(options)
|
|
|