| 329 | |
| 330 | |
| 331 | def test_bind_kwargs(): |
| 332 | p = Plugin(autopatch=False) |
| 333 | |
| 334 | req = object() |
| 335 | params = {'name': 'World'} |
| 336 | |
| 337 | def test1(name): |
| 338 | assert name == 'World' |
| 339 | bound = p._bind_kwargs(test1, params, req) |
| 340 | test1(*bound.args, **bound.kwargs) |
| 341 | |
| 342 | def test2(name, plugin): |
| 343 | assert name == 'World' |
| 344 | assert plugin == p |
| 345 | bound = p._bind_kwargs(test2, params, req) |
| 346 | test2(*bound.args, **bound.kwargs) |
| 347 | |
| 348 | def test3(plugin, name): |
| 349 | assert name == 'World' |
| 350 | assert plugin == p |
| 351 | bound = p._bind_kwargs(test3, params, req) |
| 352 | test3(*bound.args, **bound.kwargs) |
| 353 | |
| 354 | def test4(plugin, name, request): |
| 355 | assert name == 'World' |
| 356 | assert plugin == p |
| 357 | assert request == req |
| 358 | bound = p._bind_kwargs(test4, params, req) |
| 359 | test4(*bound.args, **bound.kwargs) |
| 360 | |
| 361 | def test5(request, name, plugin): |
| 362 | assert name == 'World' |
| 363 | assert plugin == p |
| 364 | assert request == req |
| 365 | bound = p._bind_kwargs(test5, params, req) |
| 366 | test5(*bound.args, **bound.kwargs) |
| 367 | |
| 368 | def test6(request, name, plugin, answer=42): |
| 369 | assert name == 'World' |
| 370 | assert plugin == p |
| 371 | assert request == req |
| 372 | assert answer == 42 |
| 373 | bound = p._bind_kwargs(test6, params, req) |
| 374 | test6(*bound.args, **bound.kwargs) |
| 375 | |
| 376 | # Now mix in a catch-all parameter that needs to be assigned |
| 377 | def test6(request, name, plugin, *args, **kwargs): |
| 378 | assert name == 'World' |
| 379 | assert plugin == p |
| 380 | assert request == req |
| 381 | assert args == () |
| 382 | assert kwargs == {'answer': 42} |
| 383 | bound = p._bind_kwargs(test6, {'name': 'World', 'answer': 42}, req) |
| 384 | test6(*bound.args, **bound.kwargs) |
| 385 | |
| 386 | |
| 387 | def test_argument_coercion(): |