From de945f854a158e4d0e1c35331666b0f2cf483545 Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Sat, 23 Jan 2021 08:49:48 -0800 Subject: [PATCH] Adopting systematic naming scheme from test_classh_wip. NO functional changes. --- tests/classh_module_local_0.cpp | 14 +++++++------- tests/classh_module_local_1.cpp | 20 ++++++++++---------- tests/classh_module_local_2.cpp | 20 ++++++++++---------- tests/test_classh_module_local.py | 26 +++++++++++++------------- 4 files changed, 40 insertions(+), 40 deletions(-) diff --git a/tests/classh_module_local_0.cpp b/tests/classh_module_local_0.cpp index 1e543c824..39c391c95 100644 --- a/tests/classh_module_local_0.cpp +++ b/tests/classh_module_local_0.cpp @@ -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); } diff --git a/tests/classh_module_local_1.cpp b/tests/classh_module_local_1.cpp index 456c863c1..04e21cf08 100644 --- a/tests/classh_module_local_1.cpp +++ b/tests/classh_module_local_1.cpp @@ -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(m, "bottle", py::module_local()) - .def(py::init([](const std::string &msg) { - bottle obj; - obj.msg = msg; + py::classh(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); } diff --git a/tests/classh_module_local_2.cpp b/tests/classh_module_local_2.cpp index f9837e889..596e6626d 100644 --- a/tests/classh_module_local_2.cpp +++ b/tests/classh_module_local_2.cpp @@ -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(m, "bottle", py::module_local()) - .def(py::init([](const std::string &msg) { - bottle obj; - obj.msg = msg; + py::classh(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); } diff --git a/tests/test_classh_module_local.py b/tests/test_classh_module_local.py index b9e6b414c..f7113efe5 100644 --- a/tests/test_classh_module_local.py +++ b/tests/test_classh_module_local.py @@ -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!" )