2022-04-27 17:26:21 +00:00
|
|
|
import unittest
|
|
|
|
|
2022-10-14 14:53:06 +00:00
|
|
|
from benedict import benedict
|
|
|
|
|
2022-04-27 17:26:21 +00:00
|
|
|
|
|
|
|
class github_issue_0088_test_case(unittest.TestCase):
|
|
|
|
"""
|
|
|
|
This class describes a github issue 0088 test case.
|
|
|
|
https://github.com/fabiocaccamo/python-benedict/issues/88
|
|
|
|
|
|
|
|
To run this specific test:
|
|
|
|
- Run python -m unittest tests.github.test_issue_0088
|
|
|
|
"""
|
|
|
|
|
|
|
|
def test_flatten_without_keypath_separator(self):
|
|
|
|
d = benedict({"a": {"b": {"c": 1}}}, keypath_separator=None)
|
|
|
|
f = d.flatten(".")
|
|
|
|
self.assertEqual(f, {"a.b.c": 1})
|
|
|
|
|
|
|
|
def test_flatten_with_separator_equal_to_keypath_separator(self):
|
|
|
|
d = benedict({"a": {"b": {"c": 1}}}, keypath_separator=".")
|
|
|
|
with self.assertRaises(ValueError):
|
2023-02-09 18:19:02 +00:00
|
|
|
_ = d.flatten(".")
|
2022-04-27 17:26:21 +00:00
|
|
|
d = benedict({"a": {"b": {"c": 1}}}, keypath_separator="_")
|
|
|
|
with self.assertRaises(ValueError):
|
2023-02-09 18:19:02 +00:00
|
|
|
_ = d.flatten("_")
|
2022-04-27 17:26:21 +00:00
|
|
|
|
|
|
|
def test_flatten_with_separator_different_from_keypath_separator(self):
|
|
|
|
d = benedict({"a": {"b": {"c": 1}}}, keypath_separator="_")
|
|
|
|
f = d.flatten(".")
|
|
|
|
self.assertEqual(f, {"a.b.c": 1})
|
|
|
|
d = benedict({"a": {"b": {"c": 1}}}, keypath_separator=".")
|
|
|
|
f = d.flatten("_")
|
|
|
|
self.assertEqual(f, {"a_b_c": 1})
|