(self)
| 357 | client.close() |
| 358 | |
| 359 | def test_http_client_timeout_option(self) -> None: |
| 360 | # custom timeout given to the httpx client should be used |
| 361 | with httpx.Client(timeout=None) as http_client: |
| 362 | client = OpenAI( |
| 363 | base_url=base_url, |
| 364 | api_key=api_key, |
| 365 | admin_api_key=admin_api_key, |
| 366 | _strict_response_validation=True, |
| 367 | http_client=http_client, |
| 368 | ) |
| 369 | |
| 370 | request = client._build_request(FinalRequestOptions(method="get", url="/foo")) |
| 371 | timeout = httpx.Timeout(**request.extensions["timeout"]) # type: ignore |
| 372 | assert timeout == httpx.Timeout(None) |
| 373 | |
| 374 | client.close() |
| 375 | |
| 376 | # no timeout given to the httpx client should not use the httpx default |
| 377 | with httpx.Client() as http_client: |
| 378 | client = OpenAI( |
| 379 | base_url=base_url, |
| 380 | api_key=api_key, |
| 381 | admin_api_key=admin_api_key, |
| 382 | _strict_response_validation=True, |
| 383 | http_client=http_client, |
| 384 | ) |
| 385 | |
| 386 | request = client._build_request(FinalRequestOptions(method="get", url="/foo")) |
| 387 | timeout = httpx.Timeout(**request.extensions["timeout"]) # type: ignore |
| 388 | assert timeout == DEFAULT_TIMEOUT |
| 389 | |
| 390 | client.close() |
| 391 | |
| 392 | # explicitly passing the default timeout currently results in it being ignored |
| 393 | with httpx.Client(timeout=HTTPX_DEFAULT_TIMEOUT) as http_client: |
| 394 | client = OpenAI( |
| 395 | base_url=base_url, |
| 396 | api_key=api_key, |
| 397 | admin_api_key=admin_api_key, |
| 398 | _strict_response_validation=True, |
| 399 | http_client=http_client, |
| 400 | ) |
| 401 | |
| 402 | request = client._build_request(FinalRequestOptions(method="get", url="/foo")) |
| 403 | timeout = httpx.Timeout(**request.extensions["timeout"]) # type: ignore |
| 404 | assert timeout == DEFAULT_TIMEOUT # our default |
| 405 | |
| 406 | client.close() |
| 407 | |
| 408 | async def test_invalid_http_client(self) -> None: |
| 409 | with pytest.raises(TypeError, match="Invalid `http_client` arg"): |
nothing calls this directly
no test coverage detected