def test_match_dict(self): self.assertEqual(match_dict({ 'a': _, 'b': 2 }, { 'a': 1, 'b': 2 }), (True, [1]))
def test_match_dict_ordering(self): for i in range(100): self.assertEqual(match_dict({ 'a': _, 'b': _ }, { 'a': 1, 'b': 2 }), (True, [1, 2]))
def test_match_asymmetric(self): self.assertEqual( match_dict({ 'a': _, 'b': 2 }, { 'a': 1, 'b': 2, 'c': 3 }), (True, [1])) self.assertEqual( match_dict({ 'a': _, 'b': 2, 'c': 3 }, { 'a': 1, 'b': 2 }), (False, []))
def test_match_nested(self): self.assertEqual( match_dict({ 'a': { 'b': _ }, 'c': _ }, { 'a': { 'b': 1 }, 'c': 2 }), (True, [1, 2]))
def test_multi_underscore_ambiguous(self): for i in range(20): self.assertEqual( match_dict({ "a": _, _: int }, { "a": 1, "b": 2, "c": 3 }), (True, [1, "b", 2])) self.assertEqual( match_dict({ "type": _, _: str }, { "type": "pet", "cat-name": "bonney", "info": { "age": 1 } }), (True, ["pet", "cat-name", "bonney"]))
def test_exclude_previously_used_keys(self): x = {"a": 1, "b": 2} self.assertEqual(match_dict({"a": _, _: _}, x), (True, [1, "b", 2])) self.assertEqual(match_dict({"a": _, _: int}, x), (True, [1, "b", 2])) self.assertEqual(match_dict({"a": _, _: int}, x), (True, [1, "b", 2]))