MCPcopy Create free account
hub / github.com/pybind/pybind11 / test_callbacks

Function test_callbacks

tests/test_callbacks.py:14–35  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

12
13
14def test_callbacks():
15 from functools import partial
16
17 def func1():
18 return "func1"
19
20 def func2(a, b, c, d):
21 return "func2", a, b, c, d
22
23 def func3(a):
24 return f"func3({a})"
25
26 assert m.test_callback1(func1) == "func1"
27 assert m.test_callback2(func2) == ("func2", "Hello", "x", True, 5)
28 assert m.test_callback1(partial(func2, 1, 2, 3, 4)) == ("func2", 1, 2, 3, 4)
29 assert m.test_callback1(partial(func3, "partial")) == "func3(partial)"
30 assert m.test_callback3(lambda i: i + 1) == "func(43) = 44"
31
32 f = m.test_callback4()
33 assert f(43) == 44
34 f = m.test_callback5()
35 assert f(number=43) == 44
36
37
38def test_bound_method_callback():

Callers

nothing calls this directly

Calls 1

fFunction · 0.85

Tested by

no test coverage detected