|
1 | 1 | from __future__ import annotations
|
2 | 2 |
|
3 | 3 | import dataclasses
|
| 4 | +import re |
4 | 5 | import typing as t
|
5 | 6 | from collections.abc import Callable, Mapping
|
6 | 7 | from contextlib import suppress
|
@@ -982,3 +983,55 @@ def __eq__(self, other: object) -> bool:
|
982 | 983 | ql1 = QueryList[int]([1, 2, 3])
|
983 | 984 | ql2 = QueryList[int]([3, 2, 1])
|
984 | 985 | assert ql1 != ql2 # Order matters
|
| 986 | + |
| 987 | + |
| 988 | +def test_lookup_functions_deep_matching() -> None: |
| 989 | + """Test deep matching behavior in lookup functions.""" |
| 990 | + # Test lookup_in with deep dictionary matching |
| 991 | + data: dict[str, t.Any] = {"a": {"b": {"c": "value"}}} |
| 992 | + rhs: dict[str, t.Any] = {"b": {"c": "value"}} |
| 993 | + # Deep dictionary matching not implemented yet |
| 994 | + assert not lookup_in(data, rhs) |
| 995 | + |
| 996 | + # Test lookup_nin with deep dictionary matching |
| 997 | + # Deep dictionary matching not implemented yet |
| 998 | + assert not lookup_nin(data, rhs) |
| 999 | + |
| 1000 | + # Test lookup_in with pattern matching |
| 1001 | + pattern = re.compile(r"test\d+") |
| 1002 | + assert not lookup_in("test123", pattern) # Pattern matching not implemented yet |
| 1003 | + assert not lookup_nin("test123", pattern) # Pattern matching not implemented yet |
| 1004 | + |
| 1005 | + # Test lookup_in with mixed types in list |
| 1006 | + mixed_list: list[str] = ["string", "123", "key:value"] # Convert to string list |
| 1007 | + # String in list returns True |
| 1008 | + assert lookup_in("key:value", mixed_list) |
| 1009 | + # String not in list returns True for nin |
| 1010 | + assert lookup_nin("other:value", mixed_list) |
| 1011 | + |
| 1012 | + # Test invalid type combinations return False |
| 1013 | + invalid_obj = {"key": "123"} # type: dict[str, str] # Valid type but invalid content |
| 1014 | + assert lookup_in(invalid_obj, "test") is False # Invalid usage but valid types |
| 1015 | + assert lookup_in("test", invalid_obj) is False # Invalid usage but valid types |
| 1016 | + |
| 1017 | + |
| 1018 | +def test_parse_lookup_error_cases() -> None: |
| 1019 | + """Test error cases in parse_lookup function.""" |
| 1020 | + # Test with invalid path type |
| 1021 | + obj = {"field": "value"} |
| 1022 | + assert parse_lookup(obj, 123, "__contains") is None # type: ignore |
| 1023 | + |
| 1024 | + # Test with invalid lookup type |
| 1025 | + assert parse_lookup(obj, "field", 123) is None # type: ignore |
| 1026 | + |
| 1027 | + # Test with path not ending in lookup |
| 1028 | + assert parse_lookup(obj, "field", "__contains") is None |
| 1029 | + |
| 1030 | + # Test with empty field name after rsplit |
| 1031 | + assert parse_lookup(obj, "__contains", "__contains") is None |
| 1032 | + |
| 1033 | + # Test with invalid object type |
| 1034 | + assert parse_lookup(None, "field", "__contains") is None # type: ignore |
| 1035 | + |
| 1036 | + # Test with path containing invalid characters |
| 1037 | + assert parse_lookup(obj, "field\x00", "__contains") is None |
0 commit comments