Skip to content

Commit

Permalink
Add coverage for adapt_type
Browse files Browse the repository at this point in the history
  • Loading branch information
foarsitter committed Nov 18, 2024
1 parent c336641 commit cabb2aa
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/requestmodel/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from .utils import unify_body


class JSONResponse(Protocol):
class JSONResponse(Protocol): # pragma: no cover
def json(self) -> Any: ... # noqa: E704


Expand Down
17 changes: 6 additions & 11 deletions tests/test_request_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import pytest
from fastapi._compat import field_annotation_is_scalar
from fastapi._compat import field_annotation_is_sequence
from httpx import AsyncClient
from pydantic import BaseModel
from pydantic import ValidationError
from typeguard import suppress_type_checks
Expand All @@ -20,7 +19,6 @@
from requestmodel import RequestModel
from requestmodel import params
from requestmodel.utils import get_annotated_type
from tests.fastapi_server import app
from tests.fastapi_server import client
from tests.fastapi_server.schema import NameModel
from tests.fastapi_server.schema import NameModelList
Expand Down Expand Up @@ -215,13 +213,10 @@ def test_type_adapter() -> None:
assert response == [NameModel(name="test")]


@suppress_type_checks
@pytest.mark.asyncio
async def test_type_adapter_async() -> None:
def test_type_adapter_exception() -> None:
request = TypeAdapterRequest()

async with AsyncClient(app=app, base_url="http://test", timeout=30) as aclient:

response = await request.asend(aclient)

assert response == [NameModel(name="test")]
TypeAdapterRequest.response_model = int # type: ignore
with pytest.raises(
ValueError, match="response_model must be a TypeAdapter or a BaseModel"
):
request.adapt_type(SimpleResponse(data="test"))

0 comments on commit cabb2aa

Please sign in to comment.