|
1
|
|
|
# |
|
2
|
|
|
# Copyright (C) 2015 - 2017 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
|
|
|
from __future__ import absolute_import |
|
8
|
|
|
|
|
9
|
|
|
# import copy |
|
10
|
|
|
import anyconfig.backend.msgpack as TT |
|
11
|
|
|
import anyconfig.compat |
|
12
|
|
|
import tests.backend.common as TBC |
|
13
|
|
|
|
|
14
|
|
|
from tests.common import to_bytes as _bytes |
|
15
|
|
|
|
|
16
|
|
|
|
|
17
|
|
|
CNF = dict(((_bytes("a"), 0.1), |
|
18
|
|
|
(_bytes("b"), _bytes("bbb")), |
|
19
|
|
|
(_bytes("sect0"), |
|
20
|
|
|
dict(((_bytes("c"), |
|
21
|
|
|
[_bytes("x"), _bytes("y"), _bytes("z")]), ))))) |
|
22
|
|
|
|
|
23
|
|
|
|
|
24
|
|
|
class HasParserTrait(TBC.HasParserTrait): |
|
25
|
|
|
|
|
26
|
|
|
psr = TT.Parser() |
|
27
|
|
|
cnf = TBC.CNF_2 |
|
28
|
|
|
cnf_s = TT.msgpack.packb(cnf) |
|
29
|
|
|
|
|
30
|
|
|
if anyconfig.compat.IS_PYTHON_3: |
|
31
|
|
|
cnf = CNF |
|
32
|
|
|
|
|
33
|
|
|
|
|
34
|
|
|
class Test_10(TBC.Test_10_dumps_and_loads, HasParserTrait): |
|
35
|
|
|
|
|
36
|
|
|
load_options = dict(use_single_float=True) |
|
37
|
|
|
|
|
38
|
|
|
|
|
39
|
|
|
# pylint: disable=pointless-string-statement |
|
40
|
|
|
""" |
|
41
|
|
|
TODO: |
|
42
|
|
|
|
|
43
|
|
|
def test_40_loads_with_options(self): |
|
44
|
|
|
cnf = self.psr.loads(self.cnf_s, use_list=False) |
|
45
|
|
|
ref = copy.deepcopy(self.cnf) |
|
46
|
|
|
ref[_bytes("sect0")][_bytes("c")] = (_bytes("x"), _bytes("y"), |
|
47
|
|
|
_bytes("z")) |
|
48
|
|
|
self._assert_dicts_equal(cnf, ref) |
|
49
|
|
|
|
|
50
|
|
|
def test_42_dumps_with_options(self): |
|
51
|
|
|
cnf = self.psr.loads(self.psr.dumps(self.cnf, use_single_float=True)) |
|
52
|
|
|
ref = copy.deepcopy(self.cnf) |
|
53
|
|
|
ref[_bytes("a")] = cnf[_bytes("a")] # single float value. |
|
54
|
|
|
self._assert_dicts_equal(cnf, ref) |
|
55
|
|
|
|
|
56
|
|
|
|
|
57
|
|
|
class Test_20(TBC.Test_20_dump_and_load, HasParserTrait): |
|
58
|
|
|
|
|
59
|
|
|
def test_40_load_with_options(self): |
|
60
|
|
|
cnf = self.psr.load(self.cnf_path, use_list=False) |
|
61
|
|
|
ref = copy.deepcopy(self.cnf) |
|
62
|
|
|
ref[_bytes("sect0")][_bytes("c")] = (_bytes("x"), _bytes("y"), |
|
63
|
|
|
_bytes("z")) |
|
64
|
|
|
self._assert_dicts_equal(cnf, ref) |
|
65
|
|
|
|
|
66
|
|
|
def test_42_dump_with_special_option(self): |
|
67
|
|
|
self.psr.dump(self.cnf, self.cnf_path, use_single_float=True) |
|
68
|
|
|
cnf = self.psr.load(self.cnf_path) |
|
69
|
|
|
ref = copy.deepcopy(self.cnf) |
|
70
|
|
|
ref[_bytes("a")] = cnf[_bytes("a")] # single float value. |
|
71
|
|
|
self._assert_dicts_equal(cnf, ref) |
|
72
|
|
|
""" |
|
73
|
|
|
|
|
74
|
|
|
# vim:sw=4:ts=4:et: |
|
75
|
|
|
|