Commit 70712e0c authored by ariblue's avatar ariblue Committed by Commit bot

Update test_runner.py to use page_set names rather than paths.

This allows us to get rid of the page_set dependency in discover.py,
since it eliminates the last call to IsPageSetFile.

BUG=

Review URL: https://codereview.chromium.org/551883003

Cr-Commit-Position: refs/heads/master@{#293973}
parent 50f0dca8
...@@ -9,8 +9,6 @@ import re ...@@ -9,8 +9,6 @@ import re
from telemetry import decorators from telemetry import decorators
from telemetry.core import camel_case from telemetry.core import camel_case
from telemetry.core import util
from telemetry.page import page_set
@decorators.Cache @decorators.Cache
...@@ -123,13 +121,3 @@ _counter = [0] ...@@ -123,13 +121,3 @@ _counter = [0]
def _GetUniqueModuleName(): def _GetUniqueModuleName():
_counter[0] += 1 _counter[0] += 1
return "module_" + str(_counter[0]) return "module_" + str(_counter[0])
def IsPageSetFile(file_path):
root_name, ext_name = os.path.splitext(file_path)
if 'unittest' in root_name or 'page_sets/data' in root_name:
return False
if ext_name != '.py':
return False
module = util.GetPythonPageSetModule(file_path)
return bool(DiscoverClassesInModule(module, page_set.PageSet))
...@@ -51,17 +51,3 @@ class DiscoverTest(unittest.TestCase): ...@@ -51,17 +51,3 @@ class DiscoverTest(unittest.TestCase):
'dummy_exception_impl2': 'DummyExceptionImpl2', 'dummy_exception_impl2': 'DummyExceptionImpl2',
} }
self.assertEqual(actual_classes, expected_classes) self.assertEqual(actual_classes, expected_classes)
def testIsPageSetFile(self):
top_10_ps_dir = os.path.join(util.GetChromiumSrcDir(),
'tools/perf/page_sets/top_10.py')
top_10_json_data = os.path.join(util.GetChromiumSrcDir(),
'tools/perf/page_sets/data/top_10.json')
test_ps_dir = os.path.join(util.GetTelemetryDir(),
'unittest_data/test_page_set.py')
page_set_dir = os.path.join(util.GetTelemetryDir(),
'telemetry/page/page_set.py')
self.assertTrue(discover.IsPageSetFile(top_10_ps_dir))
self.assertFalse(discover.IsPageSetFile(top_10_json_data))
self.assertFalse(discover.IsPageSetFile(test_ps_dir))
self.assertFalse(discover.IsPageSetFile(page_set_dir))
...@@ -151,19 +151,19 @@ class Run(command_line.OptparseCommand): ...@@ -151,19 +151,19 @@ class Run(command_line.OptparseCommand):
parser.error('Need to specify a page set for "%s".' % test_class.Name()) parser.error('Need to specify a page set for "%s".' % test_class.Name())
if len(args.positional_args) > 2: if len(args.positional_args) > 2:
parser.error('Too many arguments.') parser.error('Too many arguments.')
page_set_path = args.positional_args[1] page_set_name = args.positional_args[1]
if not os.path.exists(page_set_path): page_set_class = _MatchPageSetName(page_set_name)
parser.error('Page set not found.') if page_set_class is None:
if not (os.path.isfile(page_set_path) and parser.error(
discover.IsPageSetFile(page_set_path)): 'Page set not found. Please specify the name of a valid page set.')
parser.error('Unsupported page set file format.') #TODO(ariblue): Print available page sets.
class TestWrapper(benchmark.Benchmark): class TestWrapper(benchmark.Benchmark):
test = test_class test = test_class
@classmethod @classmethod
def CreatePageSet(cls, options): def CreatePageSet(cls, options):
return page_set.PageSet.FromFile(page_set_path) return page_set_class()
test_class = TestWrapper test_class = TestWrapper
else: else:
...@@ -213,6 +213,19 @@ def _Tests(): ...@@ -213,6 +213,19 @@ def _Tests():
return tests return tests
# TODO(ariblue): Use discover.py's abstracted _MatchName class (in pending CL
# 432543003) and eliminate _MatchPageSetName and _MatchTestName.
def _MatchPageSetName(input_name):
page_sets = []
for base_dir in config.base_paths:
page_sets += discover.DiscoverClasses(base_dir, base_dir, page_set.PageSet,
index_by_class_name=True).values()
for p in page_sets:
if input_name == p.Name():
return p
return None
def _MatchTestName(input_test_name, exact_matches=True): def _MatchTestName(input_test_name, exact_matches=True):
def _Matches(input_string, search_string): def _Matches(input_string, search_string):
if search_string.startswith(input_string): if search_string.startswith(input_string):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment