(self)
| 1622 | await client.close() |
| 1623 | |
| 1624 | async def test_http_client_timeout_option(self) -> None: |
| 1625 | # custom timeout given to the httpx client should be used |
| 1626 | async with httpx.AsyncClient(timeout=None) as http_client: |
| 1627 | client = AsyncOpenAI( |
| 1628 | base_url=base_url, |
| 1629 | api_key=api_key, |
| 1630 | admin_api_key=admin_api_key, |
| 1631 | _strict_response_validation=True, |
| 1632 | http_client=http_client, |
| 1633 | ) |
| 1634 | |
| 1635 | request = client._build_request(FinalRequestOptions(method="get", url="/foo")) |
| 1636 | timeout = httpx.Timeout(**request.extensions["timeout"]) # type: ignore |
| 1637 | assert timeout == httpx.Timeout(None) |
| 1638 | |
| 1639 | await client.close() |
| 1640 | |
| 1641 | # no timeout given to the httpx client should not use the httpx default |
| 1642 | async with httpx.AsyncClient() as http_client: |
| 1643 | client = AsyncOpenAI( |
| 1644 | base_url=base_url, |
| 1645 | api_key=api_key, |
| 1646 | admin_api_key=admin_api_key, |
| 1647 | _strict_response_validation=True, |
| 1648 | http_client=http_client, |
| 1649 | ) |
| 1650 | |
| 1651 | request = client._build_request(FinalRequestOptions(method="get", url="/foo")) |
| 1652 | timeout = httpx.Timeout(**request.extensions["timeout"]) # type: ignore |
| 1653 | assert timeout == DEFAULT_TIMEOUT |
| 1654 | |
| 1655 | await client.close() |
| 1656 | |
| 1657 | # explicitly passing the default timeout currently results in it being ignored |
| 1658 | async with httpx.AsyncClient(timeout=HTTPX_DEFAULT_TIMEOUT) as http_client: |
| 1659 | client = AsyncOpenAI( |
| 1660 | base_url=base_url, |
| 1661 | api_key=api_key, |
| 1662 | admin_api_key=admin_api_key, |
| 1663 | _strict_response_validation=True, |
| 1664 | http_client=http_client, |
| 1665 | ) |
| 1666 | |
| 1667 | request = client._build_request(FinalRequestOptions(method="get", url="/foo")) |
| 1668 | timeout = httpx.Timeout(**request.extensions["timeout"]) # type: ignore |
| 1669 | assert timeout == DEFAULT_TIMEOUT # our default |
| 1670 | |
| 1671 | await client.close() |
| 1672 | |
| 1673 | def test_invalid_http_client(self) -> None: |
| 1674 | with pytest.raises(TypeError, match="Invalid `http_client` arg"): |
nothing calls this directly
no test coverage detected