Commit b730aec0 by badaud_t

Fix decimal support with YAMLRenderer

parent 8a5fea06
...@@ -354,6 +354,17 @@ if yaml: ...@@ -354,6 +354,17 @@ if yaml:
data = parser.parse(StringIO(content)) data = parser.parse(StringIO(content))
self.assertEqual(obj, data) self.assertEqual(obj, data)
def test_render_decimal(self):
"""
Test YAML decimal rendering.
"""
renderer = YAMLRenderer()
content = renderer.render({'field': Decimal('111.2')}, 'application/yaml')
self.assertYAMLContains(content, "field: '111.2'")
def assertYAMLContains(self, content, string):
self.assertTrue(string in content, '%r not in %r' % (string, content))
class XMLRendererTestCase(TestCase): class XMLRendererTestCase(TestCase):
""" """
......
...@@ -89,6 +89,9 @@ else: ...@@ -89,6 +89,9 @@ else:
node.flow_style = best_style node.flow_style = best_style
return node return node
SafeDumper.add_representer(decimal.Decimal,
SafeDumper.represent_decimal)
SafeDumper.add_representer(SortedDict, SafeDumper.add_representer(SortedDict,
yaml.representer.SafeRepresenter.represent_dict) yaml.representer.SafeRepresenter.represent_dict)
SafeDumper.add_representer(DictWithMetadata, SafeDumper.add_representer(DictWithMetadata,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment