forked from dpath-maintainers/dpath-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_util_delete.py
More file actions
55 lines (42 loc) · 947 Bytes
/
test_util_delete.py
File metadata and controls
55 lines (42 loc) · 947 Bytes
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
from nose.tools import raises
import dpath.util
import dpath.exceptions
def test_delete_separator():
dict = {
"a": {
"b": 0,
},
}
dpath.util.delete(dict, ';a;b', separator=";")
assert('b' not in dict['a'])
def test_delete_existing():
dict = {
"a": {
"b": 0,
},
}
dpath.util.delete(dict, '/a/b')
assert('b' not in dict['a'])
@raises(dpath.exceptions.PathNotFound)
def test_delete_missing():
dict = {
"a": {
},
}
dpath.util.delete(dict, '/a/b')
def test_delete_filter():
def afilter(x):
if int(x) == 31:
return True
return False
dict = {
"a": {
"b": 0,
"c": 1,
"d": 31,
},
}
dpath.util.delete(dict, '/a/*', afilter=afilter)
assert (dict['a']['b'] == 0)
assert (dict['a']['c'] == 1)
assert ('d' not in dict['a'])