Exemple #1
0
    def test_attributes_without_text(self):
        attrs = Attributes(None, {"one": "two"})

        p2x = PyToXml("a", {"b": attrs})
        p2x.add_type_handler(Attributes)

        self.assertEqual(str(p2x.encode()), "<a><b one=\"two\"/></a>")
Exemple #2
0
    def test_attributes_without_text(self):
        attrs = Attributes(None, { "one": "two" })

        p2x = PyToXml("a", { "b": attrs } )
        p2x.add_type_handler(Attributes)

        self.assertEqual(str(p2x.encode()), "<a><b one=\"two\"/></a>")
Exemple #3
0
    def test_add_type_handler(self):
        def temp_convertor(structure, element, name, pytoxml):
            element.text = str(structure)

        p2x = PyToXml("a", { "b": Exception("Should now serialise") })
        p2x.add_type_handler(Exception, temp_convertor)

        self.assertEqual(str(p2x.encode()), "<a><b>Should now serialise</b></a>")
Exemple #4
0
    def test_add_type_handler(self):
        def temp_convertor(structure, element, name, pytoxml):
            element.text = str(structure)

        p2x = PyToXml("a", {"b": Exception("Should now serialise")})
        p2x.add_type_handler(Exception, temp_convertor)

        self.assertEqual(str(p2x.encode()),
                         "<a><b>Should now serialise</b></a>")