Skip to content

Commit

Permalink
Coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
charles-turner-1 committed Jan 24, 2025
1 parent 9d3b9be commit 4d83e74
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/access_py_telemetry/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ def request_timeout(self, timeout: float | None) -> None:
if timeout is None:
self._request_timeout = None
return None
elif timeout <= 0:
if not isinstance(timeout, (int, float)):
raise TypeError("Timeout must be a number")
elif timeout <= 0 or not isinstance(timeout, (int, float)):
raise ValueError("Timeout must be a positive number")

self._request_timeout = timeout
Expand Down
22 changes: 20 additions & 2 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,5 +261,23 @@ def test_api_handler_invalid_endpoint(api_handler):

assert "Endpoint for 'payu' not found " in str(excinfo.value)

ApiHandler._instance = None
api_handler._instance = None

def test_api_handler_set_timeout(api_handler):
"""
Make sure that we can set the timeout for the APIHandler class, and that it
is either a positive float or None.
"""

with pytest.raises(ValueError):
api_handler.request_timeout = -1

with pytest.raises(TypeError):
api_handler.request_timeout = "string"

api_handler.request_timeout = 1.0

assert api_handler.request_timeout == 1.0

api_handler.request_timeout = None

assert api_handler.request_timeout is None

0 comments on commit 4d83e74

Please sign in to comment.