|
23 | 23 |
|
24 | 24 | from isaacus import Isaacus, AsyncIsaacus, APIResponseValidationError |
25 | 25 | from isaacus._types import Omit |
26 | | -from isaacus._utils import maybe_transform |
27 | 26 | from isaacus._models import BaseModel, FinalRequestOptions |
28 | | -from isaacus._constants import RAW_RESPONSE_HEADER |
29 | 27 | from isaacus._exceptions import IsaacusError, APIStatusError, APITimeoutError, APIResponseValidationError |
30 | 28 | from isaacus._base_client import ( |
31 | 29 | DEFAULT_TIMEOUT, |
|
35 | 33 | DefaultAsyncHttpxClient, |
36 | 34 | make_request_options, |
37 | 35 | ) |
38 | | -from isaacus.types.classifications.universal_create_params import UniversalCreateParams |
39 | 36 |
|
40 | 37 | from .utils import update_env |
41 | 38 |
|
@@ -713,52 +710,29 @@ def test_parse_retry_after_header(self, remaining_retries: int, retry_after: str |
713 | 710 |
|
714 | 711 | @mock.patch("isaacus._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout) |
715 | 712 | @pytest.mark.respx(base_url=base_url) |
716 | | - def test_retrying_timeout_errors_doesnt_leak(self, respx_mock: MockRouter) -> None: |
| 713 | + def test_retrying_timeout_errors_doesnt_leak(self, respx_mock: MockRouter, client: Isaacus) -> None: |
717 | 714 | respx_mock.post("/classifications/universal").mock(side_effect=httpx.TimeoutException("Test timeout error")) |
718 | 715 |
|
719 | 716 | with pytest.raises(APITimeoutError): |
720 | | - self.client.post( |
721 | | - "/classifications/universal", |
722 | | - body=cast( |
723 | | - object, |
724 | | - maybe_transform( |
725 | | - dict( |
726 | | - model="kanon-universal-classifier", |
727 | | - query="This is a confidentiality clause.", |
728 | | - texts=["I agree not to tell anyone about the document."], |
729 | | - ), |
730 | | - UniversalCreateParams, |
731 | | - ), |
732 | | - ), |
733 | | - cast_to=httpx.Response, |
734 | | - options={"headers": {RAW_RESPONSE_HEADER: "stream"}}, |
735 | | - ) |
| 717 | + client.classifications.universal.with_streaming_response.create( |
| 718 | + model="kanon-universal-classifier", |
| 719 | + query="This is a confidentiality clause.", |
| 720 | + texts=["I agree not to tell anyone about the document."], |
| 721 | + ).__enter__() |
736 | 722 |
|
737 | 723 | assert _get_open_connections(self.client) == 0 |
738 | 724 |
|
739 | 725 | @mock.patch("isaacus._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout) |
740 | 726 | @pytest.mark.respx(base_url=base_url) |
741 | | - def test_retrying_status_errors_doesnt_leak(self, respx_mock: MockRouter) -> None: |
| 727 | + def test_retrying_status_errors_doesnt_leak(self, respx_mock: MockRouter, client: Isaacus) -> None: |
742 | 728 | respx_mock.post("/classifications/universal").mock(return_value=httpx.Response(500)) |
743 | 729 |
|
744 | 730 | with pytest.raises(APIStatusError): |
745 | | - self.client.post( |
746 | | - "/classifications/universal", |
747 | | - body=cast( |
748 | | - object, |
749 | | - maybe_transform( |
750 | | - dict( |
751 | | - model="kanon-universal-classifier", |
752 | | - query="This is a confidentiality clause.", |
753 | | - texts=["I agree not to tell anyone about the document."], |
754 | | - ), |
755 | | - UniversalCreateParams, |
756 | | - ), |
757 | | - ), |
758 | | - cast_to=httpx.Response, |
759 | | - options={"headers": {RAW_RESPONSE_HEADER: "stream"}}, |
760 | | - ) |
761 | | - |
| 731 | + client.classifications.universal.with_streaming_response.create( |
| 732 | + model="kanon-universal-classifier", |
| 733 | + query="This is a confidentiality clause.", |
| 734 | + texts=["I agree not to tell anyone about the document."], |
| 735 | + ).__enter__() |
762 | 736 | assert _get_open_connections(self.client) == 0 |
763 | 737 |
|
764 | 738 | @pytest.mark.parametrize("failures_before_success", [0, 2, 4]) |
@@ -1572,52 +1546,31 @@ async def test_parse_retry_after_header(self, remaining_retries: int, retry_afte |
1572 | 1546 |
|
1573 | 1547 | @mock.patch("isaacus._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout) |
1574 | 1548 | @pytest.mark.respx(base_url=base_url) |
1575 | | - async def test_retrying_timeout_errors_doesnt_leak(self, respx_mock: MockRouter) -> None: |
| 1549 | + async def test_retrying_timeout_errors_doesnt_leak( |
| 1550 | + self, respx_mock: MockRouter, async_client: AsyncIsaacus |
| 1551 | + ) -> None: |
1576 | 1552 | respx_mock.post("/classifications/universal").mock(side_effect=httpx.TimeoutException("Test timeout error")) |
1577 | 1553 |
|
1578 | 1554 | with pytest.raises(APITimeoutError): |
1579 | | - await self.client.post( |
1580 | | - "/classifications/universal", |
1581 | | - body=cast( |
1582 | | - object, |
1583 | | - maybe_transform( |
1584 | | - dict( |
1585 | | - model="kanon-universal-classifier", |
1586 | | - query="This is a confidentiality clause.", |
1587 | | - texts=["I agree not to tell anyone about the document."], |
1588 | | - ), |
1589 | | - UniversalCreateParams, |
1590 | | - ), |
1591 | | - ), |
1592 | | - cast_to=httpx.Response, |
1593 | | - options={"headers": {RAW_RESPONSE_HEADER: "stream"}}, |
1594 | | - ) |
| 1555 | + await async_client.classifications.universal.with_streaming_response.create( |
| 1556 | + model="kanon-universal-classifier", |
| 1557 | + query="This is a confidentiality clause.", |
| 1558 | + texts=["I agree not to tell anyone about the document."], |
| 1559 | + ).__aenter__() |
1595 | 1560 |
|
1596 | 1561 | assert _get_open_connections(self.client) == 0 |
1597 | 1562 |
|
1598 | 1563 | @mock.patch("isaacus._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout) |
1599 | 1564 | @pytest.mark.respx(base_url=base_url) |
1600 | | - async def test_retrying_status_errors_doesnt_leak(self, respx_mock: MockRouter) -> None: |
| 1565 | + async def test_retrying_status_errors_doesnt_leak(self, respx_mock: MockRouter, async_client: AsyncIsaacus) -> None: |
1601 | 1566 | respx_mock.post("/classifications/universal").mock(return_value=httpx.Response(500)) |
1602 | 1567 |
|
1603 | 1568 | with pytest.raises(APIStatusError): |
1604 | | - await self.client.post( |
1605 | | - "/classifications/universal", |
1606 | | - body=cast( |
1607 | | - object, |
1608 | | - maybe_transform( |
1609 | | - dict( |
1610 | | - model="kanon-universal-classifier", |
1611 | | - query="This is a confidentiality clause.", |
1612 | | - texts=["I agree not to tell anyone about the document."], |
1613 | | - ), |
1614 | | - UniversalCreateParams, |
1615 | | - ), |
1616 | | - ), |
1617 | | - cast_to=httpx.Response, |
1618 | | - options={"headers": {RAW_RESPONSE_HEADER: "stream"}}, |
1619 | | - ) |
1620 | | - |
| 1569 | + await async_client.classifications.universal.with_streaming_response.create( |
| 1570 | + model="kanon-universal-classifier", |
| 1571 | + query="This is a confidentiality clause.", |
| 1572 | + texts=["I agree not to tell anyone about the document."], |
| 1573 | + ).__aenter__() |
1621 | 1574 | assert _get_open_connections(self.client) == 0 |
1622 | 1575 |
|
1623 | 1576 | @pytest.mark.parametrize("failures_before_success", [0, 2, 4]) |
|
0 commit comments