| 220 | |
| 221 | |
| 222 | def test_kwargs(): |
| 223 | @validate_call |
| 224 | def foo(*, a: int, b: int): |
| 225 | return a + b |
| 226 | |
| 227 | assert foo(a=1, b=3) == 4 |
| 228 | |
| 229 | with pytest.raises(ValidationError) as exc_info: |
| 230 | foo(a=1, b='x') |
| 231 | |
| 232 | assert exc_info.value.errors(include_url=False) == [ |
| 233 | { |
| 234 | 'input': 'x', |
| 235 | 'loc': ('b',), |
| 236 | 'msg': 'Input should be a valid integer, unable to parse string as an integer', |
| 237 | 'type': 'int_parsing', |
| 238 | } |
| 239 | ] |
| 240 | |
| 241 | with pytest.raises(ValidationError) as exc_info: |
| 242 | foo(1, 'x') |
| 243 | # insert_assert(exc_info.value.errors(include_url=False)) |
| 244 | assert exc_info.value.errors(include_url=False) == [ |
| 245 | { |
| 246 | 'type': 'missing_keyword_only_argument', |
| 247 | 'loc': ('a',), |
| 248 | 'msg': 'Missing required keyword only argument', |
| 249 | 'input': ArgsKwargs((1, 'x')), |
| 250 | }, |
| 251 | { |
| 252 | 'type': 'missing_keyword_only_argument', |
| 253 | 'loc': ('b',), |
| 254 | 'msg': 'Missing required keyword only argument', |
| 255 | 'input': ArgsKwargs((1, 'x')), |
| 256 | }, |
| 257 | {'type': 'unexpected_positional_argument', 'loc': (0,), 'msg': 'Unexpected positional argument', 'input': 1}, |
| 258 | {'type': 'unexpected_positional_argument', 'loc': (1,), 'msg': 'Unexpected positional argument', 'input': 'x'}, |
| 259 | ] |
| 260 | |
| 261 | |
| 262 | def test_untyped(): |