| 1053 | |
| 1054 | @pytest.mark.respx(base_url=base_url) |
| 1055 | def test_received_text_for_expected_json(self, respx_mock: MockRouter) -> None: |
| 1056 | class Model(BaseModel): |
| 1057 | name: str |
| 1058 | |
| 1059 | respx_mock.get("/foo").mock(return_value=httpx.Response(200, text="my-custom-format")) |
| 1060 | |
| 1061 | strict_client = OpenAI( |
| 1062 | base_url=base_url, api_key=api_key, admin_api_key=admin_api_key, _strict_response_validation=True |
| 1063 | ) |
| 1064 | |
| 1065 | with pytest.raises(APIResponseValidationError): |
| 1066 | strict_client.get("/foo", cast_to=Model) |
| 1067 | |
| 1068 | non_strict_client = OpenAI( |
| 1069 | base_url=base_url, api_key=api_key, admin_api_key=admin_api_key, _strict_response_validation=False |
| 1070 | ) |
| 1071 | |
| 1072 | response = non_strict_client.get("/foo", cast_to=Model) |
| 1073 | assert isinstance(response, str) # type: ignore[unreachable] |
| 1074 | |
| 1075 | strict_client.close() |
| 1076 | non_strict_client.close() |
| 1077 | |
| 1078 | @pytest.mark.parametrize( |
| 1079 | "remaining_retries,retry_after,timeout", |