diff --git a/src/access_py_telemetry/api.py b/src/access_py_telemetry/api.py index 679cca1..157023d 100644 --- a/src/access_py_telemetry/api.py +++ b/src/access_py_telemetry/api.py @@ -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 diff --git a/tests/test_api.py b/tests/test_api.py index 27377ac..5f65fe1 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -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