Test encoding nested Pydantic models.
(self)
| 48 | assert 'MOU-042,Wireless Mouse,29.99' in toon |
| 49 | |
| 50 | def test_nested_models(self): |
| 51 | """Test encoding nested Pydantic models.""" |
| 52 | class Address(BaseModel): |
| 53 | street: str |
| 54 | city: str |
| 55 | zipcode: str |
| 56 | |
| 57 | class Person(BaseModel): |
| 58 | name: str |
| 59 | age: int |
| 60 | address: Address |
| 61 | |
| 62 | person = Person( |
| 63 | name='Bob', |
| 64 | age=35, |
| 65 | address=Address(street='123 Main St', city='Boston', zipcode='02101') |
| 66 | ) |
| 67 | |
| 68 | toon = encode_pydantic(person) |
| 69 | |
| 70 | assert 'name: Bob' in toon |
| 71 | assert 'age: 35' in toon |
| 72 | assert 'address:' in toon |
| 73 | assert 'street: 123 Main St' in toon |
| 74 | assert 'city: Boston' in toon |
| 75 | assert 'zipcode: 02101' in toon |
| 76 | |
| 77 | def test_exclude_unset(self): |
| 78 | """Test excluding unset fields.""" |
nothing calls this directly
no test coverage detected