@@ -214,24 +214,46 @@ async def test_job_with_exception(self):
214
214
class TestRunJobGenerator (IsolatedAsyncioTestCase ):
215
215
''' Tests the run_job_generator function '''
216
216
217
- def handler_success (self , job ): # pylint: disable=unused-argument
217
+ def handler_gen_success (self , job ): # pylint: disable=unused-argument
218
218
'''
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.
220
227
'''
221
228
yield "partial_output_1"
222
229
yield "partial_output_2"
223
230
224
231
def handler_fail (self , job ):
225
232
'''
226
- Test handler that raises an exception
233
+ Test handler that raises an exception.
227
234
'''
228
235
raise Exception ("Test Exception" ) # pylint: disable=broad-exception-raised
229
236
230
237
async def test_run_job_generator_success (self ):
231
238
'''
232
239
Tests the run_job_generator function with a successful generator
233
240
'''
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
235
257
job = {"id" : "123" }
236
258
237
259
with patch ("runpod.serverless.modules.rp_job.log" , new_callable = Mock ) as mock_log :
0 commit comments