Skip to content

Commit 514ecc6

Browse files
TerryHoweSteve Martinelli
authored andcommitted
Unordered dicts and lists causes variable results
The unordered dict and lists causes variable results. The user may see different results and tests can fail. Might as well make this more consistent. Change-Id: I7045b40b44cbf3ee0f2ca79c6ea0d279b6d8cfe3
1 parent dc68d3f commit 514ecc6

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

‎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)