| 1 |
"""Tests for error message formatting in extended call syntax (*args, **kwargs).""" |
| 2 |
import pytest |
| 3 |
|
| 4 |
|
| 5 |
def test_function_name_includes_module(): |
| 6 |
|
| 7 |
def f(**kwargs): |
| 8 |
pass |
| 9 |
f.__module__ = 'some.module' |
| 10 |
with pytest.raises(TypeError) as exc_info: |
| 11 |
f(**{'a': 1}, **{'a': 2}) |
| 12 |
assert str(exc_info.value).startswith('some.module.') |
| 13 |
|
| 14 |
|
| 15 |
def test_function_name_no_prefix_for_builtins_module(): |
| 16 |
|
| 17 |
def f(**kwargs): |
| 18 |
pass |
| 19 |
f.__module__ = 'builtins' |
| 20 |
with pytest.raises(TypeError) as exc_info: |
| 21 |
f(**{'a': 1}, **{'a': 2}) |
| 22 |
msg = str(exc_info.value) |
| 23 |
assert 'f() got multiple values' in msg |
| 24 |
assert not msg.startswith('builtins.') |
| 25 |
|
| 26 |
|
| 27 |
def test_function_name_no_prefix_when_module_is_none(): |
| 28 |
|
| 29 |
def f(**kwargs): |
| 30 |
pass |
| 31 |
f.__module__ = None |
| 32 |
with pytest.raises(TypeError) as exc_info: |
| 33 |
f(**{'a': 1}, **{'a': 2}) |
| 34 |
assert 'f() got multiple values' in str(exc_info.value) |
| 35 |
|
| 36 |
|
| 37 |
def test_non_function_callable_uses_repr(): |
| 38 |
|
| 39 |
nothing = None |
| 40 |
h = lambda: None |
| 41 |
with pytest.raises(TypeError) as exc_info: |
| 42 |
nothing(*h) |
| 43 |
assert str(exc_info.value).startswith('None argument after *') |
| 44 |
with pytest.raises(TypeError) as exc_info: |
| 45 |
nothing(**h) |
| 46 |
assert str(exc_info.value).startswith('None argument after **') |
| 47 |
|
| 48 |
|
| 49 |
def test_id_takes_no_keyword_arguments(): |
| 50 |
with pytest.raises(TypeError) as exc_info: |
| 51 |
id(1, **{'foo': 1}) |
| 52 |
assert 'takes no keyword arguments' in str(exc_info.value) |