python-benedict/tests/github/test_issue_0038.py

29 lines
937 B
Python
Raw Normal View History

import unittest
from benedict import benedict
class github_issue_0038_test_case(unittest.TestCase):
"""
2022-02-13 10:35:43 +00:00
This class describes a github issue 0038 test case.
https://github.com/fabiocaccamo/python-benedict/issues/38
To run this specific test:
- Run python -m unittest tests.github.test_issue_0038
"""
@staticmethod
def get_dict_generator():
yield from enumerate("abcd")
def test_init_with_generator(self):
b = benedict(self.get_dict_generator())
2022-02-13 10:35:43 +00:00
self.assertEqual(b, {0: "a", 1: "b", 2: "c", 3: "d"})
self.assertEqual(b.to_json(), '{"0": "a", "1": "b", "2": "c", "3": "d"}')
# recast benedict to dict and back to benedict
b = benedict(self.get_dict_generator())
d = dict(b)
b = benedict(d)
2022-02-13 10:35:43 +00:00
self.assertEqual(b, {0: "a", 1: "b", 2: "c", 3: "d"})
self.assertEqual(b.to_json(), '{"0": "a", "1": "b", "2": "c", "3": "d"}')