MCPcopy
hub / github.com/pydantic/pydantic / test_isinstance

Function test_isinstance

pydantic-core/tests/test_validation_context.py:65–89  ·  view source on GitHub ↗
(py_and_json: PyAndJson)

Source from the content-addressed store, hash-verified

63
64
65def test_isinstance(py_and_json: PyAndJson):
66 def f(input_value, validator, info):
67 if 'error' in info.context:
68 raise ValueError('wrong')
69 return validator(input_value)
70
71 v = py_and_json(core_schema.with_info_wrap_validator_function(f, core_schema.str_schema()))
72
73 assert v.validate_python('foobar', None, {}) == 'foobar'
74
75 with pytest.raises(TypeError):
76 v.validate_test('foobar')
77
78 with pytest.raises(TypeError):
79 v.isinstance_test('foobar')
80
81 with pytest.raises(ValidationError, match=r'Value error, wrong \[type=value_error,'):
82 v.validate_test('foobar', None, {'error'})
83
84 assert v.isinstance_test('foobar', None, {}) is True
85
86 with pytest.raises(TypeError):
87 v.isinstance_test('foobar')
88
89 assert v.isinstance_test('foobar', None, {'error'}) is False
90
91
92def test_validate_assignment_with_context():

Callers

nothing calls this directly

Calls 5

py_and_jsonFunction · 0.85
str_schemaMethod · 0.80
validate_testMethod · 0.80
isinstance_testMethod · 0.80
validate_pythonMethod · 0.45

Tested by

no test coverage detected