Merge pull request #21919 from edx/BOM-819
Updated the items order in response list comparison to work with both python versions - BOM-819
This commit is contained in:
@@ -38,15 +38,14 @@ class WordCloudModuleTest(LogicTest):
|
||||
response['student_words'],
|
||||
{'sun': 1, 'dog': 6, 'cat': 12}
|
||||
)
|
||||
|
||||
self.assertListEqual(
|
||||
response['top_words'],
|
||||
[{'text': 'dad', 'size': 2, 'percent': 9.0},
|
||||
{'text': 'sun', 'size': 1, 'percent': 5.0},
|
||||
[{'text': 'cat', 'size': 12, 'percent': 55.0},
|
||||
{'text': 'dad', 'size': 2, 'percent': 9.0},
|
||||
{'text': 'dog', 'size': 6, 'percent': 27.0},
|
||||
{'text': 'mom', 'size': 1, 'percent': 5.0},
|
||||
{'text': 'cat', 'size': 12, 'percent': 54.0}]
|
||||
{'text': 'sun', 'size': 1, 'percent': 4.0}]
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
100.0,
|
||||
sum(i['percent'] for i in response['top_words']))
|
||||
self.assertEqual(100.0, sum(i['percent'] for i in response['top_words']))
|
||||
|
||||
@@ -148,11 +148,12 @@ class WordCloudModule(WordCloudFields, XModule):
|
||||
"""
|
||||
list_to_return = []
|
||||
percents = 0
|
||||
for num, word_tuple in enumerate(six.iteritems(top_words)):
|
||||
sorted_top_words = sorted(top_words.items(), key=lambda x: x[0].lower())
|
||||
for num, word_tuple in enumerate(sorted_top_words):
|
||||
if num == len(top_words) - 1:
|
||||
percent = 100 - percents
|
||||
else:
|
||||
percent = round(100.0 * word_tuple[1] / total_count)
|
||||
percent = round((100.0 * word_tuple[1]) / total_count)
|
||||
percents += percent
|
||||
list_to_return.append(
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user