예제 #1
0
    def test_22__process_elem_text__wo_attrs_and_children_parse(self):
        (elem, dic, subdic) = (TT.ET.XML("<a>A</a>"), {}, {})
        TT._process_elem_text(elem, dic, subdic, text="#text",
                              ac_parse_value=True)
        self.assertTrue(dicts_equal(dic, {"a": 'A'}))
        self.assertTrue(not subdic)

        (elem, dic, subdic) = (TT.ET.XML("<a>1</a>"), {}, {})
        TT._process_elem_text(elem, dic, subdic, text="#text",
                              ac_parse_value=True)
        self.assertTrue(dicts_equal(dic, {"a": 1}))
        self.assertTrue(not subdic)
예제 #2
0
    def test_40_gen_schema__primitive_types(self):
        self.assertEqual(TT.gen_schema(None), {'type': 'null'})
        self.assertEqual(TT.gen_schema(0), {'type': 'integer'})
        self.assertEqual(TT.gen_schema("aaa"), {'type': 'string'})

        scm = TT.gen_schema([1])
        ref_scm = {'items': {'type': 'integer'}, 'type': 'array'}
        self.assertTrue(dicts_equal(scm, ref_scm))

        scm = TT.gen_schema({'a': 1})
        ref_scm = {'properties': {'a': {'type': 'integer'}}, 'type': 'object'}
        self.assertTrue(dicts_equal(scm, ref_scm))
예제 #3
0
    def test_22__process_elem_text__wo_attrs_and_children_parse(self):
        (elem, dic, subdic) = (TT.ET.XML("<a>A</a>"), {}, {})
        TT._process_elem_text(elem, dic, subdic, text="#text",
                              ac_parse_value=True)
        self.assertTrue(dicts_equal(dic, {"a": 'A'}))
        self.assertTrue(not subdic)

        (elem, dic, subdic) = (TT.ET.XML("<a>1</a>"), {}, {})
        TT._process_elem_text(elem, dic, subdic, text="#text",
                              ac_parse_value=True)
        self.assertTrue(dicts_equal(dic, {"a": 1}))
        self.assertTrue(not subdic)
예제 #4
0
    def test_40_gen_schema__primitive_types(self):
        self.assertEqual(TT.gen_schema(None), {'type': 'null'})
        self.assertEqual(TT.gen_schema(0), {'type': 'integer'})
        self.assertEqual(TT.gen_schema("aaa"), {'type': 'string'})

        scm = TT.gen_schema([1])
        ref_scm = {'items': {'type': 'integer'}, 'type': 'array'}
        self.assertTrue(dicts_equal(scm, ref_scm))

        scm = TT.gen_schema({'a': 1})
        ref_scm = {'properties': {'a': {'type': 'integer'}}, 'type': 'object'}
        self.assertTrue(dicts_equal(scm, ref_scm))
예제 #5
0
    def test_36__process_elem_attrs__wo_text_and_children_parse(self):
        (elem, dic, subdic) = (TT.ET.XML("<a id='1'/>"), {}, {})
        TT._process_elem_attrs(elem, dic, subdic, ac_parse_value=True)
        self.assertTrue(not dic)
        self.assertTrue(dicts_equal(subdic, {"@attrs": {"id": 1}}))

        (elem, dic, subdic) = (TT.ET.XML("<a id='A'/>"), {}, {})
        TT._process_elem_attrs(elem, dic, subdic, ac_parse_value=True)
        self.assertTrue(not dic)
        self.assertTrue(dicts_equal(subdic, {"@attrs": {"id": 'A'}}))

        (elem, dic, subdic) = (TT.ET.XML("<a id='true'/>"), {}, {})
        TT._process_elem_attrs(elem, dic, subdic, ac_parse_value=True)
        self.assertTrue(not dic)
        self.assertTrue(dicts_equal(subdic, {"@attrs": {"id": True}}))
예제 #6
0
    def test_36__process_elem_attrs__wo_text_and_children_parse(self):
        (elem, dic, subdic) = (TT.ET.XML("<a id='1'/>"), {}, {})
        TT._process_elem_attrs(elem, dic, subdic, ac_parse_value=True)
        self.assertTrue(not dic)
        self.assertTrue(dicts_equal(subdic, {"@attrs": {"id": 1}}))

        (elem, dic, subdic) = (TT.ET.XML("<a id='A'/>"), {}, {})
        TT._process_elem_attrs(elem, dic, subdic, ac_parse_value=True)
        self.assertTrue(not dic)
        self.assertTrue(dicts_equal(subdic, {"@attrs": {"id": 'A'}}))

        (elem, dic, subdic) = (TT.ET.XML("<a id='true'/>"), {}, {})
        TT._process_elem_attrs(elem, dic, subdic, ac_parse_value=True)
        self.assertTrue(not dic)
        self.assertTrue(dicts_equal(subdic, {"@attrs": {"id": True}}))
예제 #7
0
    def test_20_json_pointer(self):
        # test case in rfc, http://tools.ietf.org/html/rfc6901
        dic = {
            "foo": ["bar", "baz"],
            "": 0,
            "a/b": 1,
            "c%d": 2,
            "e^f": 3,
            "g|h": 4,
            r"i\\j": 5,
            r'k\"l': 6,
            " ": 7,
            "m~n": 8
        }

        self.assertTrue(dicts_equal(TT.get(dic, "")[0], dic))
        self.assertEqual(TT.get(dic, "/foo")[0], ["bar", "baz"])
        self.assertEqual(TT.get(dic, "/foo/0")[0], "bar")
        self.assertEqual(TT.get(dic, "/")[0], 0)
        self.assertEqual(TT.get(dic, "/a~1b")[0], 1)
        self.assertEqual(TT.get(dic, "/c%d")[0], 2)
        self.assertEqual(TT.get(dic, "/e^f")[0], 3)
        self.assertEqual(TT.get(dic, "/g|h")[0], 4)
        self.assertEqual(TT.get(dic, r"/i\\j")[0], 5)
        self.assertEqual(TT.get(dic, r'/k\"l')[0], 6)
        self.assertEqual(TT.get(dic, "/ ")[0], 7)
        self.assertEqual(TT.get(dic, "/m~0n")[0], 8)
예제 #8
0
 def test_46__process_children_elems__w_merge_attrs(self):
     elem = TT.ET.XML("<a z='Z'><x>X</x><y>Y</y></a>")
     dic = {"a": {"@attrs": {"z": "Z"}}}
     subdic = dic["a"]["@attrs"]
     TT._process_children_elems(elem, dic, subdic, merge_attrs=True)
     self.assertTrue(dicts_equal(dic, {"a": {"x": "X", "y": "Y",
                                             "z": "Z"}}), dic)
예제 #9
0
    def test_20_update_wo_replace(self):
        dic = copy.deepcopy(self.dic)
        exp = copy.deepcopy(self.dic)
        exp["e"] = self.upd["e"]

        TT.merge(dic, self.upd, ac_merge=TT.MS_NO_REPLACE)
        self.assertTrue(dicts_equal(dic, exp))
예제 #10
0
    def test_10_update_with_replace(self):
        dic = copy.deepcopy(self.dic)
        exp = copy.deepcopy(self.upd)
        exp["name"] = dic["name"]

        TT.merge(dic, self.upd, ac_merge=TT.MS_REPLACE)
        self.assertTrue(dicts_equal(dic, exp))
예제 #11
0
 def test_10__namespaces_from_file(self):
     ref = {
         "http://example.com/ns/config": '',
         "http://example.com/ns/config/val": "val"
     }
     xmlfile = anyconfig.compat.StringIO(XML_W_NS_S)
     self.assertTrue(dicts_equal(TT._namespaces_from_file(xmlfile), ref))
예제 #12
0
 def test_10__namespaces_from_file(self):
     ref = {
         "http://example.com/ns/config": '',
         "http://example.com/ns/config/val": "val"
     }
     xmlfile = anyconfig.compat.StringIO(TBC.read_from_res("20-00-cnf.xml"))
     self.assertTrue(dicts_equal(TT._namespaces_from_file(xmlfile), ref))
예제 #13
0
    def test_20_json_pointer(self):
        # test case in rfc, http://tools.ietf.org/html/rfc6901
        dic = {"foo": ["bar", "baz"],
               "": 0,
               "a/b": 1,
               "c%d": 2,
               "e^f": 3,
               "g|h": 4,
               r"i\\j": 5,
               r'k\"l': 6,
               " ": 7,
               "m~n": 8}

        self.assertTrue(dicts_equal(TT.get(dic, "")[0], dic))
        self.assertEqual(TT.get(dic, "/foo")[0], ["bar", "baz"])
        self.assertEqual(TT.get(dic, "/foo/0")[0], "bar")
        self.assertEqual(TT.get(dic, "/")[0], 0)
        self.assertEqual(TT.get(dic, "/a~1b")[0], 1)
        self.assertEqual(TT.get(dic, "/c%d")[0], 2)
        self.assertEqual(TT.get(dic, "/e^f")[0], 3)
        self.assertEqual(TT.get(dic, "/g|h")[0], 4)
        self.assertEqual(TT.get(dic, r"/i\\j")[0], 5)
        self.assertEqual(TT.get(dic, r'/k\"l')[0], 6)
        self.assertEqual(TT.get(dic, "/ ")[0], 7)
        self.assertEqual(TT.get(dic, "/m~0n")[0], 8)
예제 #14
0
    def test_19_dump_and_single_load_with_validation(self):
        cnf = CNF_0
        scm = SCM_0

        cnf_path = os.path.join(self.workdir, "cnf_19.json")
        scm_path = os.path.join(self.workdir, "scm_19.json")

        TT.dump(cnf, cnf_path)
        TT.dump(scm, scm_path)
        self.assertTrue(os.path.exists(cnf_path))
        self.assertTrue(os.path.exists(scm_path))

        cnf_1 = TT.single_load(cnf_path, ac_schema=scm_path)

        self.assertFalse(cnf_1 is None)  # Validation should succeed.
        self.assertTrue(dicts_equal(cnf_1, cnf), cnf_1)

        cnf_2 = cnf.copy()
        cnf_2["a"] = "aaa"  # It's type should be integer not string.
        cnf_2_path = os.path.join(self.workdir, "cnf_19_2.json")
        TT.dump(cnf_2, cnf_2_path)
        self.assertTrue(os.path.exists(cnf_2_path))

        cnf_3 = TT.single_load(cnf_2_path, ac_schema=scm_path)
        self.assertTrue(cnf_3 is None)  # Validation should fail.
예제 #15
0
    def test_19_dump_and_single_load_with_validation(self):
        cnf = CNF_0
        scm = SCM_0

        cnf_path = os.path.join(self.workdir, "cnf_19.json")
        scm_path = os.path.join(self.workdir, "scm_19.json")

        TT.dump(cnf, cnf_path)
        TT.dump(scm, scm_path)
        self.assertTrue(os.path.exists(cnf_path))
        self.assertTrue(os.path.exists(scm_path))

        cnf_1 = TT.single_load(cnf_path, ac_schema=scm_path)

        self.assertFalse(cnf_1 is None)  # Validation should succeed.
        self.assertTrue(dicts_equal(cnf_1, cnf), cnf_1)

        cnf_2 = cnf.copy()
        cnf_2["a"] = "aaa"  # It's type should be integer not string.
        cnf_2_path = os.path.join(self.workdir, "cnf_19_2.json")
        TT.dump(cnf_2, cnf_2_path)
        self.assertTrue(os.path.exists(cnf_2_path))

        cnf_3 = TT.single_load(cnf_2_path, ac_schema=scm_path)
        self.assertTrue(cnf_3 is None)  # Validation should fail.
예제 #16
0
    def test_20_update_wo_replace(self):
        dic = copy.deepcopy(self.dic)
        exp = copy.deepcopy(self.dic)
        exp["e"] = self.upd["e"]

        TT.merge(dic, self.upd, ac_merge=TT.MS_NO_REPLACE)
        self.assertTrue(dicts_equal(dic, exp))
예제 #17
0
    def test_10_update_with_replace(self):
        dic = copy.deepcopy(self.dic)
        exp = copy.deepcopy(self.upd)
        exp["name"] = dic["name"]

        TT.merge(dic, self.upd, ac_merge=TT.MS_REPLACE)
        self.assertTrue(dicts_equal(dic, exp))
예제 #18
0
 def test_46__process_children_elems__w_merge_attrs(self):
     elem = TT.ET.XML("<a z='Z'><x>X</x><y>Y</y></a>")
     dic = {"a": {"@attrs": {"z": "Z"}}}
     subdic = dic["a"]["@attrs"]
     TT._process_children_elems(elem, dic, subdic, merge_attrs=True)
     self.assertTrue(dicts_equal(dic, {"a": {"x": "X", "y": "Y",
                                             "z": "Z"}}), dic)
예제 #19
0
    def test_30_update_with_merge(self):
        dic = copy.deepcopy(self.dic)
        exp = copy.deepcopy(self.upd)
        exp["b"]["c"] = dic["b"]["c"]
        exp["name"] = dic["name"]

        TT.merge(dic, self.upd, ac_merge=TT.MS_DICTS)
        self.assertTrue(dicts_equal(dic, exp))
예제 #20
0
    def test_30_update_with_merge(self):
        dic = copy.deepcopy(self.dic)
        exp = copy.deepcopy(self.upd)
        exp["b"]["c"] = dic["b"]["c"]
        exp["name"] = dic["name"]

        TT.merge(dic, self.upd, ac_merge=TT.MS_DICTS)
        self.assertTrue(dicts_equal(dic, exp))
예제 #21
0
    def test_42__process_children_elems__w_attr(self):
        (elem, dic) = (TT.ET.XML("<list id='xyz'><i>A</i><i>B</i></list>"), {})
        subdic = {"id": "xyz"}
        ref = subdic.copy()
        ref.update({"#children": [{"i": "A"}, {"i": "B"}]})

        TT._process_children_elems(elem, dic, subdic, children="#children")
        self.assertTrue(not dic)
        self.assertTrue(dicts_equal(subdic, ref), subdic)
예제 #22
0
    def _try_load(self, fname="0.msgpack"):
        try:
            filepath = os.path.join(_CURDIR, "res", fname)
            cnf = anyconfig.load(filepath, ac_parser="msgpack")
        except anyconfig.UnknownFileTypeError:
            print("all types=%r" % anyconfig.list_types())
            raise

        self.assertTrue(dicts_equal(cnf, CNF_0), "%r vs. %r" % (cnf, CNF_0))
예제 #23
0
    def test_42__process_children_elems__w_attr(self):
        (elem, dic) = (TT.ET.XML("<list id='xyz'><i>A</i><i>B</i></list>"), {})
        subdic = {"id": "xyz"}
        ref = subdic.copy()
        ref.update({"#children": [{"i": "A"}, {"i": "B"}]})

        TT._process_children_elems(elem, dic, subdic, children="#children")
        self.assertTrue(not dic)
        self.assertTrue(dicts_equal(subdic, ref), subdic)
예제 #24
0
    def test_40_gen_schema__primitive_types(self):
        self.assertEqual(_gen_scm(None), {'type': 'null'})
        self.assertEqual(_gen_scm(0), {'type': 'integer'})
        self.assertEqual(_gen_scm("aaa"), {'type': 'string'})

        scm = _gen_scm([1])
        ref_scm = {'items': {'type': 'integer'}, 'type': 'array',
                   'minItems': 1, 'uniqueItems': True}
        self.assertTrue(dicts_equal(scm, ref_scm))

        scm = _gen_scm(["aaa", "bbb", "aaa"])
        ref_scm = {'items': {'type': 'string'}, 'type': 'array',
                   'minItems': 3, 'uniqueItems': False}
        self.assertTrue(dicts_equal(scm, ref_scm))

        scm = _gen_scm({'a': 1})
        ref_scm = {'properties': {'a': {'type': 'integer'}},
                   'type': 'object', 'required': ['a']}
        self.assertTrue(dicts_equal(scm, ref_scm))
예제 #25
0
    def test_40_gen_schema__primitive_types(self):
        self.assertEqual(_gen_scm(None), {'type': 'null'})
        self.assertEqual(_gen_scm(0), {'type': 'integer'})
        self.assertEqual(_gen_scm("aaa"), {'type': 'string'})

        scm = _gen_scm([1])
        ref_scm = {'items': {'type': 'integer'}, 'type': 'array',
                   'minItems': 1, 'uniqueItems': True}
        self.assertTrue(dicts_equal(scm, ref_scm))

        scm = _gen_scm(["aaa", "bbb", "aaa"])
        ref_scm = {'items': {'type': 'string'}, 'type': 'array',
                   'minItems': 3, 'uniqueItems': False}
        self.assertTrue(dicts_equal(scm, ref_scm))

        scm = _gen_scm({'a': 1})
        ref_scm = {'properties': {'a': {'type': 'integer'}},
                   'type': 'object', 'required': ['a']}
        self.assertTrue(dicts_equal(scm, ref_scm))
예제 #26
0
    def test_50_update_with_custom_merge(self):
        def set_none_merge_strat(self, other, key, *args, **kwargs):
            for k in self:
                self[k] = None

        dic = copy.deepcopy(self.dic)
        exp = dict(zip(dic.keys(), [None for _ in dic]))

        TT.merge(dic, self.upd, ac_merge=set_none_merge_strat)
        self.assertTrue(dicts_equal(dic, exp))
예제 #27
0
    def test_50_update_with_custom_merge(self):
        def set_none_merge_strat(self, other, key, *args, **kwargs):
            for k in self:
                self[k] = None

        dic = copy.deepcopy(self.dic)
        exp = dict(zip(dic.keys(), [None for _ in dic]))

        TT.merge(dic, self.upd, ac_merge=set_none_merge_strat)
        self.assertTrue(dicts_equal(dic, exp))
예제 #28
0
 def test_22_load__explicit_use(self):
     cnf = self._load_helper(ac_parser=_CID)
     ref = {
         _b('a'): 0,
         _b('b'): _b('bbb'),
         _b('c'): 5,
         _b('sect0'): {
             _b('d'): [_b('x'), _b('y'), _b('z')]
         }
     }
     self.assertTrue(dicts_equal(cnf, ref))
예제 #29
0
 def test_20_load(self):
     cnf = self._load_helper()
     ref = {
         _b('a'): 0,
         _b('b'): _b('bbb'),
         _b('c'): 5,
         _b('sect0'): {
             _b('d'): [_b('x'), _b('y'), _b('z')]
         }
     }
     self.assertTrue(dicts_equal(cnf, ref))
예제 #30
0
    def test_18_single_load__templates(self):
        if not anyconfig.template.SUPPORTED:
            return

        a_path = os.path.join(resdir(), "30-00-cnf.json")
        a2_path = os.path.join(resdir(), "00-00-cnf.json")  # Not a template

        cnf1 = TT.single_load(a_path, ac_template=True, ac_context=self.cnf)
        self.assertTrue(dicts_equal(self.cnf, cnf1), str(cnf1))

        cnf2 = TT.single_load(a2_path, ac_template=True)
        self.assertEqual(cnf2["a"], 1)
예제 #31
0
    def test_18_single_load__templates(self):
        if not anyconfig.template.SUPPORTED:
            return

        a_path = os.path.join(resdir(), "30-00-cnf.json")
        a2_path = os.path.join(resdir(), "00-00-cnf.json")  # Not a template

        cnf1 = TT.single_load(a_path, ac_template=True, ac_context=self.cnf)
        self.assertTrue(dicts_equal(self.cnf, cnf1), str(cnf1))

        cnf2 = TT.single_load(a2_path, ac_template=True)
        self.assertEqual(cnf2["a"], 1)
예제 #32
0
    def test_20_load(self):
        try:
            cnf = anyconfig.load(self.conf_path)
        except anyconfig.UnknownFileTypeError:
            for entry in pkg_resources.iter_entry_points("anyconfig_backends"):
                print("%r" % entry)
                psr = entry.load()
                print("%r" % psr)
                print("type=%r, exts=%r" % (psr.type(), psr.extensions()))

            print("all types=%r" % anyconfig.list_types())
            raise

        self.assertTrue(dicts_equal(cnf, _CNF_0))
예제 #33
0
    def _load_and_dump_with_opened_files(self, filename, rmode='r', wmode='w',
                                         **oopts):
        cpath = os.path.join(self.workdir, filename)

        with TT.open(cpath, 'w', **oopts) as out:
            TT.dump(self.cnf, out)
            self.assertTrue(_is_file_object(out))
            self.assertEqual(out.mode, wmode)

        with TT.open(cpath, 'rb', **oopts) as inp:
            cnf1 = TT.single_load(inp)
            self.assertTrue(_is_file_object(inp))
            self.assertEqual(inp.mode, rmode)
            cpair = (self.cnf, cnf1)
            self.assertTrue(dicts_equal(*cpair), "%r vs. %r" % cpair)
예제 #34
0
    def _load_and_dump_with_opened_files(self, filename, rmode='r', wmode='w',
                                         **oopts):
        cpath = os.path.join(self.workdir, filename)

        with TT.open(cpath, 'w', **oopts) as out:
            TT.dump(self.cnf, out)
            self.assertTrue(_is_file_object(out))
            self.assertEqual(out.mode, wmode)

        with TT.open(cpath, 'rb', **oopts) as inp:
            cnf1 = TT.single_load(inp)
            self.assertTrue(_is_file_object(inp))
            self.assertEqual(inp.mode, rmode)
            cpair = (self.cnf, cnf1)
            self.assertTrue(dicts_equal(*cpair), "%r vs. %r" % cpair)
예제 #35
0
    def test_20_load(self):
        try:
            cnf = anyconfig.load(self.conf_path)
        except anyconfig.UnknownFileTypeError:
            print("all types=%r" % anyconfig.list_types())
            raise

        ref = {
            _b('a'): 0,
            _b('b'): _b('bbb'),
            _b('c'): 5,
            _b('sect0'): {
                _b('d'): [_b('x'), _b('y'), _b('z')]
            }
        }
        self.assertTrue(dicts_equal(cnf, ref))
예제 #36
0
    def test_18_single_load__templates(self):
        if not anyconfig.template.SUPPORTED:
            return

        a_path = os.path.join(self.workdir, "a.yml")
        b_path = os.path.join(self.workdir, "b.yml")
        a2_path = os.path.join(self.workdir, "x/y/z", "a.yml")

        open(a_path, 'w').write("{% include 'b.yml' %}")
        open(b_path, 'w').write(CNF_TMPL_0)
        os.makedirs(os.path.dirname(a2_path))
        open(a2_path, 'w').write("a: 'xyz'")

        cnf1 = TT.single_load(a_path, ac_template=True, ac_context=self.cnf)
        self.assertTrue(dicts_equal(self.cnf, cnf1), str(cnf1))

        cnf2 = TT.single_load(a2_path, ac_template=True)
        self.assertEqual(cnf2["a"], "xyz")
예제 #37
0
 def test_30__process_elem_attrs__wo_text_and_children(self):
     (elem, dic, subdic) = (TT.ET.XML("<a id='A'/>"), {}, {})
     TT._process_elem_attrs(elem, dic, subdic)
     self.assertTrue(not dic)
     self.assertTrue(dicts_equal(subdic, {"@attrs": {"id": 'A'}}))
예제 #38
0
 def test_24__process_elem_text__w_children(self):
     (elem, dic, subdic) = (TT.ET.XML("<a>A<b/></a>"), {}, {})
     TT._process_elem_text(elem, dic, subdic, text="#text")
     self.assertTrue(not dic)
     self.assertTrue(dicts_equal(subdic, {"#text": 'A'}))
예제 #39
0
 def test_24__process_elem_text__w_children(self):
     (elem, dic, subdic) = (TT.ET.XML("<a>A<b/></a>"), {}, {})
     TT._process_elem_text(elem, dic, subdic, text="#text")
     self.assertTrue(not dic)
     self.assertTrue(dicts_equal(subdic, {"#text": 'A'}))
예제 #40
0
 def assert_dicts_equal(self, dic, ref, ordered=False):
     self.assertTrue(dicts_equal(dic, ref, ordered=ordered),
                     "%r%s vs.%s%r" % (dic, os.linesep, os.linesep, ref))
예제 #41
0
 def test_40__process_children_elems__root(self):
     (elem, dic, subdic) = (TT.ET.XML("<list><i>A</i><i>B</i></list>"), {},
                            {})
     TT._process_children_elems(elem, dic, subdic)
     self.assertTrue(dicts_equal(dic, {"list": [{"i": "A"}, {"i": "B"}]}))
     self.assertTrue(not subdic)
예제 #42
0
 def test_44__process_children_elems__w_children_have_unique_keys(self):
     (elem, dic, subdic) = (TT.ET.XML("<a><x>X</x><y>Y</y></a>"), {}, {})
     TT._process_children_elems(elem, dic, subdic)
     self.assertTrue(dicts_equal(dic, {"a": {"x": "X", "y": "Y"}}))
     self.assertTrue(not subdic)
예제 #43
0
 def test_10__namespaces_from_file(self):
     ref = {"http://example.com/ns/config": '',
            "http://example.com/ns/config/val": "val"}
     xmlfile = anyconfig.compat.StringIO(TBC.read_from_res("20-00-cnf.xml"))
     self.assertTrue(dicts_equal(TT._namespaces_from_file(xmlfile), ref))
예제 #44
0
 def test_34__process_elem_attrs__merge_attrs(self):
     (elem, dic, subdic) = (TT.ET.XML("<a id='A'/>"), {}, {})
     TT._process_elem_attrs(elem, dic, subdic, merge_attrs=True)
     self.assertTrue(dicts_equal(dic, {"a": {"id": 'A'}}))
     self.assertTrue(not subdic)
예제 #45
0
 def test_10_empty_path(self):
     dic = dict(a=1, b=[1, 2])
     (dic2, err) = TT.get(dic, '')
     self.assertEqual(err, '')
     self.assertTrue(dicts_equal(dic2, dic))
예제 #46
0
 def test_44_gen_schema__complex_types(self):
     scm = _gen_scm(self.obj2)
     self.assertTrue(dicts_equal(scm, self.ref_scm))
예제 #47
0
 def test_20_array_to_schema(self):
     scm = TT.array_to_schema([1])
     ref = dict(items=dict(type="integer"), type="array")
     self.assertTrue(dicts_equal(scm, ref), scm)
예제 #48
0
 def test_22_array_to_schema__empty_array(self):
     scm = TT.array_to_schema([])
     ref = dict(items=dict(type="string"), type="array")
     self.assertTrue(dicts_equal(scm, ref), scm)
예제 #49
0
 def test_30_object_to_schema_nodes_iter(self):
     scm = TT.object_to_schema({'a': 1})
     ref = dict(type="object", properties=dict(a=dict(type="integer")))
     self.assertTrue(dicts_equal(scm, ref), scm)
예제 #50
0
 def test_32__process_elem_attrs__w_text(self):
     (elem, dic, subdic) = (TT.ET.XML("<a id='A'>AAA</a>"), {}, {})
     TT._process_elem_attrs(elem, dic, subdic)
     self.assertTrue(not dic)
     self.assertTrue(dicts_equal(subdic, {"@attrs": {"id": 'A'}}))
예제 #51
0
 def test_34__process_elem_attrs__merge_attrs(self):
     (elem, dic, subdic) = (TT.ET.XML("<a id='A'/>"), {}, {})
     TT._process_elem_attrs(elem, dic, subdic, merge_attrs=True)
     self.assertTrue(dicts_equal(dic, {"a": {"id": 'A'}}))
     self.assertTrue(not subdic)
예제 #52
0
 def test_32__process_elem_attrs__w_text(self):
     (elem, dic, subdic) = (TT.ET.XML("<a id='A'>AAA</a>"), {}, {})
     TT._process_elem_attrs(elem, dic, subdic)
     self.assertTrue(not dic)
     self.assertTrue(dicts_equal(subdic, {"@attrs": {"id": 'A'}}))
예제 #53
0
 def test_40__process_children_elems__root(self):
     (elem, dic, subdic) = (TT.ET.XML("<list><i>A</i><i>B</i></list>"), {},
                            {})
     TT._process_children_elems(elem, dic, subdic)
     self.assertTrue(dicts_equal(dic, {"list": [{"i": "A"}, {"i": "B"}]}))
     self.assertTrue(not subdic)
예제 #54
0
 def test_30__process_elem_attrs__wo_text_and_children(self):
     (elem, dic, subdic) = (TT.ET.XML("<a id='A'/>"), {}, {})
     TT._process_elem_attrs(elem, dic, subdic)
     self.assertTrue(not dic)
     self.assertTrue(dicts_equal(subdic, {"@attrs": {"id": 'A'}}))
예제 #55
0
 def test_44__process_children_elems__w_children_have_unique_keys(self):
     (elem, dic, subdic) = (TT.ET.XML("<a><x>X</x><y>Y</y></a>"), {}, {})
     TT._process_children_elems(elem, dic, subdic)
     self.assertTrue(dicts_equal(dic, {"a": {"x": "X", "y": "Y"}}))
     self.assertTrue(not subdic)
예제 #56
0
 def test_22_array_to_schema__empty_array(self):
     scm = TT.array_to_schema([])
     ref = dict(items=dict(type="string"), type="array")
     self.assertTrue(dicts_equal(scm, ref), scm)
 def _co_assert_equals(self, cnf):
     self.assertTrue(dicts_equal(cnf, self.conf_ref.dict()))
예제 #58
0
 def test_30_object_to_schema_nodes_iter(self):
     scm = TT.object_to_schema({'a': 1})
     ref = dict(type="object", properties=dict(a=dict(type="integer")))
     self.assertTrue(dicts_equal(scm, ref), scm)