forked from pybind/pybind11
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New test_class_sh_property_bakein.py
Use cases in the wild: * `test_readonly_char6_member()`: https://github.com/pytorch/pytorch/blob/4410c44ae6fd8eb36f2358ac76f7d988ca7537c5/torch/csrc/cuda/Module.cpp#L961 * `test_readonly_const_char_ptr_member()`: https://github.com/facebookresearch/nle/blob/862a439a84f52abca94d1f744d57061da12c5831/include/permonst.h#L43
- Loading branch information
Ralf W. Grosse-Kunstleve
committed
Jul 14, 2024
1 parent
2600bb6
commit 3406be6
Showing
4 changed files
with
42 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#include "pybind11_tests.h" | ||
|
||
namespace test_class_sh_property_bakein { | ||
|
||
struct WithCharArrayMember { | ||
WithCharArrayMember() { std::strcpy(char6_member, "Char6"); } | ||
char char6_member[6]; | ||
}; | ||
|
||
struct WithConstCharPtrMember { | ||
const char *const_char_ptr_member = "ConstChar*"; | ||
}; | ||
|
||
} // namespace test_class_sh_property_bakein | ||
|
||
TEST_SUBMODULE(class_sh_property_bakein, m) { | ||
using namespace test_class_sh_property_bakein; | ||
|
||
py::class_<WithCharArrayMember>(m, "WithCharArrayMember") | ||
.def(py::init<>()) | ||
.def_readonly("char6_member", &WithCharArrayMember::char6_member); | ||
|
||
py::class_<WithConstCharPtrMember>(m, "WithConstCharPtrMember") | ||
.def(py::init<>()) | ||
.def_readonly("const_char_ptr_member", &WithConstCharPtrMember::const_char_ptr_member); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from __future__ import annotations | ||
|
||
from pybind11_tests import class_sh_property_bakein as m | ||
|
||
|
||
def test_readonly_char6_member(): | ||
obj = m.WithCharArrayMember() | ||
assert obj.char6_member == "Char6" | ||
|
||
|
||
def test_readonly_const_char_ptr_member(): | ||
obj = m.WithConstCharPtrMember() | ||
assert obj.const_char_ptr_member == "ConstChar*" |