| 14 | #include <utility> |
| 15 | |
| 16 | TEST_SUBMODULE(warnings_, m) { |
| 17 | |
| 18 | // Test warning mechanism base |
| 19 | m.def("warn_and_return_value", []() { |
| 20 | std::string message = "This is simple warning"; |
| 21 | py::warnings::warn(message.c_str(), PyExc_Warning); |
| 22 | return 21; |
| 23 | }); |
| 24 | |
| 25 | m.def("warn_with_default_category", []() { py::warnings::warn("This is RuntimeWarning"); }); |
| 26 | |
| 27 | m.def("warn_with_different_category", |
| 28 | []() { py::warnings::warn("This is FutureWarning", PyExc_FutureWarning); }); |
| 29 | |
| 30 | m.def("warn_with_invalid_category", |
| 31 | []() { py::warnings::warn("Invalid category", PyExc_Exception); }); |
| 32 | |
| 33 | // Test custom warnings |
| 34 | PYBIND11_CONSTINIT static py::gil_safe_call_once_and_store<py::object> ex_storage; |
| 35 | ex_storage.call_once_and_store_result([&]() { |
| 36 | return py::warnings::new_warning_type(m, "CustomWarning", PyExc_DeprecationWarning); |
| 37 | }); |
| 38 | |
| 39 | m.def("warn_with_custom_type", []() { |
| 40 | py::warnings::warn("This is CustomWarning", ex_storage.get_stored()); |
| 41 | return 37; |
| 42 | }); |
| 43 | |
| 44 | m.def("register_duplicate_warning", |
| 45 | [m]() { py::warnings::new_warning_type(m, "CustomWarning", PyExc_RuntimeWarning); }); |
| 46 | } |
nothing calls this directly
no test coverage detected