Move free functions in test_expectations to TestExpectations class
authorrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 21 Aug 2012 18:10:22 +0000 (18:10 +0000)
committerrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 21 Aug 2012 18:10:22 +0000 (18:10 +0000)
https://bugs.webkit.org/show_bug.cgi?id=94557

Reviewed by Dirk Pranke.

Moved test_result_was_expected, test_remove_pixel_failures, and test_suffixes_for_expectations into TestExpectations
to allow further refactoring.

* Scripts/webkitpy/common/net/resultsjsonparser.py:
(JSONTestResult.did_run_as_expected):
(JSONTestResult._tokenize):
* Scripts/webkitpy/layout_tests/models/test_expectations.py:
(TestExpectations):
(TestExpectations.result_was_expected):
(TestExpectations.remove_pixel_failures):
(TestExpectations.has_pixel_failures):
(TestExpectations.suffixes_for_expectations):
(TestExpectations.matches_an_expected_result):
* Scripts/webkitpy/layout_tests/models/test_expectations_unittest.py:
(MockBugManager.create_bug):
(test_result_was_expected):
(test_remove_pixel_failures):
(test_suffixes_for_expectations):
* Scripts/webkitpy/tool/commands/rebaseline.py:
(RebaselineExpectations._tests_to_rebaseline):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@126176 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Tools/ChangeLog
Tools/Scripts/webkitpy/common/net/resultsjsonparser.py
Tools/Scripts/webkitpy/layout_tests/models/test_expectations.py
Tools/Scripts/webkitpy/layout_tests/models/test_expectations_unittest.py
Tools/Scripts/webkitpy/tool/commands/rebaseline.py

index a3cb05b..0efc436 100644 (file)
@@ -1,3 +1,31 @@
+2012-08-20  Ryosuke Niwa  <rniwa@webkit.org>
+
+        Move free functions in test_expectations to TestExpectations class
+        https://bugs.webkit.org/show_bug.cgi?id=94557
+
+        Reviewed by Dirk Pranke.
+
+        Moved test_result_was_expected, test_remove_pixel_failures, and test_suffixes_for_expectations into TestExpectations
+        to allow further refactoring.
+
+        * Scripts/webkitpy/common/net/resultsjsonparser.py:
+        (JSONTestResult.did_run_as_expected):
+        (JSONTestResult._tokenize):
+        * Scripts/webkitpy/layout_tests/models/test_expectations.py:
+        (TestExpectations):
+        (TestExpectations.result_was_expected):
+        (TestExpectations.remove_pixel_failures):
+        (TestExpectations.has_pixel_failures):
+        (TestExpectations.suffixes_for_expectations):
+        (TestExpectations.matches_an_expected_result):
+        * Scripts/webkitpy/layout_tests/models/test_expectations_unittest.py:
+        (MockBugManager.create_bug):
+        (test_result_was_expected):
+        (test_remove_pixel_failures):
+        (test_suffixes_for_expectations):
+        * Scripts/webkitpy/tool/commands/rebaseline.py:
+        (RebaselineExpectations._tests_to_rebaseline):
+
 2012-08-21  Simon Hausmann  <simon.hausmann@nokia.com>
 
         Unreviewed build fix for newer Qt 5: The meaning of private_includes changed to be fully
index 99e8528..d30ad55 100644 (file)
@@ -34,6 +34,7 @@ from webkitpy.common.system.deprecated_logging import log
 # FIXME: common should never import from new-run-webkit-tests, one of these files needs to move.
 from webkitpy.layout_tests.layout_package import json_results_generator
 from webkitpy.layout_tests.models import test_expectations, test_results, test_failures
+from webkitpy.layout_tests.models.test_expectations import TestExpectations
 
 
 # These are helper functions for navigating the results json structure.
@@ -72,15 +73,15 @@ class JSONTestResult(object):
         expected_results = self._expected_as_tokens()
         # FIXME: We should only call remove_pixel_failures when this JSONResult
         # came from a test run without pixel tests!
-        if not test_expectations.has_pixel_failures(actual_results):
-            expected_results = test_expectations.remove_pixel_failures(expected_results)
+        if not TestExpectations.has_pixel_failures(actual_results):
+            expected_results = TestExpectations.remove_pixel_failures(expected_results)
         for actual_result in actual_results:
-            if not test_expectations.result_was_expected(actual_result, expected_results, False, False):
+            if not TestExpectations.result_was_expected(actual_result, expected_results, False, False):
                 return False
         return True
 
     def _tokenize(self, results_string):
-        tokens = map(test_expectations.TestExpectations.expectation_from_string, results_string.split(' '))
+        tokens = map(TestExpectations.expectation_from_string, results_string.split(' '))
         if None in tokens:
             log("Unrecognized result in %s" % results_string)
         return set(tokens)
index d3015db..aa946fd 100644 (file)
@@ -45,57 +45,10 @@ _log = logging.getLogger(__name__)
 (PASS, FAIL, TEXT, IMAGE, IMAGE_PLUS_TEXT, AUDIO, TIMEOUT, CRASH, SKIP, WONTFIX,
  SLOW, REBASELINE, MISSING, FLAKY, NOW, NONE) = range(16)
 
-
-def result_was_expected(result, expected_results, test_needs_rebaselining, test_is_skipped):
-    """Returns whether we got a result we were expecting.
-    Args:
-        result: actual result of a test execution
-        expected_results: set of results listed in test_expectations
-        test_needs_rebaselining: whether test was marked as REBASELINE
-        test_is_skipped: whether test was marked as SKIP"""
-    if result in expected_results:
-        return True
-    if result == MISSING and test_needs_rebaselining:
-        return True
-    if result == SKIP and test_is_skipped:
-        return True
-    return False
-
-
-def remove_pixel_failures(expected_results):
-    """Returns a copy of the expected results for a test, except that we
-    drop any pixel failures and return the remaining expectations. For example,
-    if we're not running pixel tests, then tests expected to fail as IMAGE
-    will PASS."""
-    expected_results = expected_results.copy()
-    if IMAGE in expected_results:
-        expected_results.remove(IMAGE)
-        expected_results.add(PASS)
-    if IMAGE_PLUS_TEXT in expected_results:
-        expected_results.remove(IMAGE_PLUS_TEXT)
-        expected_results.add(TEXT)
-    return expected_results
-
-
-def has_pixel_failures(actual_results):
-    return IMAGE in actual_results or IMAGE_PLUS_TEXT in actual_results
-
-
 # FIXME: Perhas these two routines should be part of the Port instead?
 BASELINE_SUFFIX_LIST = ('png', 'wav', 'txt')
 
 
-def suffixes_for_expectations(expectations):
-    suffixes = set()
-    if expectations.intersection(set([TEXT, IMAGE_PLUS_TEXT])):
-        suffixes.add('txt')
-    if expectations.intersection(set([IMAGE, IMAGE_PLUS_TEXT])):
-        suffixes.add('png')
-    if AUDIO in expectations:
-        suffixes.add('wav')
-    return set(suffixes)
-
-
 class ParseError(Exception):
     def __init__(self, warnings):
         super(ParseError, self).__init__()
@@ -718,6 +671,52 @@ class TestExpectations(object):
         assert(' ' not in string)  # This only handles one expectation at a time.
         return cls.EXPECTATIONS.get(string.lower())
 
+    @staticmethod
+    def result_was_expected(result, expected_results, test_needs_rebaselining, test_is_skipped):
+        """Returns whether we got a result we were expecting.
+        Args:
+            result: actual result of a test execution
+            expected_results: set of results listed in test_expectations
+            test_needs_rebaselining: whether test was marked as REBASELINE
+            test_is_skipped: whether test was marked as SKIP"""
+        if result in expected_results:
+            return True
+        if result == MISSING and test_needs_rebaselining:
+            return True
+        if result == SKIP and test_is_skipped:
+            return True
+        return False
+
+    @staticmethod
+    def remove_pixel_failures(expected_results):
+        """Returns a copy of the expected results for a test, except that we
+        drop any pixel failures and return the remaining expectations. For example,
+        if we're not running pixel tests, then tests expected to fail as IMAGE
+        will PASS."""
+        expected_results = expected_results.copy()
+        if IMAGE in expected_results:
+            expected_results.remove(IMAGE)
+            expected_results.add(PASS)
+        if IMAGE_PLUS_TEXT in expected_results:
+            expected_results.remove(IMAGE_PLUS_TEXT)
+            expected_results.add(TEXT)
+        return expected_results
+
+    @staticmethod
+    def has_pixel_failures(actual_results):
+        return IMAGE in actual_results or IMAGE_PLUS_TEXT in actual_results
+
+    @staticmethod
+    def suffixes_for_expectations(expectations):
+        suffixes = set()
+        if expectations.intersection(set([TEXT, IMAGE_PLUS_TEXT])):
+            suffixes.add('txt')
+        if expectations.intersection(set([IMAGE, IMAGE_PLUS_TEXT])):
+            suffixes.add('png')
+        if AUDIO in expectations:
+            suffixes.add('wav')
+        return set(suffixes)
+
     def __init__(self, port, tests=None, is_lint_mode=False, include_overrides=True):
         self._full_test_list = tests
         self._test_config = port.test_configuration()
@@ -788,8 +787,8 @@ class TestExpectations(object):
     def matches_an_expected_result(self, test, result, pixel_tests_are_enabled):
         expected_results = self._model.get_expectations(test)
         if not pixel_tests_are_enabled:
-            expected_results = remove_pixel_failures(expected_results)
-        return result_was_expected(result,
+            expected_results = self.remove_pixel_failures(expected_results)
+        return self.result_was_expected(result,
                                    expected_results,
                                    self.is_rebaselining(test),
                                    self._model.has_modifier(test, SKIP))
index 9fc1183..a95bdb4 100644 (file)
@@ -50,47 +50,6 @@ class MockBugManager(object):
         return "BUG_NEWLY_CREATED"
 
 
-class FunctionsTest(unittest.TestCase):
-    def test_result_was_expected(self):
-        # test basics
-        self.assertEquals(result_was_expected(PASS, set([PASS]),
-                                              False, False), True)
-        self.assertEquals(result_was_expected(TEXT, set([PASS]),
-                                              False, False), False)
-
-        # test handling of SKIPped tests and results
-        self.assertEquals(result_was_expected(SKIP, set([CRASH]),
-                                              False, True), True)
-        self.assertEquals(result_was_expected(SKIP, set([CRASH]),
-                                              False, False), False)
-
-        # test handling of MISSING results and the REBASELINE modifier
-        self.assertEquals(result_was_expected(MISSING, set([PASS]),
-                                              True, False), True)
-        self.assertEquals(result_was_expected(MISSING, set([PASS]),
-                                              False, False), False)
-
-    def test_remove_pixel_failures(self):
-        self.assertEquals(remove_pixel_failures(set([TEXT])),
-                          set([TEXT]))
-        self.assertEquals(remove_pixel_failures(set([PASS])),
-                          set([PASS]))
-        self.assertEquals(remove_pixel_failures(set([IMAGE])),
-                          set([PASS]))
-        self.assertEquals(remove_pixel_failures(set([IMAGE_PLUS_TEXT])),
-                          set([TEXT]))
-        self.assertEquals(remove_pixel_failures(set([PASS, IMAGE, CRASH])),
-                          set([PASS, CRASH]))
-
-    def test_suffixes_for_expectations(self):
-        self.assertEquals(suffixes_for_expectations(set([TEXT])), set(['txt']))
-        self.assertEquals(suffixes_for_expectations(set([IMAGE_PLUS_TEXT])), set(['txt', 'png']))
-        self.assertEquals(suffixes_for_expectations(set([IMAGE])), set(['png']))
-        self.assertEquals(suffixes_for_expectations(set([AUDIO])), set(['wav']))
-        self.assertEquals(suffixes_for_expectations(set([TEXT, IMAGE, CRASH])), set(['txt', 'png']))
-        self.assertEquals(suffixes_for_expectations(set()), set())
-
-
 class Base(unittest.TestCase):
     # Note that all of these tests are written assuming the configuration
     # being tested is Windows XP, Release build.
@@ -137,6 +96,34 @@ BUG_TEST WONTFIX MAC : failures/expected/image.html = IMAGE
     def assert_bad_expectations(self, expectations, overrides=None):
         self.assertRaises(ParseError, self.parse_exp, expectations, is_lint_mode=True, overrides=overrides)
 
+    def test_result_was_expected(self):
+        # test basics
+        self.assertEquals(TestExpectations.result_was_expected(PASS, set([PASS]), test_needs_rebaselining=False, test_is_skipped=False), True)
+        self.assertEquals(TestExpectations.result_was_expected(TEXT, set([PASS]), test_needs_rebaselining=False, test_is_skipped=False), False)
+
+        # test handling of SKIPped tests and results
+        self.assertEquals(TestExpectations.result_was_expected(SKIP, set([CRASH]), test_needs_rebaselining=False, test_is_skipped=True), True)
+        self.assertEquals(TestExpectations.result_was_expected(SKIP, set([CRASH]), test_needs_rebaselining=False, test_is_skipped=False), False)
+
+        # test handling of MISSING results and the REBASELINE modifier
+        self.assertEquals(TestExpectations.result_was_expected(MISSING, set([PASS]), test_needs_rebaselining=True, test_is_skipped=False), True)
+        self.assertEquals(TestExpectations.result_was_expected(MISSING, set([PASS]), test_needs_rebaselining=False, test_is_skipped=False), False)
+
+    def test_remove_pixel_failures(self):
+        self.assertEquals(TestExpectations.remove_pixel_failures(set([TEXT])), set([TEXT]))
+        self.assertEquals(TestExpectations.remove_pixel_failures(set([PASS])), set([PASS]))
+        self.assertEquals(TestExpectations.remove_pixel_failures(set([IMAGE])), set([PASS]))
+        self.assertEquals(TestExpectations.remove_pixel_failures(set([IMAGE_PLUS_TEXT])), set([TEXT]))
+        self.assertEquals(TestExpectations.remove_pixel_failures(set([PASS, IMAGE, CRASH])), set([PASS, CRASH]))
+
+    def test_suffixes_for_expectations(self):
+        self.assertEquals(TestExpectations.suffixes_for_expectations(set([TEXT])), set(['txt']))
+        self.assertEquals(TestExpectations.suffixes_for_expectations(set([IMAGE_PLUS_TEXT])), set(['txt', 'png']))
+        self.assertEquals(TestExpectations.suffixes_for_expectations(set([IMAGE])), set(['png']))
+        self.assertEquals(TestExpectations.suffixes_for_expectations(set([AUDIO])), set(['wav']))
+        self.assertEquals(TestExpectations.suffixes_for_expectations(set([TEXT, IMAGE, CRASH])), set(['txt', 'png']))
+        self.assertEquals(TestExpectations.suffixes_for_expectations(set()), set())
+
 
 class BasicTests(Base):
     def test_basic(self):
index 7ccbf56..63de323 100644 (file)
@@ -44,7 +44,7 @@ from webkitpy.common.system.user import User
 from webkitpy.layout_tests.controllers.test_result_writer import TestResultWriter
 from webkitpy.layout_tests.models import test_failures
 from webkitpy.layout_tests.models.test_configuration import TestConfiguration
-from webkitpy.layout_tests.models.test_expectations import TestExpectations, suffixes_for_expectations, BASELINE_SUFFIX_LIST
+from webkitpy.layout_tests.models.test_expectations import TestExpectations, BASELINE_SUFFIX_LIST
 from webkitpy.layout_tests.port import builders
 from webkitpy.tool.grammar import pluralize
 from webkitpy.tool.multicommandtool import AbstractDeclarativeCommand
@@ -333,7 +333,7 @@ class RebaselineExpectations(AbstractParallelRebaselineCommand):
         tests_to_rebaseline = {}
         expectations = TestExpectations(port, include_overrides=True)
         for test in expectations.get_rebaselining_failures():
-            tests_to_rebaseline[test] = suffixes_for_expectations(expectations.get_expectations(test))
+            tests_to_rebaseline[test] = TestExpectations.suffixes_for_expectations(expectations.get_expectations(test))
         return tests_to_rebaseline
 
     def _add_tests_to_rebaseline_for_port(self, port_name):