Skip to content

Commit 1014f3d

Browse files
committed
Add a failing test for Generic Serializing
1 parent 0ecebf2 commit 1014f3d

File tree

2 files changed

+35
-6
lines changed

2 files changed

+35
-6
lines changed

src/guidellm/benchmark/scheduler_registry.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ def scheduler_register_benchmark_objects():
1616
SchedulerMessagingPydanticRegistry.register("GenerationRequestTimings")(
1717
GenerationRequestTimings
1818
)
19-
SchedulerMessagingPydanticRegistry.register("ScheduledRequestInfo")(
20-
ScheduledRequestInfo
21-
)
19+
SchedulerMessagingPydanticRegistry.register(
20+
"ScheduledRequestInfo[GenerationRequestTimings]"
21+
)(ScheduledRequestInfo[GenerationRequestTimings])

tests/unit/utils/test_encoding.py

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

33
import uuid
4-
from typing import Any, Generic
4+
from typing import Any, Generic, TypeVar
55

66
import pytest
77
from pydantic import BaseModel, Field
@@ -22,12 +22,21 @@ class SampleModel(BaseModel):
2222
value: int = Field(description="Value field for testing")
2323

2424

25-
class ComplexModel(BaseModel):
25+
class SampleModelSubclass(SampleModel):
26+
"""Subclass of SampleModel for testing."""
27+
28+
extra_field: str
29+
30+
31+
SampleModelT = TypeVar("SampleModelT", bound=SampleModel)
32+
33+
34+
class ComplexModel(BaseModel, Generic[SampleModelT]):
2635
"""Complex Pydantic model for testing."""
2736

2837
items: list[str] = Field(default_factory=list)
2938
metadata: dict[str, Any] = Field(default_factory=dict)
30-
nested: SampleModel | None = Field(default=None)
39+
nested: SampleModelT | None = Field(default=None)
3140

3241

3342
class TestMessageEncoding:
@@ -508,3 +517,23 @@ def test_dynamic_import_load_pydantic(self, monkeypatch):
508517
inst.pydantic_registry.clear()
509518
restored = inst.from_dict(dumped)
510519
assert restored == sample
520+
521+
@pytest.mark.sanity
522+
@pytest.mark.parametrize(
523+
"declared_type",
524+
[
525+
ComplexModel,
526+
ComplexModel[SampleModelSubclass],
527+
],
528+
)
529+
def test_generic_model_handling(self, declared_type):
530+
inst = Serializer("dict")
531+
inst.register_pydantic(ComplexModel[SampleModelSubclass])
532+
nested = declared_type(
533+
items=["i1", "i2"],
534+
metadata={"m": 1},
535+
nested=SampleModelSubclass(name="nested", value=10, extra_field="extra"),
536+
)
537+
dumped = inst.to_dict(nested)
538+
restored = inst.from_dict(dumped)
539+
assert restored == nested

0 commit comments

Comments
 (0)