MCPcopy
hub / github.com/pydantic/pydantic / test_plugin_path_validate_call

Function test_plugin_path_validate_call

tests/test_plugins.py:410–446  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

408
409
410def test_plugin_path_validate_call() -> None:
411 class CustomOnValidatePython(ValidatePythonHandlerProtocol):
412 pass
413
414 class Plugin1:
415 def new_schema_validator(self, schema, schema_type, schema_type_path, schema_kind, config, plugin_settings):
416 assert schema_type.__name__ == 'foo'
417 assert schema_type_path == SchemaTypePath(
418 'tests.test_plugins', 'test_plugin_path_validate_call.<locals>.foo'
419 )
420 assert schema_kind == 'validate_call'
421 return CustomOnValidatePython(), None, None
422
423 plugin = Plugin1()
424 with install_plugin(plugin):
425
426 @validate_call()
427 def foo(a: int):
428 return a
429
430 class Plugin2:
431 def new_schema_validator(self, schema, schema_type, schema_type_path, schema_kind, config, plugin_settings):
432 assert schema_type.__name__ == 'my_wrapped_function'
433 assert schema_type_path == SchemaTypePath(
434 'tests.test_plugins', 'partial(test_plugin_path_validate_call.<locals>.my_wrapped_function)'
435 )
436 assert schema_kind == 'validate_call'
437 return CustomOnValidatePython(), None, None
438
439 plugin = Plugin2()
440 with install_plugin(plugin):
441
442 def my_wrapped_function(a: int, b: int, c: int):
443 return a + b + c
444
445 my_partial_function = partial(my_wrapped_function, c=3)
446 validate_call(my_partial_function)
447
448
449def test_plugin_path_create_model() -> None:

Callers

nothing calls this directly

Calls 4

validate_callFunction · 0.90
Plugin1Class · 0.85
install_pluginFunction · 0.85
Plugin2Class · 0.85

Tested by

no test coverage detected