diff --git a/tests/test_wip.cpp b/tests/test_wip.cpp index e34b85db5..d6210917e 100644 --- a/tests/test_wip.cpp +++ b/tests/test_wip.cpp @@ -1,21 +1,32 @@ +#include + #include "pybind11_tests.h" namespace pybind11_tests { namespace wip { -struct SomeType {}; +template // Using int as a trick to easily generate a series of types. +struct Atype { + int val = 0; + explicit Atype(int val_) : val{val_} {} + int get() const { return val * 10 + SerNo; } +}; + +int mixed(std::unique_ptr> at1, std::unique_ptr> at2) { + return at1->get() * 200 + at2->get() * 20; +} } // namespace wip } // namespace pybind11_tests +using namespace pybind11_tests::wip; + +PYBIND11_SMART_HOLDER_TYPE_CASTERS(Atype<1>) +PYBIND11_SMART_HOLDER_TYPE_CASTERS(Atype<2>) + TEST_SUBMODULE(wip, m) { - m.attr("__doc__") = "WIP"; + py::classh>(m, "Atype1").def(py::init()).def("get", &Atype<1>::get); + py::classh>(m, "Atype2").def(py::init()).def("get", &Atype<2>::get); - using namespace pybind11_tests::wip; - - py::class_(m, "SomeType").def(py::init([]() { - return std::unique_ptr(new SomeType); - })); - - m.def("make_some_type", []() { return std::unique_ptr(new SomeType); }); + m.def("mixed", mixed); } diff --git a/tests/test_wip.py b/tests/test_wip.py index 6b5d7956f..f4f7680fc 100644 --- a/tests/test_wip.py +++ b/tests/test_wip.py @@ -1,17 +1,26 @@ from __future__ import annotations +import pytest + from pybind11_tests import wip as m -def test_doc(): - assert m.__doc__ == "WIP" +def test_mixed(): + obj1a = m.Atype1(90) + obj2a = m.Atype2(25) + obj1b = m.Atype1(0) + obj2b = m.Atype2(0) + print("\nLOOOK A BEFORE m.mixed(obj1a, obj2a)", flush=True) + assert m.mixed(obj1a, obj2a) == (90 * 10 + 1) * 200 + (25 * 10 + 2) * 20 + print("\nLOOOK A AFTER m.mixed(obj1a, obj2a)", flush=True) -def test_some_type_ctor(): - obj = m.SomeType() - assert isinstance(obj, m.SomeType) + print("\nLOOOK B BEFORE m.mixed(obj1b, obj2a)", flush=True) + with pytest.raises(ValueError): + m.mixed(obj1b, obj2a) + print("\nLOOOK B AFTER m.mixed(obj1b, obj2a)", flush=True) - -def test_make_some_type(): - obj = m.make_some_type() - assert isinstance(obj, m.SomeType) + print("\nLOOOK C BEFORE m.mixed(obj1a, obj2b)", flush=True) + with pytest.raises(ValueError): + m.mixed(obj1a, obj2b) + print("\nLOOOK C AFTER m.mixed(obj1a, obj2b)", flush=True)