Merge "Support integer keys of dicts in text serialization"
This commit is contained in:
commit
3a1157f1e5
|
@ -316,6 +316,26 @@ class TestGenericTextViews(base.BaseTestCase):
|
||||||
'string = value')
|
'string = value')
|
||||||
self.assertEqual(target_str, str(self.model))
|
self.assertEqual(target_str, str(self.model))
|
||||||
|
|
||||||
|
def test_dict_serialization_integer_keys(self):
|
||||||
|
self.model['dt'] = {3: 4, 5: 6}
|
||||||
|
|
||||||
|
target_str = ('dt = \n'
|
||||||
|
' 3 = 4\n'
|
||||||
|
' 5 = 6\n'
|
||||||
|
'int = 1\n'
|
||||||
|
'string = value')
|
||||||
|
self.assertEqual(target_str, str(self.model))
|
||||||
|
|
||||||
|
def test_dict_serialization_mixed_keys(self):
|
||||||
|
self.model['dt'] = {'3': 4, 5: 6}
|
||||||
|
|
||||||
|
target_str = ('dt = \n'
|
||||||
|
' 3 = 4\n'
|
||||||
|
' 5 = 6\n'
|
||||||
|
'int = 1\n'
|
||||||
|
'string = value')
|
||||||
|
self.assertEqual(target_str, str(self.model))
|
||||||
|
|
||||||
def test_list_serialization(self):
|
def test_list_serialization(self):
|
||||||
self.model['lt'] = ['a', 'b']
|
self.model['lt'] = ['a', 'b']
|
||||||
|
|
||||||
|
|
|
@ -111,7 +111,7 @@ class KeyValueView(object):
|
||||||
def serialize(root, rootkey, indent):
|
def serialize(root, rootkey, indent):
|
||||||
res = []
|
res = []
|
||||||
if rootkey is not None:
|
if rootkey is not None:
|
||||||
res.append((self.indent_str * indent) + rootkey)
|
res.append((self.indent_str * indent) + str(rootkey))
|
||||||
|
|
||||||
if isinstance(root, abc.Mapping):
|
if isinstance(root, abc.Mapping):
|
||||||
if rootkey is None and indent > 0:
|
if rootkey is None and indent > 0:
|
||||||
|
@ -121,7 +121,7 @@ class KeyValueView(object):
|
||||||
if self.before_dict is not None:
|
if self.before_dict is not None:
|
||||||
res.insert(0, self.before_dict)
|
res.insert(0, self.before_dict)
|
||||||
|
|
||||||
for key in sorted(root):
|
for key in sorted(root, key=str):
|
||||||
res.extend(serialize(root[key], key, indent + 1))
|
res.extend(serialize(root[key], key, indent + 1))
|
||||||
elif (isinstance(root, abc.Sequence) and
|
elif (isinstance(root, abc.Sequence) and
|
||||||
not isinstance(root, str)):
|
not isinstance(root, str)):
|
||||||
|
|
Loading…
Reference in New Issue