示例#1
0
# License: MIT
#
# pylint: disable=missing-docstring
from __future__ import absolute_import
import anyconfig.backend.shellvars as TT
import anyconfig.backend.tests.ini

from anyconfig.compat import OrderedDict as ODict


CNF_S = """
a=0
b='bbb'   # a comment
c="ccc"   # an another comment
"""
CNF = ODict((("a", "0"), ("b", "bbb"), ("c", "ccc")))


class Test10(anyconfig.backend.tests.ini.Test10):

    cnf = CNF
    cnf_s = CNF_S

    def setUp(self):
        self.psr = TT.Parser()


class Test20(anyconfig.backend.tests.ini.Test20):

    psr_cls = TT.Parser
    cnf = CNF
示例#2
0
data = [ ["gamma", "delta"], [1, 2] ]

hosts = [
  "alpha",
  "omega"
]
"""

_DOB = TT.toml.loads("dob = 1979-05-27T07:32:00Z")['dob']

CNF = ODict((('title', 'TOML Example'),
             ('owner', ODict((('name', 'Tom Preston-Werner'), ('dob', _DOB)))),
             ('database',
              ODict((('server', '192.168.1.1'), ('ports', [8001, 8001, 8002]),
                     ('connection_max', 5000), ('enabled', True)))),
             ('servers',
              ODict((('alpha', ODict((('ip', '10.0.0.1'), ('dc', 'eqdc10')))),
                     ('beta', ODict(
                         (('ip', '10.0.0.2'), ('dc', 'eqdc10'))))))),
             ('clients',
              ODict((('data', [['gamma', 'delta'],
                               [1, 2]]), ('hosts', ['alpha', 'omega']))))))


class HasParserTrait(TBC.HasParserTrait):

    psr = TT.Parser()
    cnf = CNF
    cnf_s = CNF_S


class Test_10(TBC.Test_10_dumps_and_loads, HasParserTrait):
示例#3
0
import anyconfig.backend.properties as TT
import anyconfig.backend.tests.ini

from anyconfig.compat import OrderedDict as ODict


CNF_S = """
a = 0
  b = bbb
c:

sect0.c = x;y;z
sect1.d = \\
    1,2,3
"""
CNF = ODict((("a", "0"), ("b", "bbb"), ("c", ""),
             ("sect0.c", "x;y;z"), ("sect1.d", "1,2,3")))


class Test00(unittest.TestCase):

    def test_10_unescape(self):
        exp = "aaa:bbb"
        res = TT.unescape(r"aaa\:bbb")
        self.assertEqual(res, exp, res)

    def test_12_unescape(self):
        exp = r"\a"
        res = TT.unescape(r"\\a")
        self.assertEqual(res, exp, res)

    def test_20_escape(self):
示例#4
0
import anyconfig.backend.ini as TT
import tests.common

from anyconfig.compat import OrderedDict as ODict

CNF_0_S = """[DEFAULT]
a: 0
b: bbb
c: 5

[sect0]
d: x,y,z
"""

CNF_0 = ODict(
    (("DEFAULT", ODict((("a", "0"), ("b", "bbb"), ("c", "5")))),
     ("sect0", ODict((("a", "0"), ("b", "bbb"), ("c", "5"), ("d", "x,y,z"))))))
CNF_1 = ODict(
    (("DEFAULT", ODict((("a", 0), ("b", "bbb"), ("c", 5)))),
     ("sect0", ODict(
         (("a", 0), ("b", "bbb"), ("c", 5), ("d", "x y z".split()))))))


class MyDict(ODict):
    pass


class TestBase(unittest.TestCase):

    psr_cls = TT.Parser
    cnf = CNF_0
示例#5
0
from anyconfig.compat import OrderedDict as ODict, IS_PYTHON_2_6
from anyconfig.tests.common import dicts_equal

CNF_0_S = """{
  "a": 0,
  "b": "bbb",
  "c": 5,

  "sect0": {
    "d": ["x", "y", "z"]
  }
}
"""

CNF_0 = ODict((("a", 0), ("b", "bbb"), ("c", 5), ("sect0",
                                                  ODict((("d", ["x", "y",
                                                                "z"]), )))))


class Test10(anyconfig.backend.tests.ini.Test10):

    cnf = CNF_0
    cnf_s = CNF_0_S
    load_options = dump_options = dict(parse_int=None, indent=3)

    if IS_PYTHON_2_6:
        is_order_kept = False  # ..note:: object_pairs_hoo is not available.

    def setUp(self):
        self.psr = TT.Parser()
示例#6
0
[section 2]    # an inline comment
keyword8 = "value 9"
keyword9 = value10     # an inline comment
# The 'final_comment'
# Which also may be several lines
"""

_ML_0 = """A multiline value,
that spans more than one line :-)
The line breaks are included in the value."""

CNF_0 = ODict(
    (('keyword1', 'value1'), ('keyword 2', 'value 2'),
     ('section 1',
      ODict((('keyword 3', 'value 3'), ('keyword 4',
                                        ['value4', 'value 5', 'value 6']),
             ('sub-section',
              ODict((('keyword 5', 'value 7'), ('keyword 6', _ML_0),
                     ('sub-sub-section', ODict(
                         (('keyword 7', 'value 8'), ))))))))),
     ('section 2', ODict((('keyword8', 'value 9'), ('keyword9', 'value10'))))))


class HasParserTrait(TBC.HasParserTrait):

    psr = TT.Parser()
    cnf = CNF_0
    cnf_s = CNF_0_S


class Test_10(TBC.Test_10_dumps_and_loads, HasParserTrait):
示例#7
0
# License: MIT
#
# pylint: disable=missing-docstring
from __future__ import absolute_import

import copy

import anyconfig.backend.msgpack as TT
import anyconfig.backend.tests.ini

from anyconfig.compat import OrderedDict as ODict, IS_PYTHON_3
from anyconfig.tests.common import dicts_equal, to_bytes as _bytes

CNF_0 = ODict(((_bytes("a"), 0.1), (_bytes("b"), _bytes("bbb")),
               (_bytes("sect0"),
                ODict(((_bytes("c"), [_bytes("x"),
                                      _bytes("y"),
                                      _bytes("z")]), )))))


class Test10(anyconfig.backend.tests.ini.Test10):

    cnf = CNF_0
    cnf_s = TT.msgpack.packb(CNF_0)

    if IS_PYTHON_3:
        is_order_kept = False  # FIXME: Make it work w/ python 3.

    def setUp(self):
        self.psr = TT.Parser()
示例#8
0
from anyconfig.compat import OrderedDict as ODict

CNF_0_S = """
a: 0
b: bbb
c:
  - 1
  - 2
  - 3

sect0:
  d: ["x", "y", "z"]
"""

CNF_0 = ODict((("a", 0), ("b", "bbb"), ("c", [1, 2, 3]),
               ("sect0", ODict((("d", "x y z".split()), )))))

if TT is not None:
    import yaml

    class Test10(anyconfig.backend.tests.ini.Test10):

        cnf = CNF_0
        cnf_s = CNF_0_S
        load_options = dict(ac_safe=True, Loader=yaml.loader.Loader)
        dump_options = dict(ac_safe=True)
        is_order_kept = False  # ..note:: yaml backend cannot do this yet.

        def setUp(self):
            self.psr = TT.Parser()