Test encoding and decoding round-trip with list.
(self)
| 277 | assert decoded.active == original.active |
| 278 | |
| 279 | def test_list_roundtrip(self): |
| 280 | """Test encoding and decoding round-trip with list.""" |
| 281 | class Item(BaseModel): |
| 282 | id: int |
| 283 | name: str |
| 284 | price: float |
| 285 | |
| 286 | original = [ |
| 287 | Item(id=1, name='Item 1', price=19.99), |
| 288 | Item(id=2, name='Item 2', price=29.99), |
| 289 | Item(id=3, name='Item 3', price=39.99) |
| 290 | ] |
| 291 | |
| 292 | # Encode to TOON |
| 293 | toon = encode_pydantic(original) |
| 294 | |
| 295 | # Decode back to Pydantic |
| 296 | decoded = decode_to_pydantic(toon, Item) |
| 297 | |
| 298 | # Verify equality |
| 299 | assert len(decoded) == len(original) |
| 300 | for orig, dec in zip(original, decoded): |
| 301 | assert dec.id == orig.id |
| 302 | assert dec.name == orig.name |
| 303 | assert dec.price == orig.price |
| 304 | |
| 305 | |
| 306 | @pytest.mark.skipif(PYDANTIC_AVAILABLE, reason="test for when pydantic is not installed") |
nothing calls this directly
no test coverage detected