-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_needrefacto.py
More file actions
62 lines (43 loc) · 1.22 KB
/
test_needrefacto.py
File metadata and controls
62 lines (43 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import pytest
import csonpath
def test_torefacto():
o = csonpath.CsonPath("$.a")
# breakpoint()
o = csonpath.CsonPath("$.a")
d = {"B": "Bh", "a": "le a"}
r = o.find_first(d)
assert r == "le a"
r = o.find_all(d)
assert r == ["le a"]
o = csonpath.CsonPath("$.C")
r = o.find_first(d)
assert r is None
o = csonpath.CsonPath("$.C", True)
r = o.find_first(d)
assert r is None
o = csonpath.CsonPath("$[*]")
r = o.find_all(d)
assert r == ["Bh", "le a"]
d = {"B": {"a": "true A"}, "a": "le a", "C": {"B": "not good", "a": "oh"}}
o = csonpath.CsonPath("$[*].a")
r = o.find_all(d)
assert(r != ["oh"])
o = csonpath.CsonPath("$..a")
r = o.find_all(d)
assert r == ["true A", "le a", "oh"]
o.remove(d)
assert d == {"B": {}, "C": {"B": "not good"}}
d["C"]["la"] = "lo"
o = csonpath.CsonPath("$.C[*]")
o.remove(d)
assert d == {"B": {}, "C": {}}
o = csonpath.CsonPath("$.C")
o.remove(d)
assert d == {"B": {}}
d["ar"] = [1, 2, 3]
o = csonpath.CsonPath("$.ar[1]")
o.remove(d)
assert d == {"B": {}, "ar": [1, 3]}
o = csonpath.CsonPath("$.ar[*]")
o.remove(d)
assert d == {"B": {}, "ar": []}