Skip to content

Commit

Permalink
fix typing in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zerlok committed Dec 21, 2024
1 parent d016294 commit ab897d7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions tests/integration/test_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@


@pytest.mark.parametrize("obj", [FooModel(num=42, s="spam", bar=FooModel.Bar(str2int={"eggs": 59}))])
def test_pydantic_dump_json_load_ok(
pydantic_serializer: PydanticSerializer,
def test_pydantic_dump_json_load_ok[T: BaseModel](
pydantic_serializer: PydanticSerializer[T],
json_serializer: JSONSerializer,
message: Message[object],
message: Message[T],
obj: BaseModel,
) -> None:
loaded = json_serializer.load_message(pydantic_serializer.dump_message(message))
Expand All @@ -20,10 +20,10 @@ def test_pydantic_dump_json_load_ok(


@pytest.fixture
def pydantic_serializer(obj: BaseModel) -> PydanticSerializer:
def pydantic_serializer[T: BaseModel](obj: T) -> PydanticSerializer[T]:
return PydanticSerializer(type(obj))


@pytest.fixture
def message(obj: object, stub_routing_key: str) -> Message[object]:
def message[T: BaseModel](obj: T, stub_routing_key: str) -> Message[T]:
return AppMessage(body=obj, routing_key=stub_routing_key)
6 changes: 3 additions & 3 deletions tests/unit/serializer/test_pydantic.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@


@pytest.mark.parametrize("obj", [FooModel(num=42, s="spam", bar=FooModel.Bar(str2int={"eggs": 59}))])
def test_dump_load_ok(serializer: PydanticSerializer, message: Message[object]) -> None:
def test_dump_load_ok[T: BaseModel](serializer: PydanticSerializer[T], message: Message[T]) -> None:
loaded = serializer.load_message(serializer.dump_message(message))

assert loaded.body == message.body


@pytest.fixture
def serializer(obj: BaseModel) -> PydanticSerializer:
def serializer[T: BaseModel](obj: T) -> PydanticSerializer[T]:
return PydanticSerializer(type(obj))


@pytest.fixture
def message(obj: object, stub_routing_key: str) -> Message[object]:
def message[T: BaseModel](obj: T, stub_routing_key: str) -> Message[T]:
return AppMessage(body=obj, routing_key=stub_routing_key)

0 comments on commit ab897d7

Please sign in to comment.