88import pytest
99import pytest_asyncio
1010
11- import qbreader as qbr
11+ import qbreader as qb
1212from qbreader import Async
1313from tests import async_assert_exception , check_internet_connection
1414
@@ -32,12 +32,12 @@ class TestAsync:
3232 """Test asynchronous API functions."""
3333
3434 @pytest_asyncio .fixture (scope = "class" )
35- async def qb (self ):
35+ async def qbr (self ):
3636 """Create an Async instance shared by all tests."""
3737 return await Async .create ()
3838
3939 @pytest .fixture ()
40- def mock_get (self , monkeypatch , qb ):
40+ def mock_get (self , monkeypatch , qbr ):
4141 """Mock aiohttp.ClientSession.get for Async.session"""
4242
4343 def _set_get (mock_status_code : int = 200 , mock_json = None , * args , ** kwargs ):
@@ -55,7 +55,7 @@ async def json(self):
5555 return mock_json
5656
5757 monkeypatch .setattr (
58- qb .session , "get" , lambda * args , ** kwargs : MockResponse ()
58+ qbr .session , "get" , lambda * args , ** kwargs : MockResponse ()
5959 )
6060
6161 return _set_get
@@ -78,7 +78,7 @@ def test_internet(self):
7878 ),
7979 (
8080 {
81- "questionType" : qbr .Tossup ,
81+ "questionType" : qb .Tossup ,
8282 "setName" : "2023 PACE NSC" ,
8383 "queryString" : "hashes" ,
8484 },
@@ -94,25 +94,25 @@ def test_internet(self):
9494 ),
9595 (
9696 {
97- "questionType" : qbr .Bonus ,
97+ "questionType" : qb .Bonus ,
9898 "setName" : "2023 PACE NSC" ,
9999 "queryString" : "bell labs" ,
100100 },
101101 "C" ,
102102 ),
103103 ],
104104 )
105- async def test_query (self , qb , params : dict [str , Any ], expected_answer : str ):
106- query : qbr .QueryResponse = await qb .query (** params )
105+ async def test_query (self , qbr , params : dict [str , Any ], expected_answer : str ):
106+ query : qbr .QueryResponse = await qbr .query (** params )
107107 judgement : qbr .AnswerJudgement
108108 if params ["questionType" ] == "tossup" :
109109 judgement = await query .tossups [0 ].check_answer_async (
110- expected_answer , session = qb .session
110+ expected_answer , session = qbr .session
111111 )
112112 assert judgement .correct ()
113113 elif params ["questionType" ] == "bonus" :
114114 judgement = await query .bonuses [0 ].check_answer_async (
115- 0 , expected_answer , session = qb .session
115+ 0 , expected_answer , session = qbr .session
116116 )
117117 assert judgement .correct ()
118118
@@ -165,37 +165,39 @@ async def test_query(self, qb, params: dict[str, Any], expected_answer: str):
165165 ],
166166 )
167167 async def test_query_exception (
168- self , qb , params : dict [str , Any ], exception : Exception
168+ self , qbr , params : dict [str , Any ], exception : Exception
169169 ):
170- await async_assert_exception (qb .query , exception , ** params )
170+ await async_assert_exception (qbr .query , exception , ** params )
171171
172172 @pytest .mark .asyncio
173- async def test_query_bad_response (self , qb , mock_get ):
173+ async def test_query_bad_response (self , qbr , mock_get ):
174174 mock_get (mock_status_code = 404 )
175- await async_assert_exception (qb .query , Exception )
175+ await async_assert_exception (qbr .query , Exception )
176176
177177 @pytest .mark .asyncio
178178 @pytest .mark .parametrize ("number" , [1 , 20 , 50 , 100 ])
179- async def test_random_tossup (self , qb , number : int ):
180- assert len (await qb .random_tossup (number = number )) == number
179+ async def test_random_tossup (self , qbr , number : int ):
180+ assert len (await qbr .random_tossup (number = number )) == number
181181
182182 @pytest .mark .asyncio
183183 @pytest .mark .parametrize (
184184 "number, exception" ,
185185 [(0 , ValueError ), (- 1 , ValueError ), ("1" , TypeError ), (1.0 , TypeError )],
186186 )
187- async def test_random_tossup_exception (self , qb , number : int , exception : Exception ):
188- await async_assert_exception (qb .random_tossup , exception , number = number )
187+ async def test_random_tossup_exception (
188+ self , qbr , number : int , exception : Exception
189+ ):
190+ await async_assert_exception (qbr .random_tossup , exception , number = number )
189191
190192 @pytest .mark .asyncio
191- async def test_random_tossup_bad_response (self , qb , mock_get ):
193+ async def test_random_tossup_bad_response (self , qbr , mock_get ):
192194 mock_get (mock_status_code = 404 )
193- await async_assert_exception (qb .random_tossup , Exception )
195+ await async_assert_exception (qbr .random_tossup , Exception )
194196
195197 @pytest .mark .asyncio
196198 @pytest .mark .parametrize ("number" , [1 , 20 , 50 , 100 ])
197- async def test_random_bonus (self , qb , number : int ):
198- assert len (await qb .random_bonus (number = number )) == number
199+ async def test_random_bonus (self , qbr , number : int ):
200+ assert len (await qbr .random_bonus (number = number )) == number
199201
200202 @pytest .mark .asyncio
201203 @pytest .mark .parametrize (
@@ -209,25 +211,25 @@ async def test_random_bonus(self, qb, number: int):
209211 ],
210212 )
211213 async def test_random_bonus_exception (
212- self , qb , number : int , three_part : bool , exception : Exception
214+ self , qbr , number : int , three_part : bool , exception : Exception
213215 ):
214216 await async_assert_exception (
215- qb .random_bonus , exception , number = number , three_part_bonuses = three_part
217+ qbr .random_bonus , exception , number = number , three_part_bonuses = three_part
216218 )
217219
218220 @pytest .mark .asyncio
219- async def test_random_bonus_bad_response (self , qb , mock_get ):
221+ async def test_random_bonus_bad_response (self , qbr , mock_get ):
220222 mock_get (mock_status_code = 404 )
221- await async_assert_exception (qb .random_bonus , Exception )
223+ await async_assert_exception (qbr .random_bonus , Exception )
222224
223225 @pytest .mark .asyncio
224- async def test_random_name (self , qb ):
225- assert await qb .random_name ()
226+ async def test_random_name (self , qbr ):
227+ assert await qbr .random_name ()
226228
227229 @pytest .mark .asyncio
228- async def test_random_name_bad_response (self , qb , mock_get ):
230+ async def test_random_name_bad_response (self , qbr , mock_get ):
229231 mock_get (mock_status_code = 404 )
230- await async_assert_exception (qb .random_name , Exception )
232+ await async_assert_exception (qbr .random_name , Exception )
231233
232234 @pytest .mark .asyncio
233235 @pytest .mark .parametrize (
@@ -252,12 +254,12 @@ async def test_random_name_bad_response(self, qb, mock_get):
252254 ],
253255 )
254256 async def test_packet (
255- self , qb , params : dict [str , Any ], question : int , expected_answer : str
257+ self , qbr , params : dict [str , Any ], question : int , expected_answer : str
256258 ):
257- packet : qbr .Packet = await qb .packet (** params )
259+ packet : qbr .Packet = await qbr .packet (** params )
258260 judgement : qbr .AnswerJudgement = await packet .tossups [
259261 question - 1
260- ].check_answer_async (expected_answer , session = qb .session )
262+ ].check_answer_async (expected_answer , session = qbr .session )
261263 assert judgement .correct ()
262264
263265 @pytest .mark .asyncio
@@ -288,22 +290,22 @@ async def test_packet(
288290 ],
289291 )
290292 async def test_packet_exception (
291- self , qb , params : dict [str , Any ], exception : Exception
293+ self , qbr , params : dict [str , Any ], exception : Exception
292294 ):
293- await async_assert_exception (qb .packet , exception , ** params )
295+ await async_assert_exception (qbr .packet , exception , ** params )
294296
295297 @pytest .mark .asyncio
296- async def test_packet_bad_response (self , qb , monkeypatch , mock_get ):
298+ async def test_packet_bad_response (self , qbr , monkeypatch , mock_get ):
297299 mock_get (mock_status_code = 404 )
298300
299301 async def mock_num_packets (x ):
300302 return 21
301303
302304 monkeypatch .setattr (
303- qb , "num_packets" , mock_num_packets
305+ qbr , "num_packets" , mock_num_packets
304306 ) # mocking get requests breaks num_packets
305307 await async_assert_exception (
306- qb .packet , Exception , setName = "2023 PACE NSC" , packetNumber = 1
308+ qbr .packet , Exception , setName = "2023 PACE NSC" , packetNumber = 1
307309 )
308310
309311 @pytest .mark .asyncio
@@ -329,11 +331,11 @@ async def mock_num_packets(x):
329331 ],
330332 )
331333 async def test_packet_tossups (
332- self , qb , params : dict [str , Any ], question : int , expected_answer : str
334+ self , qbr , params : dict [str , Any ], question : int , expected_answer : str
333335 ):
334- tus = await qb .packet_tossups (** params )
336+ tus = await qbr .packet_tossups (** params )
335337 judgement : qbr .AnswerJudgement = await tus [question - 1 ].check_answer_async (
336- expected_answer , session = qb .session
338+ expected_answer , session = qbr .session
337339 )
338340 assert judgement .correct ()
339341
@@ -365,22 +367,22 @@ async def test_packet_tossups(
365367 ],
366368 )
367369 async def test_packet_tossups_exception (
368- self , qb , params : dict [str , Any ], exception : Exception
370+ self , qbr , params : dict [str , Any ], exception : Exception
369371 ):
370- await async_assert_exception (qb .packet_tossups , exception , ** params )
372+ await async_assert_exception (qbr .packet_tossups , exception , ** params )
371373
372374 @pytest .mark .asyncio
373- async def test_packet_tossups_bad_response (self , qb , monkeypatch , mock_get ):
375+ async def test_packet_tossups_bad_response (self , qbr , monkeypatch , mock_get ):
374376 mock_get (mock_status_code = 404 )
375377
376378 async def mock_num_packets (x ):
377379 return 21
378380
379381 monkeypatch .setattr (
380- qb , "num_packets" , mock_num_packets
382+ qbr , "num_packets" , mock_num_packets
381383 ) # mocking get requests breaks num_packets
382384 await async_assert_exception (
383- qb .packet_tossups , Exception , setName = "2023 PACE NSC" , packetNumber = 1
385+ qbr .packet_tossups , Exception , setName = "2023 PACE NSC" , packetNumber = 1
384386 )
385387
386388 @pytest .mark .asyncio
@@ -406,11 +408,11 @@ async def mock_num_packets(x):
406408 ],
407409 )
408410 async def test_packet_bonuses (
409- self , qb , params : dict [str , Any ], question : int , expected_answer : str
411+ self , qbr , params : dict [str , Any ], question : int , expected_answer : str
410412 ):
411- bs = await qb .packet_bonuses (** params )
413+ bs = await qbr .packet_bonuses (** params )
412414 judgement : qbr .AnswerJudgement = await bs [question - 1 ].check_answer_async (
413- 0 , expected_answer , session = qb .session
415+ 0 , expected_answer , session = qbr .session
414416 )
415417 assert judgement .correct ()
416418
@@ -442,69 +444,71 @@ async def test_packet_bonuses(
442444 ],
443445 )
444446 async def test_packet_bonuses_exception (
445- self , qb , params : dict [str , Any ], exception : Exception
447+ self , qbr , params : dict [str , Any ], exception : Exception
446448 ):
447- await async_assert_exception (qb .packet_bonuses , exception , ** params )
449+ await async_assert_exception (qbr .packet_bonuses , exception , ** params )
448450
449451 @pytest .mark .asyncio
450- async def test_packet_bonuses_bad_response (self , qb , monkeypatch , mock_get ):
452+ async def test_packet_bonuses_bad_response (self , qbr , monkeypatch , mock_get ):
451453 mock_get (mock_status_code = 404 )
452454
453455 async def mock_num_packets (x ):
454456 return 21
455457
456458 monkeypatch .setattr (
457- qb , "num_packets" , mock_num_packets
459+ qbr , "num_packets" , mock_num_packets
458460 ) # mocking get requests breaks num_packets
459461 await async_assert_exception (
460- qb .packet_bonuses , Exception , setName = "2023 PACE NSC" , packetNumber = 1
462+ qbr .packet_bonuses , Exception , setName = "2023 PACE NSC" , packetNumber = 1
461463 )
462464
463465 @pytest .mark .asyncio
464466 @pytest .mark .parametrize (
465467 "setName, expected" ,
466468 [("2023 PACE NSC" , 21 ), ("2022 SHOW-ME" , 15 )],
467469 )
468- async def test_num_packets (self , qb , setName : str , expected : int ):
469- assert await qb .num_packets (setName ) == expected
470+ async def test_num_packets (self , qbr , setName : str , expected : int ):
471+ assert await qbr .num_packets (setName ) == expected
470472
471473 @pytest .mark .asyncio
472- async def test_num_packets_bad_response (self , qb , mock_get ):
474+ async def test_num_packets_bad_response (self , qbr , mock_get ):
473475 await async_assert_exception (
474- qb .num_packets , ValueError , setName = "not a set name"
476+ qbr .num_packets , ValueError , setName = "not a set name"
475477 )
476478 mock_get (mock_status_code = 400 )
477- await async_assert_exception (qb .num_packets , Exception , setName = "2023 PACE NSC" )
479+ await async_assert_exception (
480+ qbr .num_packets , Exception , setName = "2023 PACE NSC"
481+ )
478482
479483 @pytest .mark .asyncio
480- async def test_set_list (self , qb ):
481- assert await qb .set_list ()
484+ async def test_set_list (self , qbr ):
485+ assert await qbr .set_list ()
482486
483487 @pytest .mark .asyncio
484- async def test_set_list_bad_response (self , qb , mock_get ):
488+ async def test_set_list_bad_response (self , qbr , mock_get ):
485489 mock_get (mock_status_code = 404 )
486- await async_assert_exception (qb .set_list , Exception )
490+ await async_assert_exception (qbr .set_list , Exception )
487491
488492 @pytest .mark .asyncio
489- async def test_room_list (self , qb ):
490- assert await qb .room_list ()
493+ async def test_room_list (self , qbr ):
494+ assert await qbr .room_list ()
491495
492496 @pytest .mark .asyncio
493- async def test_room_list_bad_response (self , qb , mock_get ):
497+ async def test_room_list_bad_response (self , qbr , mock_get ):
494498 mock_get (mock_status_code = 404 )
495- await async_assert_exception (qb .room_list , Exception )
499+ await async_assert_exception (qbr .room_list , Exception )
496500
497501 @pytest .mark .asyncio
498502 @pytest .mark .parametrize (
499503 "answerline, givenAnswer" ,
500504 [("Rubik's cubes [prompt on cubes and speedcubing]" , "Rubik's cubes" )],
501505 )
502- async def test_check_answer (self , qb , answerline : str , givenAnswer : str ):
503- judgement : qbr .AnswerJudgement = await qb .check_answer (
506+ async def test_check_answer (self , qbr , answerline : str , givenAnswer : str ):
507+ judgement : qb .AnswerJudgement = await qbr .check_answer (
504508 answerline = answerline , givenAnswer = givenAnswer
505509 )
506510 assert judgement .correct ()
507- judgement = await qbr .AnswerJudgement .check_answer_async (
511+ judgement = await qb .AnswerJudgement .check_answer_async (
508512 answerline = answerline , givenAnswer = givenAnswer
509513 ) # testing no session provided
510514 assert judgement .correct ()
@@ -518,33 +522,33 @@ async def test_check_answer(self, qb, answerline: str, givenAnswer: str):
518522 ],
519523 )
520524 async def test_check_answer_exception (
521- self , qb , answerline : str , givenAnswer : str , exception : Exception
525+ self , qbr , answerline : str , givenAnswer : str , exception : Exception
522526 ):
523527 await async_assert_exception (
524- qb .check_answer , exception , answerline , givenAnswer
528+ qbr .check_answer , exception , answerline , givenAnswer
525529 )
526530 await async_assert_exception (
527- qbr .AnswerJudgement .check_answer_async , exception , answerline , givenAnswer
531+ qb .AnswerJudgement .check_answer_async , exception , answerline , givenAnswer
528532 )
529533
530534 @pytest .mark .asyncio
531- async def test_check_answer_bad_response (self , qb , mock_get ):
535+ async def test_check_answer_bad_response (self , qbr , mock_get ):
532536 mock_get (mock_status_code = 404 )
533537 await async_assert_exception (
534- qb .check_answer ,
538+ qbr .check_answer ,
535539 Exception ,
536540 answerline = "Rubik's cubes" ,
537541 givenAnswer = "Rubik's cubes" ,
538542 )
539543
540544 @pytest .mark .asyncio
541- async def test_close (self , qb ):
542- await qb .close ()
543- assert qb .session .closed
545+ async def test_close (self , qbr ):
546+ await qbr .close ()
547+ assert qbr .session .closed
544548
545549 @pytest .mark .asyncio
546550 async def test_async_with (self ):
547- qb = await Async .create ()
548- async with qb :
549- assert qb .session
550- assert qb .session .closed
551+ qbr = await Async .create ()
552+ async with qbr :
553+ assert qbr .session
554+ assert qbr .session .closed
0 commit comments