Skip to content

Commit be81316

Browse files
committed
Add tests showing that the wrapped schemas are preserved
1 parent ef7b7cc commit be81316

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

tests/serializers/test_functions.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,3 +612,21 @@ def test_pydantic_serialization_unexpected_value():
612612
v = PydanticSerializationUnexpectedValue()
613613
assert str(v) == 'Unexpected Value'
614614
assert repr(v) == 'PydanticSerializationUnexpectedValue(Unexpected Value)'
615+
616+
617+
def test_function_after_preserves_wrapped_serialization():
618+
def f(value, _info):
619+
return value
620+
621+
s = SchemaSerializer(core_schema.general_after_validator_function(f, core_schema.int_schema()))
622+
with pytest.warns(UserWarning, match='Expected `int` but got `str` - serialized value may not be as expected'):
623+
assert s.to_python('abc') == 'abc'
624+
625+
626+
def test_function_wrap_preserves_wrapped_serialization():
627+
def f(value, handler, _info):
628+
return handler(value)
629+
630+
s = SchemaSerializer(core_schema.general_wrap_validator_function(f, core_schema.int_schema()))
631+
with pytest.warns(UserWarning, match='Expected `int` but got `str` - serialized value may not be as expected'):
632+
assert s.to_python('abc') == 'abc'

0 commit comments

Comments
 (0)