#
# Copyright (C) 2012 - 2015 Satoru SATOH <ssato @ redhat.com>
# License: MIT
#
# pylint: disable=missing-docstring
from __future__ import absolute_import
import unittest
import anyconfig.backend.properties as TT
import tests.backend.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

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


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):
        exp = r"\:\=\\ "
        res = TT.escape(r":=\ ")
        self.assertEqual(res, exp, res)


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

    cnf = CNF
    cnf_s = CNF_S
    load_options = dict(comment_markers=("//", "#", "!"))
    dump_options = dict(dummy_opt="this_will_be_ignored")

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


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

    psr_cls = TT.Parser
    cnf = CNF
    cnf_s = CNF_S
    cnf_fn = "conf.properties"

# vim:sw=4:ts=4:et:

@@ -57,16 +57,51 @@
 at.com%3E%0A
+# Copyright (C) 2017 Red Hat, Inc.%0A
 # Licens
@@ -144,16 +144,88 @@
 ocstring
+,invalid-name,too-few-public-methods%0A# pylint: disable=ungrouped-imports
 %0Afrom __
@@ -256,16 +256,17 @@
 _import%0A
+%0A
 import u
@@ -336,19 +336,29 @@
 backend.
-ini
+common as TBC
 %0A%0Afrom a
@@ -395,17 +395,8 @@
 Dict
- as ODict
 %0A%0A%0AC
@@ -503,16 +503,22 @@
 %0ACNF = O
+rdered
 Dict(((%22
@@ -565,16 +565,22 @@
         
+  
+    
 (%22sect0.
@@ -628,16 +628,22 @@
         
+   
+   
 (%22d%22, %22v
@@ -658,24 +658,123 @@
 ,val3%22)))%0A%0A%0A
+class HasParserTrait(TBC.HasParserTrait):%0A%0A    psr = TT.Parser()%0A    cnf = CNF%0A    cnf_s = CNF_S%0A%0A%0A
 class Test00
@@ -771,16 +771,17 @@
 ass Test
+_
 00(unitt
@@ -1203,70 +1203,58 @@
 Test
+_
 10(
-tests.backend.ini.Test10):%0A%0A    cnf = CNF%0A    cnf_s = CNF_S
+TBC.Test_10_dumps_and_loads, HasParserTrait):%0A
 %0A   
@@ -1371,61 +1371,8 @@
 %22)%0A%0A
-    def setUp(self):%0A        self.psr = TT.Parser()%0A%0A
 %0Acla
@@ -1382,125 +1382,65 @@
 Test
+_
 20(
-tests.backend.ini
+TBC
 .Test
+_
 20
-):%0A%0A    psr_cls = TT.Parser%0A    cnf = CNF%0A    cnf_s = CNF_S%0A    cnf_fn = %22conf.properties%22
+_dump_and_load, HasParserTrait):%0A%0A    pass
 %0A%0A# 

switch base test cases of properties backend from tests.backend.ini to tests.backend.common