|
24 | 24 | from ydc_search_api import YdcSearchAPI, AsyncYdcSearchAPI, APIResponseValidationError |
25 | 25 | from ydc_search_api._types import Omit |
26 | 26 | from ydc_search_api._models import BaseModel, FinalRequestOptions |
27 | | -from ydc_search_api._constants import RAW_RESPONSE_HEADER |
28 | 27 | from ydc_search_api._exceptions import APIStatusError, APITimeoutError, YdcSearchAPIError, APIResponseValidationError |
29 | 28 | from ydc_search_api._base_client import ( |
30 | 29 | DEFAULT_TIMEOUT, |
@@ -723,22 +722,21 @@ def test_parse_retry_after_header(self, remaining_retries: int, retry_after: str |
723 | 722 |
|
724 | 723 | @mock.patch("ydc_search_api._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout) |
725 | 724 | @pytest.mark.respx(base_url=base_url) |
726 | | - def test_retrying_timeout_errors_doesnt_leak(self, respx_mock: MockRouter) -> None: |
| 725 | + def test_retrying_timeout_errors_doesnt_leak(self, respx_mock: MockRouter, client: YdcSearchAPI) -> None: |
727 | 726 | respx_mock.get("/search").mock(side_effect=httpx.TimeoutException("Test timeout error")) |
728 | 727 |
|
729 | 728 | with pytest.raises(APITimeoutError): |
730 | | - self.client.get("/search", cast_to=httpx.Response, options={"headers": {RAW_RESPONSE_HEADER: "stream"}}) |
| 729 | + client.search.with_streaming_response.query(query="query").__enter__() |
731 | 730 |
|
732 | 731 | assert _get_open_connections(self.client) == 0 |
733 | 732 |
|
734 | 733 | @mock.patch("ydc_search_api._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout) |
735 | 734 | @pytest.mark.respx(base_url=base_url) |
736 | | - def test_retrying_status_errors_doesnt_leak(self, respx_mock: MockRouter) -> None: |
| 735 | + def test_retrying_status_errors_doesnt_leak(self, respx_mock: MockRouter, client: YdcSearchAPI) -> None: |
737 | 736 | respx_mock.get("/search").mock(return_value=httpx.Response(500)) |
738 | 737 |
|
739 | 738 | with pytest.raises(APIStatusError): |
740 | | - self.client.get("/search", cast_to=httpx.Response, options={"headers": {RAW_RESPONSE_HEADER: "stream"}}) |
741 | | - |
| 739 | + client.search.with_streaming_response.query(query="query").__enter__() |
742 | 740 | assert _get_open_connections(self.client) == 0 |
743 | 741 |
|
744 | 742 | @pytest.mark.parametrize("failures_before_success", [0, 2, 4]) |
@@ -1540,26 +1538,25 @@ async def test_parse_retry_after_header(self, remaining_retries: int, retry_afte |
1540 | 1538 |
|
1541 | 1539 | @mock.patch("ydc_search_api._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout) |
1542 | 1540 | @pytest.mark.respx(base_url=base_url) |
1543 | | - async def test_retrying_timeout_errors_doesnt_leak(self, respx_mock: MockRouter) -> None: |
| 1541 | + async def test_retrying_timeout_errors_doesnt_leak( |
| 1542 | + self, respx_mock: MockRouter, async_client: AsyncYdcSearchAPI |
| 1543 | + ) -> None: |
1544 | 1544 | respx_mock.get("/search").mock(side_effect=httpx.TimeoutException("Test timeout error")) |
1545 | 1545 |
|
1546 | 1546 | with pytest.raises(APITimeoutError): |
1547 | | - await self.client.get( |
1548 | | - "/search", cast_to=httpx.Response, options={"headers": {RAW_RESPONSE_HEADER: "stream"}} |
1549 | | - ) |
| 1547 | + await async_client.search.with_streaming_response.query(query="query").__aenter__() |
1550 | 1548 |
|
1551 | 1549 | assert _get_open_connections(self.client) == 0 |
1552 | 1550 |
|
1553 | 1551 | @mock.patch("ydc_search_api._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout) |
1554 | 1552 | @pytest.mark.respx(base_url=base_url) |
1555 | | - async def test_retrying_status_errors_doesnt_leak(self, respx_mock: MockRouter) -> None: |
| 1553 | + async def test_retrying_status_errors_doesnt_leak( |
| 1554 | + self, respx_mock: MockRouter, async_client: AsyncYdcSearchAPI |
| 1555 | + ) -> None: |
1556 | 1556 | respx_mock.get("/search").mock(return_value=httpx.Response(500)) |
1557 | 1557 |
|
1558 | 1558 | with pytest.raises(APIStatusError): |
1559 | | - await self.client.get( |
1560 | | - "/search", cast_to=httpx.Response, options={"headers": {RAW_RESPONSE_HEADER: "stream"}} |
1561 | | - ) |
1562 | | - |
| 1559 | + await async_client.search.with_streaming_response.query(query="query").__aenter__() |
1563 | 1560 | assert _get_open_connections(self.client) == 0 |
1564 | 1561 |
|
1565 | 1562 | @pytest.mark.parametrize("failures_before_success", [0, 2, 4]) |
|
0 commit comments