-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathtest_merge.py
56 lines (43 loc) · 1.06 KB
/
test_merge.py
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
import pytest
from pymlconf import Root, Mergable
class TestMerge:
def test_merge_empty_object(self):
root = Root()
root.merge('')
assert len(root.keys()) == 0
def test_merge_errors(self):
root = Root()
with pytest.raises(TypeError):
root.merge(None)
def test_merge_deep_object(self):
root = Root()
root.merge('''
a:
b:
c: 3
''')
assert root.a.b.c == 3
root.merge('''
d:
e: 1
''')
assert isinstance(root.d, Mergable)
root.d.merge(root.a)
assert root.d.b.c == 3
root.a.b = 2
assert root.a.b == 2
assert root.d.b.c == 3
def test_merge_list(self):
root = Root()
root.merge('''
a:
b:
- 1
- 2
c: []
''')
assert root.a.b == [1, 2]
root.c.merge(root.a.b.copy())
root.a.b.append(3)
assert root.a.b == [1, 2, 3]
assert root.c == [1, 2]