-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLoadFilesTests.py
More file actions
217 lines (212 loc) · 11.8 KB
/
Copy pathLoadFilesTests.py
File metadata and controls
217 lines (212 loc) · 11.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
from Constants import FIRST_ROUND_QUESTION_PATH,IMAGES_PATH,SECOND_ROUND_QUESTION_PATH,THIRD_ROUND_QUESTION_PATH,AUDIO_PATH
from LoadFiles import LoadFiles
from InvalidArgumentException import InvalidArgumentException
import pydub
import unittest
import pygame
class LoadFilesTests(unittest.TestCase):
def test_load_questions(self):
with self.assertRaises(InvalidArgumentException):
LoadFiles.load_questions('erkjl')
with self.assertRaises(InvalidArgumentException):
LoadFiles.load_questions(56)
with self.assertRaises(ValueError):
LoadFiles.load_questions('D:/Project/Multiplayer/FourthRoundMultiplayer.py')
loaded_files = LoadFiles.load_questions(FIRST_ROUND_QUESTION_PATH)
self.assertEqual(loaded_files,[
{
"question": "What is the capital of France?",
"choices": [
"Berlin",
"Madrid",
"Paris",
"Rome"
],
"answer(s)": [
"Paris"
]
},
{
"question": "Which planet is known as the Red Planet?",
"choices": [
"Venus",
"Mars",
"Jupiter",
"Saturn"
],
"answer(s)": [
"Mars"
]
},
{
"question": "What is the largest ocean on Earth?",
"choices": [
"Atlantic",
"Indian",
"Arctic",
"Pacific"
],
"answer(s)": [
"Pacific"
]
},
{
"question": "Who wrote the play 'Romeo and Juliet'?",
"choices": [
"Charles Dickens",
"William Shakespeare",
"Jane Austen",
"Emily Bronte"
],
"answer(s)": [
"William Shakespeare"
]
},
{
"question": "Which element has the chemical symbol 'O'?",
"choices": [
"Oxygen",
"Osmium",
"Oganesson",
"Osmium"
],
"answer(s)": [
"Oxygen"
]
},
{
"question": "In which year did the United States declare its independence?",
"choices": [
"1776",
"1789",
"1801",
"1756"
],
"answer(s)": [
"1776"
]
},
{
"question": "What is the currency of Japan?",
"choices": [
"Won",
"Yuan",
"Yen",
"Ringgit"
],
"answer(s)": [
"Yen"
]
},
{
"question": "Which famous scientist developed the theory of general relativity?",
"choices": [
"Isaac Newton",
"Albert Einstein",
"Galileo Galilei",
"Stephen Hawking"
],
"answer(s)": [
"Albert Einstein"
]
},
{
"question": "What is the capital of Australia?",
"choices": [
"Sydney",
"Melbourne",
"Canberra",
"Brisbane"
],
"answer(s)": [
"Canberra"
]
},
{
"question": "Which gas makes up the majority of Earth's atmosphere?",
"choices": [
"Oxygen",
"Carbon Dioxide",
"Nitrogen",
"Argon"
],
"answer(s)": [
"Nitrogen"
]
},
{
"question": "Who painted the Mona Lisa?",
"choices": [
"Vincent van Gogh",
"Pablo Picasso",
"Leonardo da Vinci",
"Claude Monet"
],
"answer(s)": [
"Leonardo da Vinci"
]
},
{
"question": "What is the largest mammal in the world?",
"choices": [
"Elephant",
"Blue Whale",
"Giraffe",
"Hippopotamus"
],
"answer(s)": [
"Blue whale"
]
},
{
"question": "Who performs the song 'Vmesto men ?",
"choices": [
"Kaffe",
"Te",
"Tangra",
"Doni i momchil"
],
"answer(s)": [
"Kaffe"
]
}
])
with open('empty_file.json', 'w') as f:
f.write('{}')
loaded_data = LoadFiles.load_questions('empty_file.json')
self.assertEqual(loaded_data, {})
def test_load_multimedia_images(self):
loaded_data = LoadFiles.load_questions(SECOND_ROUND_QUESTION_PATH)
multimedia_data = LoadFiles._LoadFiles__load_multimedia_data(loaded_data,IMAGES_PATH, 'something')
self.assertEqual([],multimedia_data)
multimedia_data = LoadFiles._LoadFiles__load_multimedia_data(loaded_data,IMAGES_PATH, 'images')
with self.assertRaises(BaseException):
LoadFiles._LoadFiles__load_multimedia_data('random',IMAGES_PATH, 'images')
with self.assertRaises(BaseException):
LoadFiles._LoadFiles__load_multimedia_data({'question':5,'random':9,'answer(s)':8},IMAGES_PATH, 'images')
with self.assertRaises(BaseException):
LoadFiles._LoadFiles__load_multimedia_data({'question':5,'random':9,'answer(s)':8},'random', 'images')
self.questions = []
self.answers = []
for entry in loaded_data:
self.questions.append(entry['question'])
self.answers.append(entry['answer(s)'])
multimedia_data = LoadFiles._LoadFiles__load_multimedia_data(loaded_data,IMAGES_PATH, 'images')
for element in multimedia_data:
self.assertIn(element['question'],self.questions)
self.assertIsInstance(element['image'],pygame.Surface)
self.assertIsInstance(element['rect'],pygame.Rect)
self.assertIn(element['answer(s)'],self.answers)
loaded_data = LoadFiles.load_questions(THIRD_ROUND_QUESTION_PATH)
self.questions = []
self.answers = []
for entry in loaded_data:
self.questions.append(entry['question'])
self.answers.append(entry['answer(s)'])
multimedia_data = LoadFiles._LoadFiles__load_multimedia_data(loaded_data,AUDIO_PATH, 'audio-files')
for element in multimedia_data:
self.assertIn(element['question'],self.questions)
self.assertIsInstance(element['audio'],pydub.AudioSegment)
self.assertIn(element['answer(s)'],self.answers)
if __name__=='__main__':
unittest.main()