()
| 290 | |
| 291 | |
| 292 | def test_predicates() -> None: |
| 293 | ta_int = TypeAdapter[int](Annotated[int, validate_as(int).predicate(lambda x: x % 2 == 0)]) |
| 294 | assert ta_int.validate_python(2) == 2 |
| 295 | with pytest.raises(ValidationError): |
| 296 | ta_int.validate_python(1) |
| 297 | |
| 298 | ta_str = TypeAdapter[int](Annotated[str, validate_as(str).predicate(lambda x: x != 'potato')]) |
| 299 | assert ta_str.validate_python('tomato') == 'tomato' |
| 300 | with pytest.raises(ValidationError): |
| 301 | ta_str.validate_python('potato') |
| 302 | |
| 303 | ta_str_to_int = TypeAdapter[int]( |
| 304 | Annotated[str, validate_as(str).transform(lambda x: int(float(x))).predicate(float)] |
| 305 | ) |
| 306 | assert ta_str_to_int.validate_python('1.5') == 1 |
| 307 | |
| 308 | |
| 309 | @pytest.mark.parametrize( |
nothing calls this directly
no test coverage detected