summarize_items(): sort format by decr. freq

Make the summary deterministic.
This commit is contained in:
Bruno Cauet 2015-03-16 14:41:43 +01:00
parent 1e2d481ac0
commit 8e25a70e40
2 changed files with 7 additions and 3 deletions

View file

@ -437,8 +437,9 @@ def summarize_items(items, singleton):
# A single format.
summary_parts.append(items[0].format)
else:
# Enumerate all the formats.
for fmt, count in format_counts.iteritems():
# Enumerate all the formats by decreasing frequencies:
for fmt, count in sorted(format_counts.items(),
key=lambda (f, c): (-c, f)):
summary_parts.append('{0} {1}'.format(fmt, count))
if items:

View file

@ -1005,7 +1005,10 @@ class SummarizeItemsTest(_common.TestCase):
i2.format = "G"
summary = commands.summarize_items([self.item, i2], False)
self.assertEqual(summary, "2 items, G 1, F 1, 4kbps, 21:48, 1.9 KB")
self.assertEqual(summary, "2 items, F 1, G 1, 4kbps, 21:48, 1.9 KB")
summary = commands.summarize_items([self.item, i2, i2], False)
self.assertEqual(summary, "3 items, G 2, F 1, 4kbps, 32:42, 2.9 KB")
class PathFormatTest(_common.TestCase):