Skip to content

Commit cbed5f1

Browse files
committed
Add type check tests
Thanks to @harel
1 parent 58b34df commit cbed5f1

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

tests/test_new.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,27 @@ def test_set_list_with_dict_int_ambiguity():
5252
assert d == expected
5353

5454

55+
def test_int_segment_list_type_check():
56+
d = {}
57+
dpath.new(d, "a/b/0/c/0", "hello")
58+
assert 'b' in d.get("a", {})
59+
assert isinstance(d["a"]["b"], list)
60+
assert len(d["a"]["b"]) == 1
61+
assert 'c' in d["a"]["b"][0]
62+
assert isinstance(d["a"]["b"][0]["c"], list)
63+
assert len(d["a"]["b"][0]["c"]) == 1
64+
65+
66+
def test_int_segment_dict_type_check():
67+
d = {"a": {"b": {"0": {}}}}
68+
dpath.new(d, "a/b/0/c/0", "hello")
69+
assert "b" in d.get("a", {})
70+
assert isinstance(d["a"]["b"], dict)
71+
assert '0' in d["a"]["b"]
72+
assert 'c' in d["a"]["b"]["0"]
73+
assert isinstance(d["a"]["b"]["0"]["c"], list)
74+
75+
5576
def test_set_new_list_path_with_separator():
5677
# This test kills many birds with one stone, forgive me
5778
dict = {

0 commit comments

Comments
 (0)