Exemple #1
0
def test_fields_can_fail_to_coerce_values():
    # Given that I have a Field that allows coercions
    field = Field(annotation=int, allow_coerce=True)

    # When I call its validate method with a value that cannot be coerced
    with pytest.raises(FieldValidationError) as e_data:
        field.validate("invalid")

    assert e_data.value.message == "value could not be coerced to int"
Exemple #2
0
def test_fields_with_optional_unions(annotation, value, expected):
    field = Field(annotation=annotation)
    field.select_validator()
    assert field.validate(value) == expected