forked from dpath-maintainers/dpath-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_util_get_values.py
More file actions
89 lines (82 loc) · 2.29 KB
/
test_util_get_values.py
File metadata and controls
89 lines (82 loc) · 2.29 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
import nose
from nose.tools import assert_raises
import dpath.util
import mock
def test_get_explicit_single():
ehash = {
"a": {
"b": {
"c": {
"d": 0,
"e": 1,
"f": 2
}
}
}
}
assert(dpath.util.get(ehash, '/a/b/c/f') == 2)
assert(dpath.util.get(ehash, ['a', 'b', 'c', 'f']) == 2)
def test_get_glob_single():
ehash = {
"a": {
"b": {
"c": {
"d": 0,
"e": 1,
"f": 2
}
}
}
}
assert(dpath.util.get(ehash, '/a/b/*/f') == 2)
assert(dpath.util.get(ehash, ['a', 'b', '*', 'f']) == 2)
def test_get_glob_multiple():
ehash = {
"a": {
"b": {
"c": {
"d": 0
},
"e": {
"d": 0
}
}
}
}
assert_raises(ValueError, dpath.util.get, ehash, '/a/b/*/d')
assert_raises(ValueError, dpath.util.get, ehash, ['a', 'b', '*', 'd'])
def test_get_absent():
ehash = {}
assert_raises(KeyError, dpath.util.get, ehash, '/a/b/c/d/f')
assert_raises(KeyError, dpath.util.get, ehash, ['a', 'b', 'c', 'd', 'f'])
def test_values():
ehash = {
"a": {
"b": {
"c": {
"d": 0,
"e": 1,
"f": 2
}
}
}
}
ret = dpath.util.values(ehash, '/a/b/c/*')
assert(isinstance(ret, list))
assert(0 in ret)
assert(1 in ret)
assert(2 in ret)
ret = dpath.util.values(ehash, ['a', 'b', 'c', '*'])
assert(isinstance(ret, list))
assert(0 in ret)
assert(1 in ret)
assert(2 in ret)
@mock.patch('dpath.util.search')
def test_values_passes_through(searchfunc):
searchfunc.return_value = []
def y():
pass
dpath.util.values({}, '/a/b', ':', y, False)
searchfunc.assert_called_with({}, '/a/b', dirs=False, yielded=True, separator=':', afilter=y)
dpath.util.values({}, ['a', 'b'], ':', y, False)
searchfunc.assert_called_with({}, ['a', 'b'], dirs=False, yielded=True, separator=':', afilter=y)