Fix incorrect initialization of OrderedDict

According to the doc[1], initialize OrderedDict as below won't
perserve the order:

  collections.OrderedDict({...})

This causes occasional failures of the tests. This patch changed it
to:

  collections.OrderedDict([...])

[1] https://docs.python.org/3/library/collections.html#
ordereddict-objects

Change-Id: I863f9d2879a6c119501fe1d5175ecb8a70e7e9f1
Closes-Bug: #1556475
This commit is contained in:
Hongbin Lu 2016-03-12 13:37:29 -05:00
parent a5381cdd2f
commit c991639a6b
1 changed files with 11 additions and 8 deletions

View File

@ -187,15 +187,18 @@ class CliUtilsTest(test_utils.BaseTestCase):
six.u('z'): six.u('3')},
'c': 7}
dict_exp = collections.OrderedDict(
{'a': '1',
'b': collections.OrderedDict({'x': 1, 'y': '2', 'z': '3'}),
'c': 7})
dict_exp = collections.OrderedDict([
('a', '1'),
('b', collections.OrderedDict([
('x', 1),
('y', '2'),
('z', '3')])),
('c', 7)])
dict_out = cliutils.keys_and_vals_to_strs(dict_in)
dict_act = collections.OrderedDict(
{'a': dict_out['a'],
'b': collections.OrderedDict(dict_out['b']),
'c': dict_out['c']})
dict_act = collections.OrderedDict([
('a', dict_out['a']),
('b', collections.OrderedDict(sorted(dict_out['b'].items()))),
('c', dict_out['c'])])
self.assertEqual(six.text_type(dict_exp), six.text_type(dict_act))