| 425 | |
| 426 | |
| 427 | def test_accepts_none(msg): |
| 428 | a = m.NoneTester() |
| 429 | assert m.no_none1(a) == 42 |
| 430 | assert m.no_none2(a) == 42 |
| 431 | assert m.no_none3(a) == 42 |
| 432 | assert m.no_none4(a) == 42 |
| 433 | assert m.no_none5(a) == 42 |
| 434 | assert m.ok_none1(a) == 42 |
| 435 | assert m.ok_none2(a) == 42 |
| 436 | assert m.ok_none3(a) == 42 |
| 437 | assert m.ok_none4(a) == 42 |
| 438 | assert m.ok_none5(a) == 42 |
| 439 | |
| 440 | with pytest.raises(TypeError) as excinfo: |
| 441 | m.no_none1(None) |
| 442 | assert "incompatible function arguments" in str(excinfo.value) |
| 443 | with pytest.raises(TypeError) as excinfo: |
| 444 | m.no_none2(None) |
| 445 | assert "incompatible function arguments" in str(excinfo.value) |
| 446 | with pytest.raises(TypeError) as excinfo: |
| 447 | m.no_none3(None) |
| 448 | assert "incompatible function arguments" in str(excinfo.value) |
| 449 | with pytest.raises(TypeError) as excinfo: |
| 450 | m.no_none4(None) |
| 451 | assert "incompatible function arguments" in str(excinfo.value) |
| 452 | with pytest.raises(TypeError) as excinfo: |
| 453 | m.no_none5(None) |
| 454 | assert "incompatible function arguments" in str(excinfo.value) |
| 455 | |
| 456 | # The first one still raises because you can't pass None as a lvalue reference arg: |
| 457 | with pytest.raises(TypeError) as excinfo: |
| 458 | assert m.ok_none1(None) == -1 |
| 459 | assert ( |
| 460 | msg(excinfo.value) |
| 461 | == """ |
| 462 | ok_none1(): incompatible function arguments. The following argument types are supported: |
| 463 | 1. (arg0: m.methods_and_attributes.NoneTester) -> int |
| 464 | |
| 465 | Invoked with: None |
| 466 | """ |
| 467 | ) |
| 468 | |
| 469 | # The rest take the argument as pointer or holder, and accept None: |
| 470 | assert m.ok_none2(None) == -1 |
| 471 | assert m.ok_none3(None) == -1 |
| 472 | assert m.ok_none4(None) == -1 |
| 473 | assert m.ok_none5(None) == -1 |
| 474 | |
| 475 | with pytest.raises(TypeError) as excinfo: |
| 476 | m.no_none_kwarg(None) |
| 477 | assert "incompatible function arguments" in str(excinfo.value) |
| 478 | with pytest.raises(TypeError) as excinfo: |
| 479 | m.no_none_kwarg(a=None) |
| 480 | assert "incompatible function arguments" in str(excinfo.value) |
| 481 | with pytest.raises(TypeError) as excinfo: |
| 482 | m.no_none_kwarg_kw_only(None) |
| 483 | assert "incompatible function arguments" in str(excinfo.value) |
| 484 | with pytest.raises(TypeError) as excinfo: |