def test_bound_method_callback(): from pybind11_tests import test_callback3, CppBoundMethodTest # Bound Python method: class MyClass: def double(self, val): return 2 * val z = MyClass() assert test_callback3(z.double) == "func(43) = 86" z = CppBoundMethodTest() assert test_callback3(z.triple) == "func(43) = 129"
def test_callbacks(): from functools import partial from pybind11_tests import (test_callback1, test_callback2, test_callback3, test_callback4, test_callback5) def func1(): return "func1" def func2(a, b, c, d): return "func2", a, b, c, d def func3(a): return "func3({})".format(a) if test_callback1(func1) != "func1": raise AssertionError if test_callback2(func2) != ("func2", "Hello", "x", True, 5): raise AssertionError if test_callback1(partial(func2, 1, 2, 3, 4)) != ("func2", 1, 2, 3, 4): raise AssertionError if test_callback1(partial(func3, "partial")) != "func3(partial)": raise AssertionError if test_callback3(lambda i: i + 1) != "func(43) = 44": raise AssertionError f = test_callback4() if f(43) != 44: raise AssertionError f = test_callback5() if f(number=43) != 44: raise AssertionError
def test_callbacks(): from functools import partial from pybind11_tests import (test_callback1, test_callback2, test_callback3, test_callback4, test_callback5) def func1(): return "func1" def func2(a, b, c, d): return "func2", a, b, c, d def func3(a): return "func3({})".format(a) assert test_callback1(func1) == "func1" assert test_callback2(func2) == ("func2", "Hello", "x", True, 5) assert test_callback1(partial(func2, 1, 2, 3, 4)) == ("func2", 1, 2, 3, 4) assert test_callback1(partial(func3, "partial")) == "func3(partial)" assert test_callback3(lambda i: i + 1) == "func(43) = 44" f = test_callback4() assert f(43) == 44 f = test_callback5() assert f(number=43) == 44