-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_flat.py
More file actions
52 lines (43 loc) · 989 Bytes
/
test_flat.py
File metadata and controls
52 lines (43 loc) · 989 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
from flat import NestedDict, unflatten, flatten
def test_nested_dict():
d = NestedDict()
d['a']['b']['c'] = 2
assert d == {'a': {'b': {'c': 2}}}
def test_unflatten():
assert unflatten({
'a': 1,
'data.a': 2,
'data.data.a': 3,
}) == {
'a': 1,
'data': {
'a': 2,
'data': {
'a': 3,
}
}
}
def test_flatten():
assert flatten({
'a': 1,
'data': {
'a': 2,
'data': {
'a': 3,
}
}
}) == {
'a': 1,
'data.a': 2,
'data.data.a': 3,
}
def test_roundtrip():
data = {
'a.b.c': 3,
}
assert data == flatten(unflatten(data))
if __name__ == '__main__':
# The tests are written primarily to be run by py.test, but this lets one
# run them without it
for func in [v for k, v in globals().items() if k.startswith('test_')]:
func()