3 from pybind11_tests
import custom_type_casters
as m
8 assert msg(a.f(
"hi")) ==
""" 9 loading ArgInspector1 argument WITH conversion allowed. Argument value = hi 11 assert msg(a.g(
"this is a",
"this is b")) ==
""" 12 loading ArgInspector1 argument WITHOUT conversion allowed. Argument value = this is a 13 loading ArgInspector1 argument WITH conversion allowed. Argument value = this is b 15 loading ArgInspector2 argument WITH conversion allowed. Argument value = (default arg inspector 2) 17 assert msg(a.g(
"this is a",
"this is b", 42)) ==
""" 18 loading ArgInspector1 argument WITHOUT conversion allowed. Argument value = this is a 19 loading ArgInspector1 argument WITH conversion allowed. Argument value = this is b 21 loading ArgInspector2 argument WITH conversion allowed. Argument value = (default arg inspector 2) 23 assert msg(a.g(
"this is a",
"this is b", 42,
"this is d")) ==
""" 24 loading ArgInspector1 argument WITHOUT conversion allowed. Argument value = this is a 25 loading ArgInspector1 argument WITH conversion allowed. Argument value = this is b 27 loading ArgInspector2 argument WITH conversion allowed. Argument value = this is d 29 assert (a.h(
"arg 1") ==
30 "loading ArgInspector2 argument WITHOUT conversion allowed. Argument value = arg 1")
31 assert msg(m.arg_inspect_func(
"A1",
"A2")) ==
""" 32 loading ArgInspector2 argument WITH conversion allowed. Argument value = A1 33 loading ArgInspector1 argument WITHOUT conversion allowed. Argument value = A2 36 assert m.floats_preferred(4) == 2.0
37 assert m.floats_only(4.0) == 2.0
38 with pytest.raises(TypeError)
as excinfo:
40 assert msg(excinfo.value) ==
""" 41 floats_only(): incompatible function arguments. The following argument types are supported: 42 1. (f: float) -> float 47 assert m.ints_preferred(4) == 2
48 assert m.ints_preferred(
True) == 0
49 with pytest.raises(TypeError)
as excinfo:
51 assert msg(excinfo.value) ==
""" 52 ints_preferred(): incompatible function arguments. The following argument types are supported: 58 assert m.ints_only(4) == 2
59 with pytest.raises(TypeError)
as excinfo:
61 assert msg(excinfo.value) ==
""" 62 ints_only(): incompatible function arguments. The following argument types are supported: 70 """Tests that returning a pointer to a type that gets converted with a custom type caster gets 71 destroyed when the function has py::return_value_policy::take_ownership policy applied.""" 73 cstats = m.destruction_tester_cstats()
75 z = m.custom_caster_no_destroy()
76 assert cstats.alive() == 1
and cstats.default_constructions == 1
80 z = m.custom_caster_destroy()
82 assert cstats.default_constructions == 2
85 z = m.custom_caster_destroy_const()
87 assert cstats.default_constructions == 3
90 assert cstats.alive() == 1
def test_custom_caster_destruction()
def test_noconvert_args(msg)