Adding mpty::mtxt string member.

This commit is contained in:
Ralf W. Grosse-Kunstleve 2021-01-11 15:58:14 -08:00
parent c8d19f9599
commit 1ce4256921
2 changed files with 9 additions and 2 deletions

View File

@ -3,11 +3,12 @@
#include <pybind11/classh.h> #include <pybind11/classh.h>
#include <memory> #include <memory>
#include <string>
namespace pybind11_tests { namespace pybind11_tests {
namespace classh_wip { namespace classh_wip {
struct mpty {}; struct mpty { std::string mtxt; };
mpty rtrn_mpty_valu() { mpty obj; return obj; } mpty rtrn_mpty_valu() { mpty obj; return obj; }
mpty&& rtrn_mpty_rref() { mpty obj; return std::move(obj); } mpty&& rtrn_mpty_rref() { mpty obj; return std::move(obj); }
@ -192,6 +193,8 @@ TEST_SUBMODULE(classh_wip, m) {
py::classh<mpty>(m, "mpty") py::classh<mpty>(m, "mpty")
.def(py::init<>()) .def(py::init<>())
.def(py::init([](const std::string& mtxt) {
mpty obj; obj.mtxt = mtxt; return obj; }))
; ;
m.def("rtrn_mpty_valu", rtrn_mpty_valu); m.def("rtrn_mpty_valu", rtrn_mpty_valu);

View File

@ -4,9 +4,13 @@ import pytest
from pybind11_tests import classh_wip as m from pybind11_tests import classh_wip as m
def test_mpty(): def test_mpty_constructors():
e = m.mpty() e = m.mpty()
assert e.__class__.__name__ == "mpty" assert e.__class__.__name__ == "mpty"
e = m.mpty("")
assert e.__class__.__name__ == "mpty"
e = m.mpty("txtm")
assert e.__class__.__name__ == "mpty"
def test_cast(): def test_cast():