(
status: int,
error: dict[str, object],
error_class: type[APIStatusError],
parent_class: type[APIStatusError],
sync: bool,
respx_mock: MockRouter,
)
| 191 | @pytest.mark.parametrize("sync", [True, False], ids=["sync", "async"]) |
| 192 | @pytest.mark.parametrize(("status", "error", "error_class", "parent_class"), STATUS_ERRORS) |
| 193 | async def test_status_error_class( |
| 194 | status: int, |
| 195 | error: dict[str, object], |
| 196 | error_class: type[APIStatusError], |
| 197 | parent_class: type[APIStatusError], |
| 198 | sync: bool, |
| 199 | respx_mock: MockRouter, |
| 200 | ) -> None: |
| 201 | respx_mock.post(INVOKE_URL).mock(return_value=httpx2.Response(status, json={"type": "error", "error": error})) |
| 202 | |
| 203 | with pytest.raises(parent_class) as exc_info: |
| 204 | if sync: |
| 205 | sync_client.with_options(max_retries=0).messages.create( |
| 206 | max_tokens=1024, |
| 207 | messages=[{"role": "user", "content": "Say hello there!"}], |
| 208 | model="anthropic.claude-3-5-sonnet-20241022-v2:0", |
| 209 | ) |
| 210 | else: |
| 211 | await async_client.with_options(max_retries=0).messages.create( |
| 212 | max_tokens=1024, |
| 213 | messages=[{"role": "user", "content": "Say hello there!"}], |
| 214 | model="anthropic.claude-3-5-sonnet-20241022-v2:0", |
| 215 | ) |
| 216 | |
| 217 | assert type(exc_info.value) is error_class |
| 218 | |
| 219 | |
| 220 | @pytest.mark.respx() |
nothing calls this directly
no test coverage detected