-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpodpora_patch.test.py
More file actions
91 lines (75 loc) · 1.92 KB
/
podpora_patch.test.py
File metadata and controls
91 lines (75 loc) · 1.92 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import warnings
import copy
from podpora_patch import apply_patch
warnings.filterwarnings("error")
def test(config, patch, expected):
cnf1 = copy.deepcopy(config)
cnf2 = copy.deepcopy(config)
print(expected)
try:
print(apply_patch(cnf1, patch))
print()
return apply_patch(cnf2, patch) == expected
except Exception as e:
print(e.__class__)
print()
return e.__class__ == expected
def main():
c1 = {
"b": 7,
"c": {
"d": 8,
"e": 9,
},
}
# Edit
assert test(c1, {"c": {"d": 3}}, {"b": 7, "c": {"d": 3, "e": 9}}), "Failed test 1"
# Overwrite with *
assert test(c1, {"c": {"*": {"d": 3}}}, {"b": 7, "c": {"d": 3}}), "Failed test 2"
c2 = {
"a": [
{
"_": "123456",
"b": 1,
},
{
"_": "654321",
"b": 2,
},
]
}
# Edit by serial
assert test(
c2,
{"a": {"123456": {"b": 3}}},
{"a": [{"_": "123456", "b": 3}, {"_": "654321", "b": 2}]},
), "Failed test 3"
# Edit by serial, serial not found
assert test(
c2,
{"a": {"999999": {"b": 3}}},
UserWarning,
), "Failed test 4"
# Overwrite by serial - can be used as addition
assert test(
c2,
{"a": {"999999": {"*": {"b": 3}}}},
{
"a": [
{"_": "123456", "b": 1},
{"_": "654321", "b": 2},
{"_": "999999", "b": 3},
]
},
), "Failed test 5"
c = {
"a": 1,
"b": 2,
"c": 3,
}
# Edit, nothing unusual
assert test(c, {"a": None}, {"a": None, "b": 2, "c": 3}), "Failed test 6"
# Special notation {"*": None} - delete key
assert test(c, {"a": {"*": None}}, {"b": 2, "c": 3}), "Failed test 7"
if __name__ == "__main__":
main()