2020-09-29 08:31:55 +00:00
|
|
|
import unittest
|
|
|
|
|
2022-10-14 14:53:06 +00:00
|
|
|
from benedict import benedict
|
|
|
|
|
2020-09-29 08:31:55 +00:00
|
|
|
|
|
|
|
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.
|
2020-09-29 08:31:55 +00:00
|
|
|
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():
|
2022-12-31 17:33:20 +00:00
|
|
|
yield from enumerate("abcd")
|
2020-09-29 08:31:55 +00:00
|
|
|
|
|
|
|
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"})
|
2020-09-29 08:31:55 +00:00
|
|
|
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"})
|
2020-09-29 08:31:55 +00:00
|
|
|
self.assertEqual(b.to_json(), '{"0": "a", "1": "b", "2": "c", "3": "d"}')
|