Fix `items` and `values` methods returned values type (cast to `benedict`). #333
This commit is contained in:
parent
1530a4b999
commit
a80201e975
|
@ -177,6 +177,10 @@ class benedict(KeyattrDict, KeypathDict, IODict, ParseDict):
|
|||
"""
|
||||
return _invert(self, flat)
|
||||
|
||||
def items(self):
|
||||
for key, value in super().items():
|
||||
yield (key, self._cast(value))
|
||||
|
||||
def items_sorted_by_keys(self, reverse=False):
|
||||
"""
|
||||
Return items (key/value list) sorted by keys.
|
||||
|
@ -300,6 +304,10 @@ class benedict(KeyattrDict, KeypathDict, IODict, ParseDict):
|
|||
"""
|
||||
_unique(self)
|
||||
|
||||
def values(self):
|
||||
for value in super().values():
|
||||
yield self._cast(value)
|
||||
|
||||
|
||||
# fix benedict json dumps support - #57 #59 #61
|
||||
JSONSerializer.disable_c_make_encoder()
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
import unittest
|
||||
|
||||
from benedict import benedict
|
||||
|
||||
|
||||
class github_issue_0333_test_case(unittest.TestCase):
|
||||
"""
|
||||
This class describes a github issue 0333 test case.
|
||||
https://github.com/fabiocaccamo/python-benedict/issues/294
|
||||
|
||||
To run this specific test:
|
||||
- Run python -m unittest tests.github.test_issue_0333
|
||||
"""
|
||||
|
||||
def test_items_value_type(self):
|
||||
likes = {
|
||||
"fruit": {
|
||||
"apple": "green",
|
||||
"banana": "yellow",
|
||||
"raspberry": "red",
|
||||
}
|
||||
}
|
||||
likes = benedict(
|
||||
likes,
|
||||
keyattr_enabled=True,
|
||||
keyattr_dynamic=False,
|
||||
)
|
||||
# print(type(likes.items()))
|
||||
# print(likes.items())
|
||||
for _, v in likes.items():
|
||||
self.assertEqual(type(v), benedict)
|
||||
|
||||
def test_values_value_type(self):
|
||||
likes = {
|
||||
"fruit": {
|
||||
"apple": "green",
|
||||
"banana": "yellow",
|
||||
"raspberry": "red",
|
||||
}
|
||||
}
|
||||
likes = benedict(
|
||||
likes,
|
||||
keyattr_enabled=True,
|
||||
keyattr_dynamic=False,
|
||||
)
|
||||
# print(type(likes.values()))
|
||||
# print(likes.values())
|
||||
for v in likes.values():
|
||||
self.assertEqual(type(v), benedict)
|
Loading…
Reference in New Issue