(py_and_json: PyAndJson)
| 63 | |
| 64 | |
| 65 | def 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 | |
| 92 | def test_validate_assignment_with_context(): |
nothing calls this directly
no test coverage detected