mirror of
https://github.com/pybind/pybind11.git
synced 2025-02-21 16:09:22 +00:00
Adopting systematic naming scheme from test_classh_wip. NO functional changes.
This commit is contained in:
parent
235fa288b8
commit
de945f854a
@ -5,23 +5,23 @@
|
|||||||
namespace pybind11_tests {
|
namespace pybind11_tests {
|
||||||
namespace classh_module_local {
|
namespace classh_module_local {
|
||||||
|
|
||||||
struct bottle {
|
struct atyp { // Short for "any type".
|
||||||
std::string msg;
|
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 classh_module_local
|
||||||
} // namespace pybind11_tests
|
} // 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) {
|
PYBIND11_MODULE(classh_module_local_0, m) {
|
||||||
using namespace pybind11_tests::classh_module_local;
|
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);
|
||||||
}
|
}
|
||||||
|
@ -6,28 +6,28 @@
|
|||||||
namespace pybind11_tests {
|
namespace pybind11_tests {
|
||||||
namespace classh_module_local {
|
namespace classh_module_local {
|
||||||
|
|
||||||
struct bottle {
|
struct atyp { // Short for "any type".
|
||||||
std::string msg;
|
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 classh_module_local
|
||||||
} // namespace pybind11_tests
|
} // 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) {
|
PYBIND11_MODULE(classh_module_local_1, m) {
|
||||||
namespace py = pybind11;
|
namespace py = pybind11;
|
||||||
using namespace pybind11_tests::classh_module_local;
|
using namespace pybind11_tests::classh_module_local;
|
||||||
|
|
||||||
py::classh<bottle>(m, "bottle", py::module_local())
|
py::classh<atyp>(m, "atyp", py::module_local())
|
||||||
.def(py::init([](const std::string &msg) {
|
.def(py::init([](const std::string &mtxt) {
|
||||||
bottle obj;
|
atyp obj;
|
||||||
obj.msg = msg;
|
obj.mtxt = mtxt;
|
||||||
return obj;
|
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);
|
||||||
}
|
}
|
||||||
|
@ -6,28 +6,28 @@
|
|||||||
namespace pybind11_tests {
|
namespace pybind11_tests {
|
||||||
namespace classh_module_local {
|
namespace classh_module_local {
|
||||||
|
|
||||||
struct bottle {
|
struct atyp { // Short for "any type".
|
||||||
std::string msg;
|
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 classh_module_local
|
||||||
} // namespace pybind11_tests
|
} // 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) {
|
PYBIND11_MODULE(classh_module_local_2, m) {
|
||||||
namespace py = pybind11;
|
namespace py = pybind11;
|
||||||
using namespace pybind11_tests::classh_module_local;
|
using namespace pybind11_tests::classh_module_local;
|
||||||
|
|
||||||
py::classh<bottle>(m, "bottle", py::module_local())
|
py::classh<atyp>(m, "atyp", py::module_local())
|
||||||
.def(py::init([](const std::string &msg) {
|
.def(py::init([](const std::string &mtxt) {
|
||||||
bottle obj;
|
atyp obj;
|
||||||
obj.msg = msg;
|
obj.mtxt = mtxt;
|
||||||
return obj;
|
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);
|
||||||
}
|
}
|
||||||
|
@ -6,22 +6,22 @@ import classh_module_local_1 as m1
|
|||||||
import classh_module_local_2 as m2
|
import classh_module_local_2 as m2
|
||||||
|
|
||||||
|
|
||||||
def test_cross_module_get_msg():
|
def test_cross_module_get_mtxt():
|
||||||
b1 = m1.bottle("A")
|
obj1 = m1.atyp("A")
|
||||||
assert b1.tag() == 1
|
assert obj1.tag() == 1
|
||||||
b2 = m2.bottle("B")
|
obj2 = m2.atyp("B")
|
||||||
assert b2.tag() == 2
|
assert obj2.tag() == 2
|
||||||
assert m1.get_msg(b1) == "A"
|
assert m1.get_mtxt(obj1) == "A"
|
||||||
assert m2.get_msg(b2) == "B"
|
assert m2.get_mtxt(obj2) == "B"
|
||||||
assert m1.get_msg(b2) == "B"
|
assert m1.get_mtxt(obj2) == "B"
|
||||||
assert m2.get_msg(b1) == "A"
|
assert m2.get_mtxt(obj1) == "A"
|
||||||
assert m0.get_msg(b1) == "A"
|
assert m0.get_mtxt(obj1) == "A"
|
||||||
assert m0.get_msg(b2) == "B"
|
assert m0.get_mtxt(obj2) == "B"
|
||||||
|
|
||||||
|
|
||||||
def test_m0_make_bottle():
|
def test_m0_rtrn_valu_atyp():
|
||||||
with pytest.raises(TypeError) as exc_info:
|
with pytest.raises(TypeError) as exc_info:
|
||||||
m0.make_bottle()
|
m0.rtrn_valu_atyp()
|
||||||
assert str(exc_info.value).startswith(
|
assert str(exc_info.value).startswith(
|
||||||
"Unable to convert function return value to a Python type!"
|
"Unable to convert function return value to a Python type!"
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user