Skip to content

Commit 976ba03

Browse files
committed
fix typing, update tests, add test for retries
1 parent 5f03bef commit 976ba03

2 files changed

Lines changed: 23 additions & 7 deletions

File tree

src/groundlight/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ def _user_is_privileged(self) -> bool:
273273
def get_detector(
274274
self,
275275
id: Union[str, Detector],
276-
request_timeout: Optional[float] = None,
276+
request_timeout: Optional[Union[float, Tuple[float, float]]] = None,
277277
) -> Detector: # pylint: disable=redefined-builtin
278278
"""
279279
Get a Detector by id.
@@ -675,7 +675,7 @@ def submit_image_query( # noqa: PLR0913 # pylint: disable=too-many-arguments, t
675675
inspection_id: Optional[str] = None,
676676
metadata: Union[dict, str, None] = None,
677677
image_query_id: Optional[str] = None,
678-
request_timeout: Optional[float] = None,
678+
request_timeout: Optional[Union[float, Tuple[float, float]]] = None,
679679
) -> ImageQuery:
680680
"""
681681
Evaluates an image with Groundlight. This is the core method for getting predictions about images.

test/integration/test_groundlight.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
PaginatedDetectorList,
2828
PaginatedImageQueryList,
2929
)
30-
from urllib3.exceptions import ReadTimeoutError
30+
from urllib3.exceptions import MaxRetryError
31+
from urllib3.util.retry import Retry
3132

3233
DEFAULT_CONFIDENCE_THRESHOLD = 0.9
3334
IQ_IMPROVEMENT_THRESHOLD = 0.75
@@ -80,6 +81,21 @@ def fixture_image() -> str:
8081
return "test/assets/dog.jpeg"
8182

8283

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+
8399
def test_create_detector(gl: Groundlight):
84100
name = f"Test {datetime.utcnow()}" # Need a unique name
85101
query = "Is there a dog?"
@@ -227,12 +243,12 @@ def test_get_detector_with_low_request_timeout(gl: Groundlight, detector: Detect
227243
Verifies that get_detector respects the request_timeout parameter and raises a ReadTimeoutError when timeout is
228244
exceeded. Verifies that request_timeout parameter can be a float or a tuple.
229245
"""
230-
with pytest.raises(ReadTimeoutError):
246+
with pytest.raises(MaxRetryError):
231247
# Setting a very low request_timeout value should result in a timeout.
232248
# NOTE: request_timeout=0 seems to have special behavior that does not result in a timeout.
233249
gl.get_detector(id=detector.id, request_timeout=1e-8)
234250

235-
with pytest.raises(ReadTimeoutError):
251+
with pytest.raises(MaxRetryError):
236252
# Ensure a tuple can be passed.
237253
gl.get_detector(id=detector.id, request_timeout=(1e-8, 1e-8))
238254

@@ -370,12 +386,12 @@ def test_submit_image_query_with_low_request_timeout(gl: Groundlight, detector:
370386
Verifies that submit_image_query respects the request_timeout parameter and raises a ReadTimeoutError when timeout is
371387
exceeded. Verifies that request_timeout parameter can be a float or a tuple.
372388
"""
373-
with pytest.raises(ReadTimeoutError):
389+
with pytest.raises(MaxRetryError):
374390
# Setting a very low request_timeout value should result in a timeout.
375391
# NOTE: request_timeout=0 seems to have special behavior that does not result in a timeout.
376392
gl.submit_image_query(detector=detector, image=image, human_review="NEVER", request_timeout=1e-8)
377393

378-
with pytest.raises(ReadTimeoutError):
394+
with pytest.raises(MaxRetryError):
379395
# Ensure a tuple can be passed.
380396
gl.submit_image_query(detector=detector, image=image, human_review="NEVER", request_timeout=(1e-8, 1e-8))
381397

0 commit comments

Comments
 (0)