Modify flatten method to display an empty dict
When a dict is flattened, if a value of an item is empty, e.g. {"cpu_info": {}}, the item is not displayed. This patch fixes _flatten method to display such an item including an empty dict. Change-Id: I2e4ada0de217c5c4ddea10f3f283c6d8e78083b6 Related-Bug: #1594230
This commit is contained in:
parent
22beb3b4ea
commit
fae24eee4a
@ -340,7 +340,8 @@ class FlattenTestCase(test_utils.TestCase):
|
||||
'b4': {'c1': ['l', 'l', ['l']],
|
||||
'c2': 'string'}},
|
||||
'a2': ['l'],
|
||||
'a3': ('t',)})
|
||||
'a3': ('t',),
|
||||
'a4': {}})
|
||||
|
||||
self.assertEqual({'a1_b1': 1234,
|
||||
'a1_b2': 'string',
|
||||
@ -348,7 +349,8 @@ class FlattenTestCase(test_utils.TestCase):
|
||||
'a1_b4_c1': ['l', 'l', ['l']],
|
||||
'a1_b4_c2': 'string',
|
||||
'a2': ['l'],
|
||||
'a3': ('t',)},
|
||||
'a3': ('t',),
|
||||
'a4': {}},
|
||||
squashed)
|
||||
|
||||
def test_pretty_choice_dict(self):
|
||||
|
@ -210,7 +210,7 @@ def _flatten(data, prefix=None):
|
||||
if isinstance(data, dict):
|
||||
for key, value in six.iteritems(data):
|
||||
new_key = '%s_%s' % (prefix, key) if prefix else key
|
||||
if isinstance(value, (dict, list)):
|
||||
if isinstance(value, (dict, list)) and value:
|
||||
for item in _flatten(value, new_key):
|
||||
yield item
|
||||
else:
|
||||
|
Loading…
Reference in New Issue
Block a user