⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 268811 in webkit


Ignore:
Timestamp:
Oct 21, 2020, 11:33:17 AM (6 years ago)
Author:
Lauro Moura
Message:

webkitpy: Check for duplicated keys in json expectation files
https://bugs.webkit.org/show_bug.cgi?id=218032

Reviewed by Carlos Alberto Lopez Perez.

Tools:

When JSON contains repeated keys, Python only uses the last key/value
pair in the resulting dict, without warnings. This may cause some
expectations to be ignored, like what r267323 fixed.

This change also makes MockTestExpectations use the same loading
validation as the actual expectation instead of calling json.loads
directly.

  • Scripts/webkitpy/common/test_expectations.py:

(check_repeated_keys): Added.
(TestExpectations.init): Use helper function.
(TestExpectations._load_expectation_string): Moved validation here.

  • Scripts/webkitpy/common/test_expectations_unittest.py:

(MockTestExpectations.init): Use helper function.
(test_repeated_keys): Added test when there are repeated keys.

WebDriverTests:

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r268796 r268811  
     12020-10-21  Lauro Moura  <lmoura@igalia.com>
     2
     3        webkitpy: Check for duplicated keys in json expectation files
     4        https://bugs.webkit.org/show_bug.cgi?id=218032
     5
     6        Reviewed by Carlos Alberto Lopez Perez.
     7
     8        When JSON contains repeated keys, Python only uses the last key/value
     9        pair in the resulting dict, without warnings. This may cause some
     10        expectations to be ignored, like what r267323 fixed.
     11
     12        This change also makes MockTestExpectations use the same loading
     13        validation as the actual expectation instead of calling json.loads
     14        directly.
     15
     16        * Scripts/webkitpy/common/test_expectations.py:
     17        (check_repeated_keys): Added.
     18        (TestExpectations.__init__): Use helper function.
     19        (TestExpectations._load_expectation_string): Moved validation here.
     20        * Scripts/webkitpy/common/test_expectations_unittest.py:
     21        (MockTestExpectations.__init__): Use helper function.
     22        (test_repeated_keys): Added test when there are repeated keys.
     23
    1242020-10-21  Alex Christensen  <achristensen@webkit.org>
    225
  • trunk/Tools/Scripts/webkitpy/common/test_expectations.py

    r226944 r268811  
    2525
    2626
     27def check_repeated_keys(args):
     28    seen = {}
     29    for key, val in args:
     30        if key in seen:
     31            raise ValueError("Key %s appears more than once" % key)
     32        else:
     33            seen[key] = val
     34
     35    return seen
     36
     37
    2738class TestExpectations(object):
    2839
     
    3243        if os.path.isfile(expectations_file):
    3344            with open(expectations_file, 'r') as fd:
    34                 self._expectations = json.load(fd)
     45                self._expectations = self._load_expectation_string(fd.read())
    3546        else:
    3647            self._expectations = {}
     48
     49    def _load_expectation_string(self, expectations):
     50        return json.loads(expectations, object_pairs_hook=check_repeated_keys)
    3751
    3852    def _port_name_for_expected(self, expected):
  • trunk/Tools/Scripts/webkitpy/common/test_expectations_unittest.py

    r227406 r268811  
    3838        self._port_name = port.name()
    3939        self._build_type = build_type
    40         self._expectations = json.loads(expectations)
     40        self._expectations = self._load_expectation_string(expectations)
    4141
    4242    def is_skip(self, test, subtest):
     
    183183            }
    184184        }
     185    }
     186}"""
     187
     188    REPEATED_KEYS = """
     189{
     190    "TestDummy": {
     191        "a": 1
     192    },
     193    "TestAnother": {
     194    },
     195    "TestDummy": {
     196        "a": 2
    185197    }
    186198}"""
     
    294306        self.assert_slow('TestWebKit', 'WebKit.MouseMoveAfterCrash', True)
    295307        self.assert_slow('TestWebKit', 'WebKit.WKConnection', False)
     308
     309    def test_repeated_keys(self):
     310        self.assertRaises(ValueError, lambda: MockTestExpectations('gtk', self.REPEATED_KEYS))
  • trunk/WebDriverTests/ChangeLog

    r268793 r268811  
     12020-10-21  Lauro Moura  <lmoura@igalia.com>
     2
     3        webkitpy: Check for duplicated keys in json expectation files
     4        https://bugs.webkit.org/show_bug.cgi?id=218032
     5
     6        Reviewed by Carlos Alberto Lopez Perez.
     7
     8        * TestExpectations.json: Fix duplicated test key.
     9
    1102020-10-21  Carlos Garcia Campos  <cgarcia@igalia.com>
    211
  • trunk/WebDriverTests/TestExpectations.json

    r268793 r268811  
    515515            "test_duplicated_cookie": {
    516516                "expected": {"all": {"status": ["FAIL"], "bug": "webkit.org/b/182330"}}
     517            },
     518            "test_no_top_browsing_context": {
     519                "expected": {"wpe": {"status": ["FAIL"], "bug": "webkit.org/b/212950"}}
     520            },
     521            "test_no_browsing_context": {
     522                "expected": {"wpe": {"status": ["FAIL"], "bug": "webkit.org/b/212950"}}
    517523            }
    518524        }
     
    924930
    925931    "imported/w3c/webdriver/tests/get_element_text/get.py": {
    926         "subtests": {
    927             "test_no_top_browsing_context": {
    928                 "expected": {"wpe": {"status": ["FAIL"], "bug": "webkit.org/b/212950"}}
    929             },
    930             "test_no_browsing_context": {
    931                 "expected": {"wpe": {"status": ["FAIL"], "bug": "webkit.org/b/212950"}}
    932             }
    933         }
    934     },
    935 
    936     "imported/w3c/webdriver/tests/get_named_cookie/get.py": {
    937932        "subtests": {
    938933            "test_no_top_browsing_context": {
Note: See TracChangeset for help on using the changeset viewer.