MCPcopy Create free account
hub / github.com/apple/coremltools / TEST_SUBMODULE

Function TEST_SUBMODULE

deps/pybind11/tests/test_callbacks.cpp:19–280  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

17int dummy_function(int i) { return i + 1; }
18
19TEST_SUBMODULE(callbacks, m) {
20 // test_callbacks, test_function_signatures
21 m.def("test_callback1", [](const py::object &func) { return func(); });
22 m.def("test_callback2", [](const py::object &func) { return func("Hello", 'x', true, 5); });
23 m.def("test_callback3", [](const std::function<int(int)> &func) {
24 return "func(43) = " + std::to_string(func(43));
25 });
26 m.def("test_callback4",
27 []() -> std::function<int(int)> { return [](int i) { return i + 1; }; });
28 m.def("test_callback5",
29 []() { return py::cpp_function([](int i) { return i + 1; }, py::arg("number")); });
30
31 // test_keyword_args_and_generalized_unpacking
32 m.def("test_tuple_unpacking", [](const py::function &f) {
33 auto t1 = py::make_tuple(2, 3);
34 auto t2 = py::make_tuple(5, 6);
35 return f("positional", 1, *t1, 4, *t2);
36 });
37
38 m.def("test_dict_unpacking", [](const py::function &f) {
39 auto d1 = py::dict("key"_a = "value", "a"_a = 1);
40 auto d2 = py::dict();
41 auto d3 = py::dict("b"_a = 2);
42 return f("positional", 1, **d1, **d2, **d3);
43 });
44
45 m.def("test_keyword_args", [](const py::function &f) { return f("x"_a = 10, "y"_a = 20); });
46
47 m.def("test_unpacking_and_keywords1", [](const py::function &f) {
48 auto args = py::make_tuple(2);
49 auto kwargs = py::dict("d"_a = 4);
50 return f(1, *args, "c"_a = 3, **kwargs);
51 });
52
53 m.def("test_unpacking_and_keywords2", [](const py::function &f) {
54 auto kwargs1 = py::dict("a"_a = 1);
55 auto kwargs2 = py::dict("c"_a = 3, "d"_a = 4);
56 return f("positional",
57 *py::make_tuple(1),
58 2,
59 *py::make_tuple(3, 4),
60 5,
61 "key"_a = "value",
62 **kwargs1,
63 "b"_a = 2,
64 **kwargs2,
65 "e"_a = 5);
66 });
67
68 m.def("test_unpacking_error1", [](const py::function &f) {
69 auto kwargs = py::dict("x"_a = 3);
70 return f("x"_a = 1, "y"_a = 2, **kwargs); // duplicate ** after keyword
71 });
72
73 m.def("test_unpacking_error2", [](const py::function &f) {
74 auto kwargs = py::dict("x"_a = 3);
75 return f(**kwargs, "x"_a = 1); // duplicate keyword after **
76 });

Callers

nothing calls this directly

Calls 15

to_stringFunction · 0.85
cpp_functionClass · 0.85
fFunction · 0.85
UnregisteredTypeClass · 0.85
silence_unused_warningsFunction · 0.85
moveFunction · 0.85
MovableObjectClass · 0.85
noneClass · 0.85
aliveMethod · 0.80
ptrMethod · 0.80
funcFunction · 0.70
argClass · 0.50

Tested by

no test coverage detected