MCPcopy
hub / github.com/pydantic/pydantic / test_after_validator

Function test_after_validator

tests/test_networks.py:1118–1129  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1116
1117
1118def test_after_validator() -> None:
1119 def remove_trailing_slash(url: AnyUrl) -> str:
1120 """Custom url -> str transformer that removes trailing slash."""
1121 return str(url._url).rstrip('/')
1122
1123 HttpUrl = Annotated[
1124 AnyUrl,
1125 UrlConstraints(allowed_schemes=['http', 'https']),
1126 AfterValidator(lambda url: remove_trailing_slash(url)),
1127 ]
1128 ta = TypeAdapter(HttpUrl)
1129 assert ta.validate_python('https://example.com/') == 'https://example.com'
1130
1131
1132def test_serialize_as_any() -> None:

Callers

nothing calls this directly

Calls 5

validate_pythonMethod · 0.95
UrlConstraintsClass · 0.90
AfterValidatorClass · 0.90
TypeAdapterClass · 0.90
remove_trailing_slashFunction · 0.85

Tested by

no test coverage detected