def test_field_validation() -> None: """Custom field validation should behave correctly.""" def _validate(context: ValidationContext, _: str) -> None: assert isinstance(context, ValidationContext) context.error("Test") class _Test: fields = {"field": StringField(validate=_validate)} check_field_error(_Test, "field", "value", ErrorCode.VALIDATION_ERROR)
def _check_field_error(yaml_value: str, expected_error: ErrorCode) -> None: check_field_error(_Test, "path", yaml_value, expected_error)
def _check_field_error(field: str, yml_value: str, expected_error: ErrorCode) -> None: check_field_error(_Test, field, yml_value, expected_error)
def _check_field_error(yml_value: str, expected_error: ErrorCode) -> None: check_field_error(_Test, "enum", yml_value, expected_error)
def _check_field_error(yaml_value: str, expected_error: ErrorCode) -> None: check_field_error(_Owner, "field", yaml_value, expected_error)