Skip to content

Commit

Permalink
Add test_pyobject_ptr_from_handle_nullptr (no production code chang…
Browse files Browse the repository at this point in the history
…es), to firmly establish that this part works already.
  • Loading branch information
Ralf W. Grosse-Kunstleve committed Dec 1, 2023
1 parent a67d786 commit a3fd84d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tests/test_type_caster_pyobject_ptr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,16 @@ TEST_SUBMODULE(type_caster_pyobject_ptr, m) {
(void) py::cast(*ptr);
}
#endif

m.def("pyobject_ptr_from_handle_nullptr", []() {
py::handle handle_nullptr;
if (handle_nullptr.ptr() != nullptr) {
return "UNEXPECTED: handle_nullptr.ptr() != nullptr";
}
auto *pyobject_ptr_from_handle = py::cast<PyObject *>(handle_nullptr);
if (pyobject_ptr_from_handle != nullptr) {
return "UNEXPECTED: pyobject_ptr_from_handle != nullptr";
}
return "SUCCESS";
});
}
4 changes: 4 additions & 0 deletions tests/test_type_caster_pyobject_ptr.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,7 @@ def test_return_list_pyobject_ptr_reference():
def test_type_caster_name_via_incompatible_function_arguments_type_error():
with pytest.raises(TypeError, match=r"1\. \(arg0: object, arg1: int\) -> None"):
m.pass_pyobject_ptr_and_int(ValueHolder(101), ValueHolder(202))


def test_pyobject_ptr_from_handle_nullptr():
assert m.pyobject_ptr_from_handle_nullptr() == "SUCCESS"

0 comments on commit a3fd84d

Please sign in to comment.