| 86 | |
| 87 | |
| 88 | def test_kwargs(): |
| 89 | @validate_arguments |
| 90 | def foo(*, a: int, b: int): |
| 91 | return a + b |
| 92 | |
| 93 | assert foo.model.model_fields.keys() == {'a', 'b', 'args', 'kwargs'} |
| 94 | assert foo(a=1, b=3) == 4 |
| 95 | |
| 96 | with pytest.raises(ValidationError) as exc_info: |
| 97 | foo(a=1, b='x') |
| 98 | |
| 99 | assert exc_info.value.errors(include_url=False) == [ |
| 100 | { |
| 101 | 'input': 'x', |
| 102 | 'loc': ('b',), |
| 103 | 'msg': 'Input should be a valid integer, unable to parse string as an integer', |
| 104 | 'type': 'int_parsing', |
| 105 | } |
| 106 | ] |
| 107 | |
| 108 | with pytest.raises(TypeError, match='0 positional arguments expected but 2 given'): |
| 109 | foo(1, 'x') |
| 110 | |
| 111 | |
| 112 | def test_untyped(): |