forked from Infinidat/munch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_yaml.py
39 lines (31 loc) · 1.39 KB
/
test_yaml.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
from munch import Munch
try:
import yaml
except ImportError:
yaml = None
def test_from_yaml():
data = yaml.load('''
Flow style: !munch.Munch { Clark: Evans, Brian: Ingerson, Oren: Ben-Kiki }
Block style: !munch
Clark : Evans
Brian : Ingerson
Oren : Ben-Kiki
''')
assert data == {
'Flow style': Munch(Brian='Ingerson', Clark='Evans', Oren='Ben-Kiki'),
'Block style': Munch(Brian='Ingerson', Clark='Evans', Oren='Ben-Kiki'),
}
def test_to_yaml_safe():
b = Munch(foo=['bar', Munch(lol=True)], hello=42)
dumped = yaml.safe_dump(b, default_flow_style=True)
assert dumped == '{foo: [bar, {lol: true}], hello: 42}\n'
def test_to_yaml():
b = Munch(foo=['bar', Munch(lol=True)], hello=42)
dumped = yaml.dump(b, default_flow_style=True)
assert dumped == '!munch.Munch {foo: [bar, !munch.Munch {lol: true}], hello: 42}\n'
def test_toYAML():
b = Munch(foo=['bar', Munch(lol=True)], hello=42)
assert yaml.safe_dump(b, default_flow_style=True) == '{foo: [bar, {lol: true}], hello: 42}\n'
assert b.toYAML(default_flow_style=True) == '{foo: [bar, {lol: true}], hello: 42}\n'
assert yaml.dump(b, default_flow_style=True) == '!munch.Munch {foo: [bar, !munch.Munch {lol: true}], hello: 42}\n'
assert b.toYAML(Dumper=yaml.Dumper, default_flow_style=True) == '!munch.Munch {foo: [bar, !munch.Munch {lol: true}], hello: 42}\n'