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

Function TEST_SUBMODULE

deps/pybind11/tests/test_virtual_functions.cpp:234–414  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

232void initialize_inherited_virtuals(py::module_ &m);
233
234TEST_SUBMODULE(virtual_functions, m) {
235 // test_override
236 py::class_<ExampleVirt, PyExampleVirt>(m, "ExampleVirt")
237 .def(py::init<int>())
238 /* Reference original class in function definitions */
239 .def("run", &ExampleVirt::run)
240 .def("run_bool", &ExampleVirt::run_bool)
241 .def("pure_virtual", &ExampleVirt::pure_virtual);
242
243 py::class_<NonCopyable>(m, "NonCopyable").def(py::init<int, int>());
244
245 py::class_<Movable>(m, "Movable").def(py::init<int, int>());
246
247 // test_move_support
248#if !defined(__INTEL_COMPILER) && !defined(__CUDACC__) && !defined(__PGIC__)
249 py::class_<NCVirt, NCVirtTrampoline>(m, "NCVirt")
250 .def(py::init<>())
251 .def("get_noncopyable", &NCVirt::get_noncopyable)
252 .def("get_movable", &NCVirt::get_movable)
253 .def("print_nc", &NCVirt::print_nc)
254 .def("print_movable", &NCVirt::print_movable);
255#endif
256
257 m.def("runExampleVirt", [](ExampleVirt *ex, int value) { return ex->run(value); });
258 m.def("runExampleVirtBool", [](ExampleVirt *ex) { return ex->run_bool(); });
259 m.def("runExampleVirtVirtual", [](ExampleVirt *ex) { ex->pure_virtual(); });
260
261 m.def("cstats_debug", &ConstructorStats::get<ExampleVirt>);
262 initialize_inherited_virtuals(m);
263
264 // test_alias_delay_initialization1
265 // don't invoke Python dispatch classes by default when instantiating C++ classes
266 // that were not extended on the Python side
267 struct A {
268 A() = default;
269 A(const A &) = delete;
270 virtual ~A() = default;
271 virtual void f() { py::print("A.f()"); }
272 };
273
274 struct PyA : A {
275 PyA() { py::print("PyA.PyA()"); }
276 PyA(const PyA &) = delete;
277 ~PyA() override { py::print("PyA.~PyA()"); }
278
279 void f() override {
280 py::print("PyA.f()");
281 // This convolution just gives a `void`, but tests that PYBIND11_TYPE() works to
282 // protect a type containing a ,
283 PYBIND11_OVERRIDE(PYBIND11_TYPE(typename std::enable_if<true, void>::type), A, f);
284 }
285 };
286
287 py::class_<A, PyA>(m, "A").def(py::init<>()).def("f", &A::f);
288
289 m.def("call_f", [](A *a) { a->f(); });
290
291 // test_alias_delay_initialization2

Callers

nothing calls this directly

Calls 7

run_boolMethod · 0.80
pure_virtualMethod · 0.80
runMethod · 0.65
initFunction · 0.50
fMethod · 0.45
dispatchMethod · 0.45

Tested by

no test coverage detected