From aa75d0636096cf17c586ea9383617f3941b1d999 Mon Sep 17 00:00:00 2001 From: Fabio Caccamo Date: Sun, 16 Jul 2023 11:15:53 +0200 Subject: [PATCH] Add test case for issue #314. --- tests/github/test_issue_0314.py | 36 +++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 tests/github/test_issue_0314.py diff --git a/tests/github/test_issue_0314.py b/tests/github/test_issue_0314.py new file mode 100644 index 0000000..feae94b --- /dev/null +++ b/tests/github/test_issue_0314.py @@ -0,0 +1,36 @@ +import unittest + +import yaml + +from benedict import benedict + + +class github_issue_0314_test_case(unittest.TestCase): + """ + This class describes a github issue 0314 test case. + https://github.com/fabiocaccamo/python-benedict/issues/294 + + To run this specific test: + - Run python -m unittest tests.github.test_issue_0314 + """ + + def test_yaml_serializer_produces_inconsistent_results(self): + b = benedict({"foo": "foo"}) + b["hello.world"] = "hello world" + + # output as custom object using yaml manually + print(yaml.dump({"world": dict(b)})) + + # output as custom object using yaml manually + print(yaml.dump({"world": b})) + + # output as normal dict using yaml manually + print(yaml.dump({"world": b.dict()})) + + # output as normal dict using benedict yaml serializer + print(benedict({"world": b}).to_yaml()) + + self.assertEqual( + yaml.dump({"world": b.dict()}), + benedict({"world": b}).to_yaml(), + )