mirror of
https://github.com/pybind/pybind11.git
synced 2026-06-08 23:39:12 +00:00
nicer error message for invalid function arguments
This commit is contained in:
@@ -83,7 +83,7 @@ def test_cpp_function_roundtrip():
|
||||
|
||||
with pytest.raises(TypeError) as excinfo:
|
||||
test_dummy_function(dummy_function2)
|
||||
assert "Incompatible function arguments" in str(excinfo.value)
|
||||
assert "incompatible function arguments" in str(excinfo.value)
|
||||
|
||||
with pytest.raises(TypeError) as excinfo:
|
||||
test_dummy_function(lambda x, y: x + y)
|
||||
|
||||
@@ -24,9 +24,10 @@ def test_inheritance(msg):
|
||||
with pytest.raises(TypeError) as excinfo:
|
||||
dog_bark(polly)
|
||||
assert msg(excinfo.value) == """
|
||||
Incompatible function arguments. The following argument types are supported:
|
||||
dog_bark(): incompatible function arguments. The following argument types are supported:
|
||||
1. (arg0: m.Dog) -> str
|
||||
Invoked with: <m.Pet object at 0>
|
||||
|
||||
Invoked with: <m.Pet object at 0>
|
||||
"""
|
||||
|
||||
|
||||
|
||||
@@ -65,17 +65,19 @@ def test_no_id(capture, msg):
|
||||
with pytest.raises(TypeError) as excinfo:
|
||||
get_element(None)
|
||||
assert msg(excinfo.value) == """
|
||||
Incompatible function arguments. The following argument types are supported:
|
||||
get_element(): incompatible function arguments. The following argument types are supported:
|
||||
1. (arg0: m.issues.ElementA) -> int
|
||||
Invoked with: None
|
||||
|
||||
Invoked with: None
|
||||
"""
|
||||
|
||||
with pytest.raises(TypeError) as excinfo:
|
||||
expect_int(5.2)
|
||||
assert msg(excinfo.value) == """
|
||||
Incompatible function arguments. The following argument types are supported:
|
||||
expect_int(): incompatible function arguments. The following argument types are supported:
|
||||
1. (arg0: int) -> int
|
||||
Invoked with: 5.2
|
||||
|
||||
Invoked with: 5.2
|
||||
"""
|
||||
assert expect_float(12) == 12
|
||||
|
||||
@@ -90,10 +92,11 @@ def test_str_issue(msg):
|
||||
with pytest.raises(TypeError) as excinfo:
|
||||
str(StrIssue("no", "such", "constructor"))
|
||||
assert msg(excinfo.value) == """
|
||||
Incompatible constructor arguments. The following argument types are supported:
|
||||
__init__(): incompatible constructor arguments. The following argument types are supported:
|
||||
1. m.issues.StrIssue(arg0: int)
|
||||
2. m.issues.StrIssue()
|
||||
Invoked with: no, such, constructor
|
||||
|
||||
Invoked with: no, such, constructor
|
||||
"""
|
||||
|
||||
|
||||
|
||||
@@ -35,9 +35,10 @@ def test_named_arguments(msg):
|
||||
# noinspection PyArgumentList
|
||||
kw_func2(x=5, y=10, z=12)
|
||||
assert msg(excinfo.value) == """
|
||||
Incompatible function arguments. The following argument types are supported:
|
||||
kw_func2(): incompatible function arguments. The following argument types are supported:
|
||||
1. (x: int=100, y: int=200) -> str
|
||||
Invoked with:
|
||||
|
||||
Invoked with:
|
||||
"""
|
||||
|
||||
assert kw_func4() == "{13 17}"
|
||||
|
||||
@@ -35,9 +35,10 @@ def test_pointers(msg):
|
||||
with pytest.raises(TypeError) as excinfo:
|
||||
get_void_ptr_value([1, 2, 3]) # This should not work
|
||||
assert msg(excinfo.value) == """
|
||||
Incompatible function arguments. The following argument types are supported:
|
||||
get_void_ptr_value(): incompatible function arguments. The following argument types are supported:
|
||||
1. (arg0: capsule) -> int
|
||||
Invoked with: [1, 2, 3]
|
||||
|
||||
Invoked with: [1, 2, 3]
|
||||
"""
|
||||
|
||||
assert return_null_str() is None
|
||||
|
||||
Reference in New Issue
Block a user