"""Page serialization.""" from __future__ import annotations from ypms.framework.pagination import Page def test_to_dict_uses_provided_serializer() -> None: p: Page[int] = Page(items=[1, 2, 3], next_cursor=42) out = p.to_dict(lambda i: {"n": i * 2}) assert out == {"items": [{"n": 2}, {"n": 4}, {"n": 6}], "next_cursor": 42, "total": None} def test_to_dict_carries_total_when_set() -> None: p: Page[str] = Page(items=["a"], next_cursor=None, total=100) out = p.to_dict(lambda s: s) assert out == {"items": ["a"], "next_cursor": None, "total": 100}