1
|
|
|
# |
2
|
|
|
# Copyright (C) 2012 - 2018 Satoru SATOH <ssato @ redhat.com> |
3
|
|
|
# Copyright (C) 2017 Red Hat, Inc. |
4
|
|
|
# License: MIT |
5
|
|
|
# |
6
|
|
|
# pylint: disable=missing-docstring,invalid-name,too-few-public-methods |
7
|
|
|
# pylint: disable=ungrouped-imports |
8
|
|
|
from __future__ import absolute_import |
9
|
|
|
|
10
|
|
|
import os |
11
|
|
|
import anyconfig.backend.yaml as TT |
12
|
|
|
import tests.backend.common as TBC |
13
|
|
|
|
14
|
|
|
from anyconfig.compat import OrderedDict |
15
|
|
|
|
16
|
|
|
|
17
|
|
|
CNF_S = """ |
18
|
|
|
a: 0 |
19
|
|
|
b: bbb |
20
|
|
|
c: |
21
|
|
|
- 1 |
22
|
|
|
- 2 |
23
|
|
|
- 3 |
24
|
|
|
|
25
|
|
|
sect0: §0 |
26
|
|
|
d: ["x", "y", "z"] |
27
|
|
|
sect1: |
28
|
|
|
<<: *sect0 |
29
|
|
|
e: true |
30
|
|
|
""" |
31
|
|
|
|
32
|
|
|
CNF = OrderedDict((("a", 0), ("b", "bbb"), ("c", [1, 2, 3]), |
33
|
|
|
("sect0", OrderedDict((("d", "x y z".split()), ))), |
34
|
|
|
("sect1", OrderedDict((("d", "x y z".split()), |
35
|
|
|
("e", True)))))) |
36
|
|
|
|
37
|
|
|
|
38
|
|
|
class HasParserTrait(TBC.HasParserTrait): |
39
|
|
|
|
40
|
|
|
psr = TT.Parser() |
41
|
|
|
cnf = CNF |
42
|
|
|
cnf_s = CNF_S |
43
|
|
|
|
44
|
|
|
|
45
|
|
|
class Test_10(TBC.Test_10_dumps_and_loads, HasParserTrait): |
46
|
|
|
|
47
|
|
|
load_options = dict(ac_safe=True, Loader=TT.yaml.loader.Loader) |
48
|
|
|
dump_options = dict(ac_safe=True) |
49
|
|
|
empty_patterns = ['', ' ', "#%s#%s" % (os.linesep, os.linesep)] |
50
|
|
|
|
51
|
|
|
|
52
|
|
View Code Duplication |
class Test_20(TBC.Test_20_dump_and_load, HasParserTrait): |
|
|
|
|
53
|
|
|
|
54
|
|
|
def test_18_load__list(self): |
55
|
|
|
if self.is_ready(): |
56
|
|
|
# overwrite it. |
57
|
|
|
with self.psr.wopen(self.cnf_path) as out: |
58
|
|
|
out.write("- 1\n- 2\n") |
59
|
|
|
|
60
|
|
|
ioi = self._to_ioinfo(self.cnf_path) |
61
|
|
|
|
62
|
|
|
cnf = self.psr.load(ioi) |
63
|
|
|
self.assertTrue(cnf) |
64
|
|
|
self.assertEqual(cnf, [1, 2]) |
65
|
|
|
|
66
|
|
|
def test_19_load__nested_list(self): |
67
|
|
|
if self.is_ready(): |
68
|
|
|
with self.psr.wopen(self.cnf_path) as out: |
69
|
|
|
out.write('[{"a": 1}, {"a": 2}]\n') |
70
|
|
|
|
71
|
|
|
ioi = self._to_ioinfo(self.cnf_path) |
72
|
|
|
|
73
|
|
|
cnf = self.psr.load(ioi) |
74
|
|
|
self.assertTrue(cnf) |
75
|
|
|
self.assertEqual(cnf, [{"a": 1}, {"a": 2}]) |
76
|
|
|
|
77
|
|
|
# vim:sw=4:ts=4:et: |
78
|
|
|
|