|
23 | 23 |
|
24 | 24 | from meterhub import Meterhub, AsyncMeterhub, APIResponseValidationError |
25 | 25 | from meterhub._types import Omit |
26 | | -from meterhub._utils import maybe_transform |
27 | 26 | from meterhub._models import BaseModel, FinalRequestOptions |
28 | | -from meterhub._constants import RAW_RESPONSE_HEADER |
29 | 27 | from meterhub._exceptions import MeterhubError, APIStatusError, APITimeoutError, APIResponseValidationError |
30 | 28 | from meterhub._base_client import ( |
31 | 29 | DEFAULT_TIMEOUT, |
|
35 | 33 | DefaultAsyncHttpxClient, |
36 | 34 | make_request_options, |
37 | 35 | ) |
38 | | -from meterhub.types.api.v1.meter_detect_params import MeterDetectParams |
39 | 36 |
|
40 | 37 | from .utils import update_env |
41 | 38 |
|
@@ -715,32 +712,21 @@ def test_parse_retry_after_header(self, remaining_retries: int, retry_after: str |
715 | 712 |
|
716 | 713 | @mock.patch("meterhub._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout) |
717 | 714 | @pytest.mark.respx(base_url=base_url) |
718 | | - def test_retrying_timeout_errors_doesnt_leak(self, respx_mock: MockRouter) -> None: |
| 715 | + def test_retrying_timeout_errors_doesnt_leak(self, respx_mock: MockRouter, client: Meterhub) -> None: |
719 | 716 | respx_mock.post("/api/v1/meter/detect/").mock(side_effect=httpx.TimeoutException("Test timeout error")) |
720 | 717 |
|
721 | 718 | with pytest.raises(APITimeoutError): |
722 | | - self.client.post( |
723 | | - "/api/v1/meter/detect/", |
724 | | - body=cast(object, maybe_transform(dict(image="REPLACE_ME"), MeterDetectParams)), |
725 | | - cast_to=httpx.Response, |
726 | | - options={"headers": {RAW_RESPONSE_HEADER: "stream"}}, |
727 | | - ) |
| 719 | + client.api.v1.meter.with_streaming_response.detect(image="image").__enter__() |
728 | 720 |
|
729 | 721 | assert _get_open_connections(self.client) == 0 |
730 | 722 |
|
731 | 723 | @mock.patch("meterhub._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout) |
732 | 724 | @pytest.mark.respx(base_url=base_url) |
733 | | - def test_retrying_status_errors_doesnt_leak(self, respx_mock: MockRouter) -> None: |
| 725 | + def test_retrying_status_errors_doesnt_leak(self, respx_mock: MockRouter, client: Meterhub) -> None: |
734 | 726 | respx_mock.post("/api/v1/meter/detect/").mock(return_value=httpx.Response(500)) |
735 | 727 |
|
736 | 728 | with pytest.raises(APIStatusError): |
737 | | - self.client.post( |
738 | | - "/api/v1/meter/detect/", |
739 | | - body=cast(object, maybe_transform(dict(image="REPLACE_ME"), MeterDetectParams)), |
740 | | - cast_to=httpx.Response, |
741 | | - options={"headers": {RAW_RESPONSE_HEADER: "stream"}}, |
742 | | - ) |
743 | | - |
| 729 | + client.api.v1.meter.with_streaming_response.detect(image="image").__enter__() |
744 | 730 | assert _get_open_connections(self.client) == 0 |
745 | 731 |
|
746 | 732 | @pytest.mark.parametrize("failures_before_success", [0, 2, 4]) |
@@ -1544,32 +1530,25 @@ async def test_parse_retry_after_header(self, remaining_retries: int, retry_afte |
1544 | 1530 |
|
1545 | 1531 | @mock.patch("meterhub._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout) |
1546 | 1532 | @pytest.mark.respx(base_url=base_url) |
1547 | | - async def test_retrying_timeout_errors_doesnt_leak(self, respx_mock: MockRouter) -> None: |
| 1533 | + async def test_retrying_timeout_errors_doesnt_leak( |
| 1534 | + self, respx_mock: MockRouter, async_client: AsyncMeterhub |
| 1535 | + ) -> None: |
1548 | 1536 | respx_mock.post("/api/v1/meter/detect/").mock(side_effect=httpx.TimeoutException("Test timeout error")) |
1549 | 1537 |
|
1550 | 1538 | with pytest.raises(APITimeoutError): |
1551 | | - await self.client.post( |
1552 | | - "/api/v1/meter/detect/", |
1553 | | - body=cast(object, maybe_transform(dict(image="REPLACE_ME"), MeterDetectParams)), |
1554 | | - cast_to=httpx.Response, |
1555 | | - options={"headers": {RAW_RESPONSE_HEADER: "stream"}}, |
1556 | | - ) |
| 1539 | + await async_client.api.v1.meter.with_streaming_response.detect(image="image").__aenter__() |
1557 | 1540 |
|
1558 | 1541 | assert _get_open_connections(self.client) == 0 |
1559 | 1542 |
|
1560 | 1543 | @mock.patch("meterhub._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout) |
1561 | 1544 | @pytest.mark.respx(base_url=base_url) |
1562 | | - async def test_retrying_status_errors_doesnt_leak(self, respx_mock: MockRouter) -> None: |
| 1545 | + async def test_retrying_status_errors_doesnt_leak( |
| 1546 | + self, respx_mock: MockRouter, async_client: AsyncMeterhub |
| 1547 | + ) -> None: |
1563 | 1548 | respx_mock.post("/api/v1/meter/detect/").mock(return_value=httpx.Response(500)) |
1564 | 1549 |
|
1565 | 1550 | with pytest.raises(APIStatusError): |
1566 | | - await self.client.post( |
1567 | | - "/api/v1/meter/detect/", |
1568 | | - body=cast(object, maybe_transform(dict(image="REPLACE_ME"), MeterDetectParams)), |
1569 | | - cast_to=httpx.Response, |
1570 | | - options={"headers": {RAW_RESPONSE_HEADER: "stream"}}, |
1571 | | - ) |
1572 | | - |
| 1551 | + await async_client.api.v1.meter.with_streaming_response.detect(image="image").__aenter__() |
1573 | 1552 | assert _get_open_connections(self.client) == 0 |
1574 | 1553 |
|
1575 | 1554 | @pytest.mark.parametrize("failures_before_success", [0, 2, 4]) |
|
0 commit comments