()
| 3268 | |
| 3269 | |
| 3270 | def test_dataclass_field_exclude() -> None: |
| 3271 | @pydantic.dataclasses.dataclass |
| 3272 | class Foo: |
| 3273 | foo: str = Field(exclude=True) |
| 3274 | bar: int = Field(exclude_if=lambda x: x > 1) |
| 3275 | |
| 3276 | ta = TypeAdapter(Foo) |
| 3277 | |
| 3278 | assert ta.dump_python(Foo(foo='bar', bar=1)) == {'bar': 1} |
| 3279 | assert ta.dump_python(Foo(foo='bar', bar=1), exclude={'bar'}) == {} |
| 3280 | assert ta.dump_python(Foo(foo='bar', bar=2)) == {} |
| 3281 | |
| 3282 | assert ta.dump_json(Foo(foo='bar', bar=1)).decode('utf-8') == '{"bar":1}' |
| 3283 | assert ta.dump_json(Foo(foo='bar', bar=1), exclude={'bar'}).decode('utf-8') == '{}' |
| 3284 | assert ta.dump_json(Foo(foo='bar', bar=2)).decode('utf-8') == '{}' |
| 3285 | |
| 3286 | |
| 3287 | @pytest.mark.skipif(sys.version_info < (3, 10), reason='kw_only is not available in python >= 3.10') |
nothing calls this directly
no test coverage detected