Adopting systematic naming scheme from test_classh_wip. NO functional changes.

This commit is contained in:
Ralf W. Grosse-Kunstleve 2021-01-23 08:49:48 -08:00
parent 235fa288b8
commit de945f854a
4 changed files with 40 additions and 40 deletions

View File

@ -5,23 +5,23 @@
namespace pybind11_tests {
namespace classh_module_local {
struct bottle {
std::string msg;
struct atyp { // Short for "any type".
std::string mtxt;
};
std::string get_msg(const bottle &b) { return b.msg; }
std::string get_mtxt(const atyp &obj) { return obj.mtxt; }
bottle make_bottle() { return bottle(); }
atyp rtrn_valu_atyp() { return atyp(); }
} // namespace classh_module_local
} // namespace pybind11_tests
PYBIND11_CLASSH_TYPE_CASTERS(pybind11_tests::classh_module_local::bottle)
PYBIND11_CLASSH_TYPE_CASTERS(pybind11_tests::classh_module_local::atyp)
PYBIND11_MODULE(classh_module_local_0, m) {
using namespace pybind11_tests::classh_module_local;
m.def("get_msg", get_msg);
m.def("get_mtxt", get_mtxt);
m.def("make_bottle", make_bottle);
m.def("rtrn_valu_atyp", rtrn_valu_atyp);
}

View File

@ -6,28 +6,28 @@
namespace pybind11_tests {
namespace classh_module_local {
struct bottle {
std::string msg;
struct atyp { // Short for "any type".
std::string mtxt;
};
std::string get_msg(const bottle &b) { return b.msg; }
std::string get_mtxt(const atyp &obj) { return obj.mtxt; }
} // namespace classh_module_local
} // namespace pybind11_tests
PYBIND11_CLASSH_TYPE_CASTERS(pybind11_tests::classh_module_local::bottle)
PYBIND11_CLASSH_TYPE_CASTERS(pybind11_tests::classh_module_local::atyp)
PYBIND11_MODULE(classh_module_local_1, m) {
namespace py = pybind11;
using namespace pybind11_tests::classh_module_local;
py::classh<bottle>(m, "bottle", py::module_local())
.def(py::init([](const std::string &msg) {
bottle obj;
obj.msg = msg;
py::classh<atyp>(m, "atyp", py::module_local())
.def(py::init([](const std::string &mtxt) {
atyp obj;
obj.mtxt = mtxt;
return obj;
}))
.def("tag", [](const bottle &) { return 1; });
.def("tag", [](const atyp &) { return 1; });
m.def("get_msg", get_msg);
m.def("get_mtxt", get_mtxt);
}

View File

@ -6,28 +6,28 @@
namespace pybind11_tests {
namespace classh_module_local {
struct bottle {
std::string msg;
struct atyp { // Short for "any type".
std::string mtxt;
};
std::string get_msg(const bottle &b) { return b.msg; }
std::string get_mtxt(const atyp &obj) { return obj.mtxt; }
} // namespace classh_module_local
} // namespace pybind11_tests
PYBIND11_CLASSH_TYPE_CASTERS(pybind11_tests::classh_module_local::bottle)
PYBIND11_CLASSH_TYPE_CASTERS(pybind11_tests::classh_module_local::atyp)
PYBIND11_MODULE(classh_module_local_2, m) {
namespace py = pybind11;
using namespace pybind11_tests::classh_module_local;
py::classh<bottle>(m, "bottle", py::module_local())
.def(py::init([](const std::string &msg) {
bottle obj;
obj.msg = msg;
py::classh<atyp>(m, "atyp", py::module_local())
.def(py::init([](const std::string &mtxt) {
atyp obj;
obj.mtxt = mtxt;
return obj;
}))
.def("tag", [](const bottle &) { return 2; });
.def("tag", [](const atyp &) { return 2; });
m.def("get_msg", get_msg);
m.def("get_mtxt", get_mtxt);
}

View File

@ -6,22 +6,22 @@ import classh_module_local_1 as m1
import classh_module_local_2 as m2
def test_cross_module_get_msg():
b1 = m1.bottle("A")
assert b1.tag() == 1
b2 = m2.bottle("B")
assert b2.tag() == 2
assert m1.get_msg(b1) == "A"
assert m2.get_msg(b2) == "B"
assert m1.get_msg(b2) == "B"
assert m2.get_msg(b1) == "A"
assert m0.get_msg(b1) == "A"
assert m0.get_msg(b2) == "B"
def test_cross_module_get_mtxt():
obj1 = m1.atyp("A")
assert obj1.tag() == 1
obj2 = m2.atyp("B")
assert obj2.tag() == 2
assert m1.get_mtxt(obj1) == "A"
assert m2.get_mtxt(obj2) == "B"
assert m1.get_mtxt(obj2) == "B"
assert m2.get_mtxt(obj1) == "A"
assert m0.get_mtxt(obj1) == "A"
assert m0.get_mtxt(obj2) == "B"
def test_m0_make_bottle():
def test_m0_rtrn_valu_atyp():
with pytest.raises(TypeError) as exc_info:
m0.make_bottle()
m0.rtrn_valu_atyp()
assert str(exc_info.value).startswith(
"Unable to convert function return value to a Python type!"
)