pybind11/tests/test_class_sh_inheritance.py
Ralf W. Grosse-Kunstleve 5ab036bf08
[smart_holder] Simplification: Enable smart_holder functionality unconditionally. (#5531)
* git merge --squash purge_internals_versions_4_5

* Remove PYBIND11_HAS_INTERNALS_WITH_SMART_HOLDER_SUPPORT, set PYBIND11_INTERNALS_VERSION 7

* Remove all uses of PYBIND11_SMART_HOLDER_ENABLED under include/pybind11

* Remove obsolete PYBIND11_ACTUALLY_USING_SMART_HOLDER_AS_DEFAULT macro.

* Remove PYBIND11_SMART_HOLDER_ENABLED in ubench/holder_comparison.cpp

* Remove all uses of PYBIND11_SMART_HOLDER_ENABLED under tests/

* Remove `#define PYBIND11_SMART_HOLDER_ENABLED`

* Remove all uses of PYBIND11_SMART_HOLDER_TYPE_CASTERS under tests/

* Remove all uses of PYBIND11_TYPE_CASTER_BASE_HOLDER under tests/

* Add missing `#include <cstdint>`

Example error message (🐍 3.11 • ubuntu-latest • x64, GNU 13.3.0):

```
include/pybind11/detail/value_and_holder.h:56:52: error: ‘uint8_t’ is not a member of ‘std’; did you mean ‘wint_t’?
   56 |             inst->nonsimple.status[index] &= (std::uint8_t) ~instance::status_holder_constructed;
      |                                                    ^~~~~~~
```

* Change PYBIND11_INTERNALS_VERSION to 106: It will be changed to 7 in a follow-on PR that actually changes the internals.
2025-02-22 10:22:20 -08:00

64 lines
1.7 KiB
Python

from __future__ import annotations
from pybind11_tests import class_sh_inheritance as m
def test_rtrn_mptr_drvd_pass_cptr_base():
d = m.rtrn_mptr_drvd()
i = m.pass_cptr_base(d) # load_impl Case 2a
assert i == 2 * 100 + 11
def test_rtrn_shmp_drvd_pass_shcp_base():
d = m.rtrn_shmp_drvd()
i = m.pass_shcp_base(d) # load_impl Case 2a
assert i == 2 * 100 + 21
def test_rtrn_mptr_drvd_up_cast_pass_cptr_drvd():
b = m.rtrn_mptr_drvd_up_cast()
# the base return is down-cast immediately.
assert b.__class__.__name__ == "drvd"
i = m.pass_cptr_drvd(b)
assert i == 2 * 100 + 12
def test_rtrn_shmp_drvd_up_cast_pass_shcp_drvd():
b = m.rtrn_shmp_drvd_up_cast()
# the base return is down-cast immediately.
assert b.__class__.__name__ == "drvd"
i = m.pass_shcp_drvd(b)
assert i == 2 * 100 + 22
def test_rtrn_mptr_drvd2_pass_cptr_bases():
d = m.rtrn_mptr_drvd2()
i1 = m.pass_cptr_base1(d) # load_impl Case 2c
assert i1 == 3 * 110 + 4 * 120 + 21
i2 = m.pass_cptr_base2(d)
assert i2 == 3 * 110 + 4 * 120 + 22
def test_rtrn_mptr_drvd2_up_casts_pass_cptr_drvd2():
b1 = m.rtrn_mptr_drvd2_up_cast1()
assert b1.__class__.__name__ == "drvd2"
i1 = m.pass_cptr_drvd2(b1)
assert i1 == 3 * 110 + 4 * 120 + 23
b2 = m.rtrn_mptr_drvd2_up_cast2()
assert b2.__class__.__name__ == "drvd2"
i2 = m.pass_cptr_drvd2(b2)
assert i2 == 3 * 110 + 4 * 120 + 23
def test_python_drvd2():
class Drvd2(m.base1, m.base2):
def __init__(self):
m.base1.__init__(self)
m.base2.__init__(self)
d = Drvd2()
i1 = m.pass_cptr_base1(d) # load_impl Case 2b
assert i1 == 110 + 21
i2 = m.pass_cptr_base2(d)
assert i2 == 120 + 22