pybind11/tests/test_class_sh_factory_constructors.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

54 lines
1.4 KiB
Python

from __future__ import annotations
import pytest
from pybind11_tests import class_sh_factory_constructors as m
def test_atyp_factories():
assert m.atyp_valu().get_mtxt() == "Valu"
assert m.atyp_rref().get_mtxt() == "Rref"
# sert m.atyp_cref().get_mtxt() == "Cref"
# sert m.atyp_mref().get_mtxt() == "Mref"
# sert m.atyp_cptr().get_mtxt() == "Cptr"
assert m.atyp_mptr().get_mtxt() == "Mptr"
assert m.atyp_shmp().get_mtxt() == "Shmp"
# sert m.atyp_shcp().get_mtxt() == "Shcp"
assert m.atyp_uqmp().get_mtxt() == "Uqmp"
# sert m.atyp_uqcp().get_mtxt() == "Uqcp"
assert m.atyp_udmp().get_mtxt() == "Udmp"
# sert m.atyp_udcp().get_mtxt() == "Udcp"
@pytest.mark.parametrize(
("init_args", "expected"),
[
((3,), 300),
((5, 7), 570),
((9, 11, 13), 1023),
],
)
def test_with_alias_success(init_args, expected):
assert m.with_alias(*init_args).val == expected
@pytest.mark.parametrize(
("num_init_args", "smart_ptr"),
[
(4, "std::unique_ptr"),
(5, "std::shared_ptr"),
],
)
def test_with_alias_invalid(num_init_args, smart_ptr):
class PyDrvdWithAlias(m.with_alias):
pass
with pytest.raises(TypeError) as excinfo:
PyDrvdWithAlias(*((0,) * num_init_args))
assert (
str(excinfo.value)
== "pybind11::init(): construction failed: returned "
+ smart_ptr
+ " pointee is not an alias instance"
)