|
4 | 4 |
|
5 | 5 | import exo_planet_c_api
|
6 | 6 | import exo_planet_pybind11
|
| 7 | +import home_planet_very_lonely_traveler |
7 | 8 | import pytest
|
8 | 9 |
|
9 | 10 | from pybind11_tests import cpp_conduit as home_planet
|
@@ -125,3 +126,37 @@ def test_exo_planet_c_api_premium_traveler(premium_traveler_type):
|
125 | 126 | pt = premium_traveler_type("gucci", 5)
|
126 | 127 | assert exo_planet_c_api.GetLuggage(pt) == "gucci"
|
127 | 128 | assert exo_planet_c_api.GetPoints(pt) == 5
|
| 129 | + |
| 130 | + |
| 131 | +def test_home_planet_wrap_very_lonely_traveler(): |
| 132 | + # This does not exercise the cpp_conduit feature, but is here to |
| 133 | + # demonstrate that the cpp_conduit feature does not solve all |
| 134 | + # cross-extension interoperability issues. |
| 135 | + # Here is the proof that the following works for extensions with |
| 136 | + # matching `PYBIND11_INTERNALS_ID`s: |
| 137 | + # test_cpp_conduit.cpp: |
| 138 | + # py::class_<LonelyTraveler> |
| 139 | + # home_planet_very_lonely_traveler.cpp: |
| 140 | + # py::class_<VeryLonelyTraveler, LonelyTraveler> |
| 141 | + # See test_exo_planet_pybind11_wrap_very_lonely_traveler() for the negative |
| 142 | + # test. |
| 143 | + assert home_planet.LonelyTraveler is not None # Verify that the base class exists. |
| 144 | + home_planet_very_lonely_traveler.wrap_very_lonely_traveler() |
| 145 | + # Ensure that the derived class exists. |
| 146 | + assert home_planet_very_lonely_traveler.VeryLonelyTraveler is not None |
| 147 | + |
| 148 | + |
| 149 | +def test_exo_planet_pybind11_wrap_very_lonely_traveler(): |
| 150 | + # See comment under test_home_planet_wrap_very_lonely_traveler() first. |
| 151 | + # Here the `PYBIND11_INTERNALS_ID`s don't match between: |
| 152 | + # test_cpp_conduit.cpp: |
| 153 | + # py::class_<LonelyTraveler> |
| 154 | + # exo_planet_pybind11.cpp: |
| 155 | + # py::class_<VeryLonelyTraveler, LonelyTraveler> |
| 156 | + assert home_planet.LonelyTraveler is not None # Verify that the base class exists. |
| 157 | + with pytest.raises( |
| 158 | + RuntimeError, |
| 159 | + match='^generic_type: type "VeryLonelyTraveler" referenced unknown base type ' |
| 160 | + '"pybind11_tests::test_cpp_conduit::LonelyTraveler"$', |
| 161 | + ): |
| 162 | + exo_planet_pybind11.wrap_very_lonely_traveler() |
0 commit comments