Exemple #1
0
 def test_typemap(self):
     """
     Providing a type map to `ElementMaker` allows the caller to specify how
     to serialize types other than strings and dictionaries.
     """
     E = ElementMaker(typemap={
         float: lambda e, v: '%0.2f' % (v, ),
         int: lambda e, v: L.int(str(v))
     })
     self.assertEqual('<tag>2.50</tag>', tostring(E('tag', 2.5)))
     self.assertEqual('<tag><int>42</int></tag>', tostring(E('tag', 42)))
Exemple #2
0
 def test_typemap(self):
     """
     Providing a type map to `ElementMaker` allows the caller to specify how
     to serialize types other than strings and dictionaries.
     """
     E = ElementMaker(typemap={
         float: lambda e, v: '%0.2f' % (v,),
         int: lambda e, v: L.int(str(v))})
     self.assertEqual(
         '<tag>2.50</tag>',
         tostring(E('tag', 2.5)))
     self.assertEqual(
         '<tag><int>42</int></tag>',
         tostring(E('tag', 42)))