Tools/ChangeLog

 12012-07-02 Dirk Pranke <dpranke@chromium.org>
 2
 3 webkitpy: lint code in webkitpy.layout_tests.models
 4 https://bugs.webkit.org/show_bug.cgi?id=90416
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 Cleaning up errors reported from lint-webkitpy.
 9
 10 Also, suppress the warnings about wildcard imports in pylintrc;
 11 we have nothing particularly against them.
 12
 13 * Scripts/webkitpy/layout_tests/models/test_configuration.py:
 14 (TestConfigurationConverter.combinations):
 15 * Scripts/webkitpy/layout_tests/models/test_configuration_unittest.py:
 16 (TestConfigurationTest.test_hash.query_unknown_key):
 17 (TestConfigurationTest.test_eq):
 18 * Scripts/webkitpy/layout_tests/models/test_expectations.py:
 19 (ParseError.__init__):
 20 (TestExpectationLine.__init__):
 21 (TestExpectationsModel.get_expectations_string):
 22 (TestExpectationsModel):
 23 (TestExpectationsModel.expectation_to_string):
 24 (TestExpectationsModel.add_expectation_line):
 25 (TestExpectationsModel._clear_expectations_for_test):
 26 (TestExpectationsModel._remove_from_sets):
 27 (TestExpectations.get_expectations_string):
 28 (TestExpectations.expectation_to_string):
 29 (TestExpectations._report_warnings):
 30 * Scripts/webkitpy/layout_tests/models/test_expectations_unittest.py:
 31 (Base.__init__):
 32 (parse_exp):
 33 (SkippedTests.check):
 34 (TestExpectationParserTests.test_parse_empty_string):
 35 * Scripts/webkitpy/layout_tests/models/test_failures.py:
 36 (FailureTimeout.__init__):
 37 (FailureCrash.__init__):
 38 (FailureImageHashMismatch.__init__):
 39 (FailureReftestMismatch.__init__):
 40 (FailureReftestMismatchDidNotOccur.__init__):
 41 (FailureReftestNoImagesGenerated.__init__):
 42 * Scripts/webkitpy/layout_tests/models/test_failures_unittest.py:
 43 (TestFailuresTest.test_unknown_failure_type.UnknownFailure.message):
 44 (TestFailuresTest.test_unknown_failure_type):
 45 (TestFailuresTest):
 46 (TestFailuresTest.test_message_is_virtual):
 47 * Scripts/webkitpy/layout_tests/models/test_results.py:
 48 (TestResult.loads):
 49 (TestResult.has_failure_matching_types):
 50 * Scripts/webkitpy/pylintrc:
 51
1522012-07-02 Ojan Vafai <ojan@chromium.org>
253
354 Delete unused rebaseline method in gardeningserver.py

Tools/Scripts/webkitpy/layout_tests/models/test_configuration.py

2626# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2727# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2828
29 import itertools
3029
3130class TestConfiguration(object):
3231 def __init__(self, version, architecture, build_type):

@@class TestConfigurationConverter(object):
212211 break
213212 else:
214213 return
215  indices[i] += 1
216  for j in range(i + 1, r):
 214 indices[i] += 1 # pylint: disable=W0631
 215 for j in range(i + 1, r): # pylint: disable=W0631
217216 indices[j] = indices[j - 1] + 1
218217 yield tuple(pool[i] for i in indices)
219218

Tools/Scripts/webkitpy/layout_tests/models/test_configuration_unittest.py

2828
2929import unittest
3030
31 from webkitpy.common.host_mock import MockHost
32 
3331from webkitpy.layout_tests.models.test_configuration import *
3432
3533

@@class TestConfigurationTest(unittest.TestCase):
7775 self.assertTrue(config_dict[TestConfiguration('xp', 'x86', 'release')])
7876
7977 def query_unknown_key():
80  config_dict[TestConfiguration('xp', 'x86', 'debug')]
 78 return config_dict[TestConfiguration('xp', 'x86', 'debug')]
8179
8280 self.assertRaises(KeyError, query_unknown_key)
8381 self.assertTrue(TestConfiguration('xp', 'x86', 'release') in config_dict)

@@class TestConfigurationTest(unittest.TestCase):
8886
8987 def test_eq(self):
9088 self.assertEquals(TestConfiguration('xp', 'x86', 'release'), TestConfiguration('xp', 'x86', 'release'))
91  host = MockHost()
92  test_port = host.port_factory.get('test-win-xp', None)
9389 self.assertNotEquals(TestConfiguration('xp', 'x86', 'release'), TestConfiguration('xp', 'x86', 'debug'))
9490
9591 def test_values(self):

Tools/Scripts/webkitpy/layout_tests/models/test_expectations.py

3131for layout tests.
3232"""
3333
34 import itertools
35 import json
3634import logging
3735import re
3836
39 from webkitpy.layout_tests.models.test_configuration import TestConfiguration, TestConfigurationConverter
 37from webkitpy.layout_tests.models.test_configuration import TestConfigurationConverter
4038
4139_log = logging.getLogger(__name__)
4240

@@def strip_comments(line):
117115
118116class ParseError(Exception):
119117 def __init__(self, warnings):
 118 super(ParseError, self).__init__()
120119 self.warnings = warnings
121120
122121 def __str__(self):

@@class TestExpectationLine(object):
400399 def __init__(self):
401400 """Initializes a blank-line equivalent of an expectation."""
402401 self.original_string = None
 402 self.filename = None # this is the path to the expectations file for this line
403403 self.line_number = None
404  self.name = None
405  self.path = None
 404 self.name = None # this is the path in the line itself
 405 self.path = None # this is the normpath of self.name
406406 self.modifiers = []
407407 self.parsed_modifiers = []
408408 self.parsed_bug_modifiers = []

@@class TestExpectationsModel(object):
515515 def get_expectations(self, test):
516516 return self._test_to_expectations[test]
517517
 518 def get_expectations_string(self, test):
 519 """Returns the expectatons for the given test as an uppercase string.
 520 If there are no expectations for the test, then "PASS" is returned."""
 521 expectations = self.get_expectations(test)
 522 retval = []
 523
 524 for expectation in expectations:
 525 retval.append(self.expectation_to_string(expectation))
 526
 527 return " ".join(retval)
 528
 529 def expectation_to_string(self, expectation):
 530 """Return the uppercased string equivalent of a given expectation."""
 531 for item in TestExpectations.EXPECTATIONS.items():
 532 if item[1] == expectation:
 533 return item[0].upper()
 534 raise ValueError(expectation)
 535
 536
518537 def add_expectation_line(self, expectation_line, in_skipped=False):
519538 """Returns a list of warnings encountered while matching modifiers."""
520539

@@class TestExpectationsModel(object):
525544 if not in_skipped and self._already_seen_better_match(test, expectation_line):
526545 continue
527546
528  self._clear_expectations_for_test(test, expectation_line)
 547 self._clear_expectations_for_test(test)
529548 self._test_to_expectation_line[test] = expectation_line
530549 self._add_test(test, expectation_line)
531550

@@class TestExpectationsModel(object):
559578 # FIXME: What is this?
560579 self._result_type_to_tests[FAIL].add(test)
561580
562  def _clear_expectations_for_test(self, test, expectation_line):
 581 def _clear_expectations_for_test(self, test):
563582 """Remove prexisting expectations for this test.
564583 This happens if we are seeing a more precise path
565584 than a previous listing.

@@class TestExpectationsModel(object):
571590 self._remove_from_sets(test, self._timeline_to_tests)
572591 self._remove_from_sets(test, self._result_type_to_tests)
573592
574  def _remove_from_sets(self, test, dict):
 593 def _remove_from_sets(self, test, dict_of_sets_of_tests):
575594 """Removes the given test from the sets in the dictionary.
576595
577596 Args:
578597 test: test to look for
579598 dict: dict of sets of files"""
580  for set_of_tests in dict.itervalues():
 599 for set_of_tests in dict_of_sets_of_tests.itervalues():
581600 if test in set_of_tests:
582601 set_of_tests.remove(test)
583602

@@class TestExpectations(object):
782801 return self._model.get_tests_with_timeline(timeline)
783802
784803 def get_expectations_string(self, test):
785  """Returns the expectatons for the given test as an uppercase string.
786  If there are no expectations for the test, then "PASS" is returned."""
787  expectations = self._model.get_expectations(test)
788  retval = []
789 
790  for expectation in expectations:
791  retval.append(self.expectation_to_string(expectation))
792 
793  return " ".join(retval)
 804 return self._model.get_expectations_string(test)
794805
795806 def expectation_to_string(self, expectation):
796  """Return the uppercased string equivalent of a given expectation."""
797  for item in self.EXPECTATIONS.items():
798  if item[1] == expectation:
799  return item[0].upper()
800  raise ValueError(expectation)
 807 return self._model.expectation_to_string(expectation)
801808
802809 def matches_an_expected_result(self, test, result, pixel_tests_are_enabled):
803810 expected_results = self._model.get_expectations(test)

@@class TestExpectations(object):
820827 warnings = []
821828 for expectation in self._expectations:
822829 for warning in expectation.warnings:
823  warnings.append('%s:%d %s %s' % (self._shorten_filename(expectation.filename), expectation.line_number, warning, expectation.name if expectation.expectations else expectation.original_string))
 830 warnings.append('%s:%d %s %s' % (self._shorten_filename(expectation.filename), expectation.line_number,
 831 warning, expectation.name if expectation.expectations else expectation.original_string))
824832
825833 if warnings:
826834 self._has_warnings = True

Tools/Scripts/webkitpy/layout_tests/models/test_expectations_unittest.py

@@class Base(unittest.TestCase):
9595 # Note that all of these tests are written assuming the configuration
9696 # being tested is Windows XP, Release build.
9797
98  def __init__(self, testFunc, setUp=None, tearDown=None, description=None):
 98 def __init__(self, testFunc):
9999 host = MockHost()
100100 self._port = host.port_factory.get('test-win-xp', None)
101101 self._exp = None

@@BUG_TEST WONTFIX MAC : failures/expected/image.html = IMAGE
123123"""
124124
125125 def parse_exp(self, expectations, overrides=None, is_lint_mode=False):
126  self._expectations_dict = OrderedDict()
127  self._expectations_dict['expectations'] = expectations
 126 expectations_dict = OrderedDict()
 127 expectations_dict['expectations'] = expectations
128128 if overrides:
129  self._expectations_dict['overrides'] = overrides
130  self._port.expectations_dict = lambda: self._expectations_dict
 129 expectations_dict['overrides'] = overrides
 130 self._port.expectations_dict = lambda: expectations_dict
131131 self._exp = TestExpectations(self._port, self.get_basic_tests(), is_lint_mode)
132132
133133 def assert_exp(self, test, result):

@@class SkippedTests(Base):
274274 def check(self, expectations, overrides, skips, lint=False):
275275 port = MockHost().port_factory.get('qt')
276276 port._filesystem.write_text_file(port._filesystem.join(port.layout_tests_dir(), 'failures/expected/text.html'), 'foo')
277  self._expectations_dict = OrderedDict()
278  self._expectations_dict['expectations'] = expectations
 277 expectations_dict = OrderedDict()
 278 expectations_dict['expectations'] = expectations
279279 if overrides:
280  self._expectations_dict['overrides'] = overrides
281  port.expectations_dict = lambda: self._expectations_dict
 280 expectations_dict['overrides'] = overrides
 281 port.expectations_dict = lambda: expectations_dict
282282 port.skipped_layout_tests = lambda tests: set(skips)
283283 exp = TestExpectations(port, ['failures/expected/text.html'], lint)
284284

@@class TestExpectationParserTests(unittest.TestCase):
532532 host = MockHost()
533533 test_port = host.port_factory.get('test-win-xp', None)
534534 test_port.test_exists = lambda test: True
535  test_config = test_port.test_configuration()
536535 full_test_list = []
537536 expectation_line = self._tokenize('')
538537 parser = TestExpectationParser(test_port, full_test_list, allow_rebaseline_modifier=False)

Tools/Scripts/webkitpy/layout_tests/models/test_failures.py

@@class TestFailure(object):
112112class FailureTimeout(TestFailure):
113113 """Test timed out. We also want to restart DumpRenderTree if this happens."""
114114 def __init__(self, is_reftest=False):
 115 super(FailureTimeout, self).__init__()
115116 self.is_reftest = is_reftest
116117
117118 def message(self):

@@class FailureTimeout(TestFailure):
124125class FailureCrash(TestFailure):
125126 """DumpRenderTree/WebKitTestRunner crashed."""
126127 def __init__(self, is_reftest=False, process_name='DumpRenderTree', pid=None):
 128 super(FailureCrash, self).__init__()
127129 self.process_name = process_name
128130 self.pid = pid
129131 self.is_reftest = is_reftest

@@class FailureMissingImage(TestFailure):
168170class FailureImageHashMismatch(TestFailure):
169171 """Image hashes didn't match."""
170172 def __init__(self, diff_percent=0):
 173 super(FailureImageHashMismatch, self).__init__()
171174 self.diff_percent = diff_percent
172175
173176 def message(self):

@@class FailureReftestMismatch(TestFailure):
185188 """The result didn't match the reference rendering."""
186189
187190 def __init__(self, reference_filename=None):
 191 super(FailureReftestMismatch, self).__init__()
188192 self.reference_filename = reference_filename
189193 self.diff_percent = None
190194

@@class FailureReftestMismatchDidNotOccur(TestFailure):
196200 """Unexpected match between the result and the reference rendering."""
197201
198202 def __init__(self, reference_filename=None):
 203 super(FailureReftestMismatchDidNotOccur, self).__init__()
199204 self.reference_filename = reference_filename
200205
201206 def message(self):

@@class FailureReftestNoImagesGenerated(TestFailure):
206211 """Both the reftest and the -expected html file didn't generate pixel results."""
207212
208213 def __init__(self, reference_filename=None):
 214 super(FailureReftestNoImagesGenerated, self).__init__()
209215 self.reference_filename = reference_filename
210216
211217 def message(self):

Tools/Scripts/webkitpy/layout_tests/models/test_failures_unittest.py

@@class TestFailuresTest(unittest.TestCase):
4545
4646 def test_unknown_failure_type(self):
4747 class UnknownFailure(TestFailure):
48  pass
 48 def message(self):
 49 return ''
4950
5051 failure_obj = UnknownFailure()
5152 self.assertRaises(ValueError, determine_result_type, [failure_obj])
 53
 54 def test_message_is_virtual(self):
 55 failure_obj = TestFailure()
5256 self.assertRaises(NotImplementedError, failure_obj.message)
5357
5458 def test_loads(self):

Tools/Scripts/webkitpy/layout_tests/models/test_results.py

@@class TestResult(object):
3535 """Data object containing the results of a single test."""
3636
3737 @staticmethod
38  def loads(str):
39  return cPickle.loads(str)
 38 def loads(string):
 39 return cPickle.loads(string)
4040
4141 def __init__(self, test_name, failures=None, test_run_time=None, has_stderr=False):
4242 self.test_name = test_name

@@class TestResult(object):
5454 def __ne__(self, other):
5555 return not (self == other)
5656
57  def has_failure_matching_types(self, *args, **kargs):
 57 def has_failure_matching_types(self, *failure_classes):
5858 for failure in self.failures:
59  if type(failure) in args:
 59 if type(failure) in failure_classes:
6060 return True
6161 return False
6262

Tools/Scripts/webkitpy/pylintrc

@@load-plugins=
8585# W0141: Used builtin function ''
8686# W0212: Access to a protected member X of a client class
8787# W0142: Used * or ** magic
 88# W0401: Wildcard import X
8889# W0402: Uses of a deprecated module 'string'
8990# W0404: 41: Reimport 'XX' (imported line NN)
9091# W0511: TODO
9192# W0603: Using the global statement
 93# W0614: Unused import X from wildcard import
9294# W0703: Catch "Exception"
9395# W1201: Specify string format arguments as logging function parameters
94 disable=C0103,C0111,C0302,I0010,I0011,R0201,R0801,R0901,R0902,R0903,R0904,R0911,R0912,R0913,R0914,R0915,R0921,R0922,W0122,W0141,W0142,W0212,W0402,W0404,W0511,W0603,W0703,W1201
 96disable=C0103,C0111,C0302,I0010,I0011,R0201,R0801,R0901,R0902,R0903,R0904,R0911,R0912,R0913,R0914,R0915,R0921,R0922,W0122,W0141,W0142,W0212,W0401,W0402,W0404,W0511,W0603,W0614,W0703,W1201
9597
9698
9799[REPORTS]