-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_utils.py
More file actions
59 lines (48 loc) · 1.24 KB
/
test_utils.py
File metadata and controls
59 lines (48 loc) · 1.24 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
from unittest import TestCase
from simple_schema_validator.utils import get_paths, set_nested
class UtilsTests(TestCase):
def test_get_paths(self):
data = {
'a': 1,
'b': {
'c': 2,
'd': {
'f': 3
}
}
}
paths = get_paths(data)
self.assertEqual(
{
'a': 1,
'b': {
'c': 2,
'd': {
'f': 3
}
},
'b.c': 2,
'b.d': {
'f': 3
},
'b.d.f': 3
},
paths
)
def test_set_nested(self):
value = 'foo'
data = {
'a': 1,
'b': {
'c': 2,
'd': {
'f': 3
}
}
}
with self.subTest('Setting on first level works'):
set_nested(data, 'a', value)
self.assertEqual(data['a'], value)
with self.subTest('Setting nested works'):
set_nested(data, 'b.d.f', value)
self.assertEqual(data['b']['d']['f'], value)