@@ -45,7 +45,13 @@ class MockResponse:
4545 def __init__ (self ):
4646 self .status = mock_status_code
4747
48- def json (self ):
48+ async def __aenter__ (self ):
49+ return self
50+
51+ async def __aexit__ (self , exc_type , exc_val , exc_tb ):
52+ pass
53+
54+ async def json (self ):
4955 return mock_json
5056
5157 monkeypatch .setattr (
@@ -289,8 +295,12 @@ async def test_packet_exception(
289295 @pytest .mark .asyncio
290296 async def test_packet_bad_response (self , qb , monkeypatch , mock_get ):
291297 mock_get (mock_status_code = 404 )
298+
299+ async def mock_num_packets (x ):
300+ return 21
301+
292302 monkeypatch .setattr (
293- qb , "num_packets" , lambda x : 21
303+ qb , "num_packets" , mock_num_packets
294304 ) # mocking get requests breaks num_packets
295305 await async_assert_exception (
296306 qb .packet , Exception , setName = "2023 PACE NSC" , packetNumber = 1
@@ -362,8 +372,12 @@ async def test_packet_tossups_exception(
362372 @pytest .mark .asyncio
363373 async def test_packet_tossups_bad_response (self , qb , monkeypatch , mock_get ):
364374 mock_get (mock_status_code = 404 )
375+
376+ async def mock_num_packets (x ):
377+ return 21
378+
365379 monkeypatch .setattr (
366- qb , "num_packets" , lambda x : 21
380+ qb , "num_packets" , mock_num_packets
367381 ) # mocking get requests breaks num_packets
368382 await async_assert_exception (
369383 qb .packet_tossups , Exception , setName = "2023 PACE NSC" , packetNumber = 1
@@ -435,8 +449,12 @@ async def test_packet_bonuses_exception(
435449 @pytest .mark .asyncio
436450 async def test_packet_bonuses_bad_response (self , qb , monkeypatch , mock_get ):
437451 mock_get (mock_status_code = 404 )
452+
453+ async def mock_num_packets (x ):
454+ return 21
455+
438456 monkeypatch .setattr (
439- qb , "num_packets" , lambda x : 21
457+ qb , "num_packets" , mock_num_packets
440458 ) # mocking get requests breaks num_packets
441459 await async_assert_exception (
442460 qb .packet_bonuses , Exception , setName = "2023 PACE NSC" , packetNumber = 1
@@ -491,3 +509,10 @@ async def test_check_answer(self, qb, answerline: str, givenAnswer: str):
491509 async def test_close (self , qb ):
492510 await qb .close ()
493511 assert qb .session .closed
512+
513+ @pytest .mark .asyncio
514+ async def test_async_with (self ):
515+ qb = await Async .create ()
516+ async with qb :
517+ assert qb .session
518+ assert qb .session .closed
0 commit comments