Fixed benedict yaml representer. #43

This commit is contained in:
Fabio Caccamo 2020-11-30 11:26:20 +01:00
parent c1172d8cc0
commit a121c9da9e
2 changed files with 13 additions and 0 deletions

View File

@ -270,3 +270,10 @@ class benedict(KeypathDict, IODict, ParseDict):
Remove duplicated values from the current dict instance.
"""
_unique(self)
# fix benedict yaml representer - #43
from yaml import SafeDumper
from yaml.representer import SafeRepresenter
SafeDumper.yaml_representers[cls] = SafeRepresenter.represent_dict

View File

@ -3,6 +3,7 @@
from benedict import benedict
import unittest
import yaml
class github_issue_0043_test_case(unittest.TestCase):
@ -21,3 +22,8 @@ class github_issue_0043_test_case(unittest.TestCase):
level2: Hello world
"""
self.assertEqual(s, r)
def test_dict_compatibility(self):
yaml.safe_dump(dict(benedict({})))
yaml.safe_dump(dict(benedict({"level1": None})))
yaml.safe_dump(dict(benedict({"level1": {"level2": "blablabla"}})))