mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-22 13:15:12 +00:00
test_enum.cpp,py copied from remove_cross_extension_shared_state branch
This commit is contained in:
parent
edf03ccd34
commit
0286e5a2d6
@ -130,4 +130,20 @@ TEST_SUBMODULE(enums, m) {
|
||||
py::enum_<ScopedBoolEnum>(m, "ScopedBoolEnum")
|
||||
.value("FALSE", ScopedBoolEnum::FALSE)
|
||||
.value("TRUE", ScopedBoolEnum::TRUE);
|
||||
|
||||
#if defined(__MINGW32__)
|
||||
m.attr("obj_cast_UnscopedEnum_ptr") = "MinGW: dangling pointer to an unnamed temporary may be "
|
||||
"used [-Werror=dangling-pointer=]";
|
||||
#else
|
||||
m.def("obj_cast_UnscopedEnum_ptr", [](const py::object &obj) {
|
||||
// https://github.com/OpenImageIO/oiio/blob/30ea4ebdfab11aec291befbaff446f2a7d24835b/src/python/py_oiio.h#L300
|
||||
if (py::isinstance<UnscopedEnum>(obj)) {
|
||||
if (*obj.cast<UnscopedEnum *>() == UnscopedEnum::ETwo) {
|
||||
return 2;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
#endif
|
||||
}
|
||||
|
@ -268,3 +268,12 @@ def test_docstring_signatures():
|
||||
def test_str_signature():
|
||||
for enum_type in [m.ScopedEnum, m.UnscopedEnum]:
|
||||
assert enum_type.__str__.__doc__.startswith("__str__")
|
||||
|
||||
|
||||
@pytest.mark.skipif(
|
||||
isinstance(m.obj_cast_UnscopedEnum_ptr, str), reason=m.obj_cast_UnscopedEnum_ptr
|
||||
)
|
||||
def test_obj_cast_unscoped_enum_ptr():
|
||||
assert m.obj_cast_UnscopedEnum_ptr(m.UnscopedEnum.ETwo) == 2
|
||||
assert m.obj_cast_UnscopedEnum_ptr(m.UnscopedEnum.EOne) == 1
|
||||
assert m.obj_cast_UnscopedEnum_ptr(None) == 0
|
||||
|
Loading…
Reference in New Issue
Block a user