diff --git a/oslo_reports/tests/test_views.py b/oslo_reports/tests/test_views.py index 195390c..76cbd09 100644 --- a/oslo_reports/tests/test_views.py +++ b/oslo_reports/tests/test_views.py @@ -316,6 +316,26 @@ class TestGenericTextViews(base.BaseTestCase): 'string = value') 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): self.model['lt'] = ['a', 'b'] diff --git a/oslo_reports/views/text/generic.py b/oslo_reports/views/text/generic.py index 05928a7..e69f653 100644 --- a/oslo_reports/views/text/generic.py +++ b/oslo_reports/views/text/generic.py @@ -111,7 +111,7 @@ class KeyValueView(object): def serialize(root, rootkey, indent): res = [] 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 rootkey is None and indent > 0: @@ -121,7 +121,7 @@ class KeyValueView(object): if self.before_dict is not None: 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)) elif (isinstance(root, abc.Sequence) and not isinstance(root, str)):