@@ -214,24 +214,46 @@ async def test_job_with_exception(self):
214214class TestRunJobGenerator (IsolatedAsyncioTestCase ):
215215 ''' Tests the run_job_generator function '''
216216
217- def handler_success (self , job ): # pylint: disable=unused-argument
217+ def handler_gen_success (self , job ): # pylint: disable=unused-argument
218218 '''
219- Test handler that returns a generator
219+ Test handler that returns a generator.
220+ '''
221+ yield "partial_output_1"
222+ yield "partial_output_2"
223+
224+ async def handler_async_gen_success (self , job ): # pylint: disable=unused-argument
225+ '''
226+ Test handler that returns an async generator.
220227 '''
221228 yield "partial_output_1"
222229 yield "partial_output_2"
223230
224231 def handler_fail (self , job ):
225232 '''
226- Test handler that raises an exception
233+ Test handler that raises an exception.
227234 '''
228235 raise Exception ("Test Exception" ) # pylint: disable=broad-exception-raised
229236
230237 async def test_run_job_generator_success (self ):
231238 '''
232239 Tests the run_job_generator function with a successful generator
233240 '''
234- handler = self .handler_success
241+ handler = self .handler_gen_success
242+ job = {"id" : "123" }
243+
244+ with patch ("runpod.serverless.modules.rp_job.log" , new_callable = Mock ) as mock_log :
245+ result = [i async for i in rp_job .run_job_generator (handler , job )]
246+
247+ assert result == [{"output" : "partial_output_1" }, {"output" : "partial_output_2" }]
248+ assert mock_log .error .call_count == 0
249+ assert mock_log .info .call_count == 1
250+ mock_log .info .assert_called_with ('123 | Finished ' )
251+
252+ async def test_run_job_generator_success_async (self ):
253+ '''
254+ Tests the run_job_generator function with a successful generator
255+ '''
256+ handler = self .handler_async_gen_success
235257 job = {"id" : "123" }
236258
237259 with patch ("runpod.serverless.modules.rp_job.log" , new_callable = Mock ) as mock_log :
0 commit comments