|
27 | 27 | PaginatedDetectorList, |
28 | 28 | PaginatedImageQueryList, |
29 | 29 | ) |
30 | | -from urllib3.exceptions import ReadTimeoutError |
| 30 | +from urllib3.exceptions import MaxRetryError |
| 31 | +from urllib3.util.retry import Retry |
31 | 32 |
|
32 | 33 | DEFAULT_CONFIDENCE_THRESHOLD = 0.9 |
33 | 34 | IQ_IMPROVEMENT_THRESHOLD = 0.75 |
@@ -80,6 +81,21 @@ def fixture_image() -> str: |
80 | 81 | return "test/assets/dog.jpeg" |
81 | 82 |
|
82 | 83 |
|
| 84 | +def test_create_groundlight_with_retries(): |
| 85 | + """Verify that the `retries` parameter can be successfully passed to the `Groundlight` constructor.""" |
| 86 | + # Set retries using int value |
| 87 | + num_retries = 25 |
| 88 | + gl = Groundlight(retries=num_retries) |
| 89 | + assert gl.configuration.retries == num_retries |
| 90 | + assert gl.api_client.configuration.retries == num_retries |
| 91 | + |
| 92 | + # Set retries using Retry object |
| 93 | + retries = Retry(total=num_retries) |
| 94 | + gl = Groundlight(retries=retries) |
| 95 | + assert gl.configuration.retries.total == retries.total |
| 96 | + assert gl.api_client.configuration.retries.total == retries.total |
| 97 | + |
| 98 | + |
83 | 99 | def test_create_detector(gl: Groundlight): |
84 | 100 | name = f"Test {datetime.utcnow()}" # Need a unique name |
85 | 101 | query = "Is there a dog?" |
@@ -227,12 +243,12 @@ def test_get_detector_with_low_request_timeout(gl: Groundlight, detector: Detect |
227 | 243 | Verifies that get_detector respects the request_timeout parameter and raises a ReadTimeoutError when timeout is |
228 | 244 | exceeded. Verifies that request_timeout parameter can be a float or a tuple. |
229 | 245 | """ |
230 | | - with pytest.raises(ReadTimeoutError): |
| 246 | + with pytest.raises(MaxRetryError): |
231 | 247 | # Setting a very low request_timeout value should result in a timeout. |
232 | 248 | # NOTE: request_timeout=0 seems to have special behavior that does not result in a timeout. |
233 | 249 | gl.get_detector(id=detector.id, request_timeout=1e-8) |
234 | 250 |
|
235 | | - with pytest.raises(ReadTimeoutError): |
| 251 | + with pytest.raises(MaxRetryError): |
236 | 252 | # Ensure a tuple can be passed. |
237 | 253 | gl.get_detector(id=detector.id, request_timeout=(1e-8, 1e-8)) |
238 | 254 |
|
@@ -370,12 +386,12 @@ def test_submit_image_query_with_low_request_timeout(gl: Groundlight, detector: |
370 | 386 | Verifies that submit_image_query respects the request_timeout parameter and raises a ReadTimeoutError when timeout is |
371 | 387 | exceeded. Verifies that request_timeout parameter can be a float or a tuple. |
372 | 388 | """ |
373 | | - with pytest.raises(ReadTimeoutError): |
| 389 | + with pytest.raises(MaxRetryError): |
374 | 390 | # Setting a very low request_timeout value should result in a timeout. |
375 | 391 | # NOTE: request_timeout=0 seems to have special behavior that does not result in a timeout. |
376 | 392 | gl.submit_image_query(detector=detector, image=image, human_review="NEVER", request_timeout=1e-8) |
377 | 393 |
|
378 | | - with pytest.raises(ReadTimeoutError): |
| 394 | + with pytest.raises(MaxRetryError): |
379 | 395 | # Ensure a tuple can be passed. |
380 | 396 | gl.submit_image_query(detector=detector, image=image, human_review="NEVER", request_timeout=(1e-8, 1e-8)) |
381 | 397 |
|
|
0 commit comments