3
3
'''
4
4
5
5
import unittest
6
- from unittest import mock
7
6
from unittest .mock import patch , Mock
8
7
import requests
9
8
@@ -194,6 +193,23 @@ def test_run_sync(self, mock_client_request):
194
193
195
194
self .assertEqual (run_request , {"result" : "YOUR_MODEL_OUTPUT_VALUE" })
196
195
196
+ @patch .object (runpod .endpoint .runner .RunPodClient , '_request' )
197
+ def test_run_sync_with_timeout (self , mock_client_request ):
198
+ '''
199
+ Tests Endpoint.run_sync with timeout
200
+ '''
201
+ mock_client_request .return_value = {
202
+ "id" : "123" ,
203
+ "status" : "IN_PROGRESS"
204
+ }
205
+
206
+ runpod .api_key = "MOCK_API_KEY"
207
+ endpoint = runpod .Endpoint ("ENDPOINT_ID" )
208
+
209
+ request_data = {"YOUR_MODEL_INPUT_JSON" : "YOUR_MODEL_INPUT_VALUE" }
210
+ with self .assertRaises (TimeoutError ):
211
+ endpoint .run_sync (request_data , timeout = 1 )
212
+
197
213
198
214
class TestJob (unittest .TestCase ):
199
215
''' Tests for Job '''
@@ -245,6 +261,19 @@ def test_output_with_sleep(self, mock_client):
245
261
246
262
self .assertEqual (output , "Job output" )
247
263
264
+ @patch ('runpod.endpoint.runner.RunPodClient' )
265
+ def test_output_timeout (self , mock_client ):
266
+ '''
267
+ Tests Job.output with timeout
268
+ '''
269
+ mock_client .get .return_value = {
270
+ "status" : "IN_PROGRESS"
271
+ }
272
+
273
+ job = runner .Job ("endpoint_id" , "job_id" , mock_client )
274
+ with self .assertRaises (TimeoutError ):
275
+ job .output (timeout = 1 )
276
+
248
277
@patch ('runpod.endpoint.runner.RunPodClient' )
249
278
def test_job_status (self , mock_client ):
250
279
'''
@@ -262,3 +291,4 @@ def test_job_status(self, mock_client):
262
291
job = runner .Job ("endpoint_id" , "job_id" , mock_client )
263
292
self .assertEqual (job .status (), "IN_PROGRESS" )
264
293
self .assertEqual (job .status (), "COMPLETED" )
294
+ self .assertEqual (job .status (), "COMPLETED" )
0 commit comments