Skip to content

Commit dcf658c

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Unordered dicts and lists causes variable results"
2 parents 9b3c84e + 514ecc6 commit dcf658c

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

openstackclient/common/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def format_dict(data):
7777
"""
7878

7979
output = ""
80-
for s in data:
80+
for s in sorted(data):
8181
output = output + s + "='" + six.text_type(data[s]) + "', "
8282
return output[:-2]
8383

@@ -89,7 +89,7 @@ def format_list(data):
8989
:rtype: a string formatted to a,b,c
9090
"""
9191

92-
return ', '.join(data)
92+
return ', '.join(sorted(data))
9393

9494

9595
def get_item_properties(item, fields, mixed_case_fields=[], formatters={}):

openstackclient/tests/common/test_utils.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,15 @@ def test_find_resource_find_no_unique(self):
130130
str(result))
131131
self.manager.get.assert_called_with(self.name)
132132
self.manager.find.assert_called_with(name=self.name)
133+
134+
def test_format_dict(self):
135+
expected = "a='b', c='d', e='f'"
136+
self.assertEqual(expected,
137+
utils.format_dict({'a': 'b', 'c': 'd', 'e': 'f'}))
138+
self.assertEqual(expected,
139+
utils.format_dict({'e': 'f', 'c': 'd', 'a': 'b'}))
140+
141+
def test_format_list(self):
142+
expected = 'a, b, c'
143+
self.assertEqual(expected, utils.format_list(['a', 'b', 'c']))
144+
self.assertEqual(expected, utils.format_list(['c', 'b', 'a']))

0 commit comments

Comments
 (0)