blob: b68bc0929871e749d5d7771b227ab5f774f55c69 [file] [log] [blame]
# Copyright (c) 2012 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""A module to analyze test expectations for Webkit layout tests."""
import urllib2
from webkitpy.layout_tests.models.test_expectations import *
# Default location for chromium test expectation file.
# TODO(imasaki): support multiple test expectations files.
# The following is from test expectation syntax. The detail can be found in
# <decision> ::== [SKIP] [WONTFIX] [SLOW]
# <config> ::== RELEASE | DEBUG
# Only hard code keywords we don't expect to change. Determine the rest from
# the format of the status line.
class TestExpectations(object):
"""A class to model the content of test expectation file for analysis.
This class retrieves the TestExpectations file via HTTP from WebKit and uses
the WebKit layout test processor to process each line.
The resulting dictionary is stored in |all_test_expectation_info| and looks
{'<test name>': [{'<modifier0>': True, '<modifier1>': True, ...,
'Platforms: ['<platform0>', ... ], 'Bugs': ['....']}]}
Duplicate keys are merged (though technically they shouldn't exist).
Example: [ Android ] \
platform/chromium/media/video-frame-size-change.html [ Timeout ] [ SnowLeopard ] \
platform/chromium/media/video-frame-size-change.html \
[ ImageOnlyFailure Pass ]
{'platform/chromium/media/video-frame-size-change.html': [{'IMAGE': True,
'Bugs': ['BUGWK84724', 'BUGCR145590'], 'Comments': '',
'Platforms': ['SNOWLEOPARD', 'ANDROID'], 'TIMEOUT': True, 'PASS': True}]}
"""Read the test expectation file from the specified URL and parse it.
url: A URL string for the test expectation file.
NameError when the test expectation file cannot be retrieved from |url|.
self.all_test_expectation_info = {}
resp = urllib2.urlopen(url)
if resp.code != 200:
raise NameError('Test expectation file does not exist in %s' % url)
# Start parsing each line.
for line in'\n'):
line = line.strip()
# Skip comments.
if line.startswith('#'):
testname, te_info = self.ParseLine(line)
if not testname or not te_info:
if testname in self.all_test_expectation_info:
# Merge keys if entry already exists.
for k in te_info.keys():
if (isinstance(te_info[k], list) and
k in self.all_test_expectation_info[testname]):
self.all_test_expectation_info[testname][0][k] += te_info[k]
self.all_test_expectation_info[testname][0][k] = te_info[k]
self.all_test_expectation_info[testname] = [te_info]
def ParseLine(line):
"""Parses the provided line using WebKit's TextExpecations parser.
Tuple of test name, test expectations dictionary. See class documentation
for the format of the dictionary
test_expectation_info = {}
parsed = TestExpectationParser._tokenize_line('TestExpectations', line, 0)
if parsed.is_invalid():
return None, None
test_expectation_info['Comments'] = parsed.comment or ''
test_expectation_info['Bugs'] = parsed.bugs or [];
test_expectation_info['Platforms'] = parsed.specifiers or []
# Shovel the expectations and modifiers in as "<key>: True" entries. Ugly,
# but required by the rest of the pipeline for parsing.
for m in parsed.expectations:
test_expectation_info[m] = True
return, test_expectation_info