Skip to content

Commit 8e1ef65

Browse files
committed
update
1 parent 412b06d commit 8e1ef65

1 file changed

Lines changed: 86 additions & 34 deletions

File tree

tests/providers/test_common.py

Lines changed: 86 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -147,46 +147,98 @@ def test_complex_nested_structure(data, path, expected):
147147
assert result == expected
148148

149149

150-
def test_nested_wildcard_with_missing_intermediate():
151-
"""Test nested wildcard when intermediate path is missing"""
152-
data = {"groups": [{"users": [{"name": "Alice"}]}, {"other": "data"}]}
153-
result = get_path_value_from_dict("groups.*.users.*.name", data)
154-
assert result == ["Alice"]
150+
# Test data for edge cases with wildcards
151+
edge_case_wildcard_cases = [
152+
# Nested wildcard when intermediate path is missing
153+
({"groups": [{"users": [{"name": "Alice"}]}, {"other": "data"}]}, "groups.*.users.*.name", ["Alice"]),
154+
# Partial match with wildcard - some list items have the key and others don't
155+
({"items": [{"name": "Alice"}, {"other": "value"}, {"name": "Bob"}]}, "items.*.name", ["Alice", "Bob"]),
156+
]
155157

158+
# Test data for empty containers
159+
empty_container_cases = [
160+
({"users": []}, "users.*.name", False, []),
161+
({"users": {}}, "users.*.name", False, []),
162+
]
156163

157-
def test_partial_match_with_wildcard():
158-
"""Test when some list items have the key and others don't"""
159-
data = {"items": [{"name": "Alice"}, {"other": "value"}, {"name": "Bob"}]}
160-
result = get_path_value_from_dict("items.*.name", data)
161-
assert result == ["Alice", "Bob"]
164+
# Test data for empty containers with flag
165+
empty_container_with_flag_cases = [
166+
({"users": []}, "users.*.name", True, []),
167+
({"users": {}}, "users.*.name", True, []),
168+
]
162169

163170

164-
def test_empty_containers_default():
171+
@pytest.mark.parametrize("data,path,expected", edge_case_wildcard_cases)
172+
def test_edge_case_wildcards(data, path, expected):
173+
"""Test edge cases with wildcards like missing intermediate paths and partial matches"""
174+
result = get_path_value_from_dict(path, data)
175+
assert result == expected
176+
177+
178+
@pytest.mark.parametrize("data,path,flag,expected", empty_container_cases)
179+
def test_empty_containers(data, path, flag, expected):
165180
"""Test empty containers return empty list"""
166-
assert get_path_value_from_dict("users.*.name", {"users": []}) == []
167-
assert get_path_value_from_dict("users.*.name", {"users": {}}) == []
181+
result = get_path_value_from_dict(path, data, place_none_if_not_found=flag)
182+
assert result == expected
168183

169184

170-
def test_empty_containers_with_flag():
185+
@pytest.mark.parametrize("data,path,flag,expected", empty_container_with_flag_cases)
186+
def test_empty_containers_with_flag(data, path, flag, expected):
171187
"""Test empty containers with place_none_if_not_found flag"""
172188
# Empty containers don't trigger the flag since they exist but are empty
173-
assert get_path_value_from_dict("users.*.name", {"users": []}, place_none_if_not_found=True) == []
174-
assert get_path_value_from_dict("users.*.name", {"users": {}}, place_none_if_not_found=True) == []
175-
176-
177-
def test_wildcard_with_no_remaining_paths():
178-
"""Test wildcard at the end of path with no remaining paths - covers line 31-32"""
179-
# Test with list at root level - wildcard with no further paths should return all items
180-
data = [1, 2, 3, 4, 5]
181-
result = get_path_value_from_dict("*", data)
182-
assert result == [1, 2, 3, 4, 5]
183-
184-
# Test with list of dicts - wildcard with no further paths should return all dict items
185-
data2 = [{"name": "Alice"}, {"name": "Bob"}, {"name": "Charlie"}]
186-
result2 = get_path_value_from_dict("*", data2)
187-
assert result2 == [{"name": "Alice"}, {"name": "Bob"}, {"name": "Charlie"}]
188-
189-
# Test with nested list - get list then apply wildcard with no remaining paths
190-
data3 = {"items": [10, 20, 30]}
191-
result3 = get_path_value_from_dict("items.*", data3)
192-
assert result3 == [10, 20, 30]
189+
result = get_path_value_from_dict(path, data, place_none_if_not_found=flag)
190+
assert result == expected
191+
192+
193+
# Test data for wildcard with no remaining paths
194+
wildcard_list_no_remaining_cases = [
195+
([1, 2, 3, 4, 5], "*", [1, 2, 3, 4, 5]),
196+
(
197+
[{"name": "Alice"}, {"name": "Bob"}, {"name": "Charlie"}],
198+
"*",
199+
[{"name": "Alice"}, {"name": "Bob"}, {"name": "Charlie"}],
200+
),
201+
({"items": [10, 20, 30]}, "items.*", [10, 20, 30]),
202+
]
203+
204+
# Test data for wildcard dict with no remaining paths
205+
wildcard_dict_no_remaining_cases = [
206+
({"a": 1, "b": 2, "c": 3}, "*", {1, 2, 3}),
207+
({"config": {"x": 10, "y": 20, "z": 30}}, "config.*", {10, 20, 30}),
208+
(
209+
{"config": {"setting1": "value1", "setting2": "value2", "setting3": "value3"}},
210+
"config.*",
211+
{"value1", "value2", "value3"},
212+
),
213+
({"settings": {"enabled": True, "count": 42, "name": "test"}}, "settings.*", {True, 42, "test"}),
214+
({"items": {"x": 100, "y": "text", "z": True}}, "items.*", {100, "text", True}),
215+
]
216+
217+
# Test data for wildcard with primitive values
218+
wildcard_primitive_cases = [
219+
(42, "*", [42]),
220+
("hello", "*", ["hello"]),
221+
(True, "*", [True]),
222+
(None, "*", [None]),
223+
]
224+
225+
226+
@pytest.mark.parametrize("data,path,expected", wildcard_list_no_remaining_cases)
227+
def test_wildcard_list_no_remaining_paths(data, path, expected):
228+
"""Test wildcard at the end of path with list and no remaining paths - covers lines 31-32"""
229+
result = get_path_value_from_dict(path, data)
230+
assert result == expected
231+
232+
233+
@pytest.mark.parametrize("data,path,expected_set", wildcard_dict_no_remaining_cases)
234+
def test_wildcard_dict_no_remaining_paths(data, path, expected_set):
235+
"""Test wildcard at the end of path with dict and no remaining paths - covers lines 38-39"""
236+
result = get_path_value_from_dict(path, data)
237+
assert set(result) == expected_set
238+
239+
240+
@pytest.mark.parametrize("data,path,expected", wildcard_primitive_cases)
241+
def test_wildcard_primitive_no_remaining_paths(data, path, expected):
242+
"""Test wildcard applied to primitive value with no remaining paths - covers lines 42-43"""
243+
result = get_path_value_from_dict(path, data)
244+
assert result == expected

0 commit comments

Comments
 (0)