Skip to content
Snippets Groups Projects
Unverified Commit 4bce520f authored by Aarif's avatar Aarif Committed by GitHub
Browse files

Merge pull request #21919 from edx/BOM-819

Updated the items order in response list comparison to work with both python versions - BOM-819
parents c7cb9957 8e816fc8
No related branches found
No related tags found
No related merge requests found
......@@ -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(
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment