Fix the disorder of items of Traits in the output of event-list
When use the command ceilometer event-list, the output is not alwarys ordered. This patch fix it. Closes-Bug: #1553932 Change-Id: I3af0fb25bd09ea9f15584219f07dd24ebb77c1cc
This commit is contained in:
parent
844bf19be0
commit
8ce8b801be
|
@ -104,6 +104,9 @@ def format_nested_list_of_dict(l, column_names):
|
|||
pt = prettytable.PrettyTable(caching=False, print_empty=False,
|
||||
header=True, hrules=prettytable.FRAME,
|
||||
field_names=column_names)
|
||||
# Sort by values of first column
|
||||
if l is not None:
|
||||
l.sort(key=lambda k: k.get(column_names[0]))
|
||||
for d in l:
|
||||
pt.add_row(list(map(lambda k: d[k], column_names)))
|
||||
return pt.get_string()
|
||||
|
|
|
@ -283,14 +283,16 @@ l2"]}] |
|
|||
table.get_string.return_value = "the table"
|
||||
|
||||
test_data = [
|
||||
{'column_1': 'value_11', 'column_2': 'value_21'},
|
||||
{'column_1': 'value_12', 'column_2': 'value_22'}
|
||||
|
||||
{'column_1': 'value_c', 'column_2': 'value_23'},
|
||||
{'column_1': 'value_b', 'column_2': 'value_22'},
|
||||
{'column_1': 'value_a', 'column_2': 'value_21'}
|
||||
]
|
||||
columns = ['column_1', 'column_2']
|
||||
pt_mock.return_value = table
|
||||
|
||||
rval = utils.format_nested_list_of_dict(test_data, columns)
|
||||
self.assertEqual("the table", rval)
|
||||
self.assertEqual([['value_11', 'value_21'], ['value_12', 'value_22']],
|
||||
self.assertEqual([['value_a', 'value_21'],
|
||||
['value_b', 'value_22'],
|
||||
['value_c', 'value_23']],
|
||||
actual_rows)
|
||||
|
|
Loading…
Reference in New Issue