mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-13 17:13:53 +00:00
9d4b4dffce
* Reproducer for https://github.com/pybind/pybind11/issues/3788 Expected to build & run as-is. Uncommenting reproduces the infinite recursion. * Moving try_as_void_ptr_capsule() to the end of load_impl() * Moving new test into the existing test_class_sh_void_ptr_capsule * Experiment * Remove comments and simplify the test cases. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci Co-authored-by: Ralf W. Grosse-Kunstleve <rwgk@google.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
40 lines
1.3 KiB
Python
40 lines
1.3 KiB
Python
import pytest
|
|
|
|
from pybind11_tests import class_sh_void_ptr_capsule as m
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"ctor, caller, expected, capsule_generated",
|
|
[
|
|
(m.Valid, m.get_from_valid_capsule, 101, False),
|
|
(m.NoConversion, m.get_from_no_conversion_capsule, 102, False),
|
|
(m.NoCapsuleReturned, m.get_from_no_capsule_returned, 103, False),
|
|
(m.AsAnotherObject, m.get_from_valid_capsule, 104, True),
|
|
],
|
|
)
|
|
def test_as_void_ptr_capsule(ctor, caller, expected, capsule_generated):
|
|
obj = ctor()
|
|
assert caller(obj) == expected
|
|
assert obj.capsule_generated == capsule_generated
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"ctor, caller, pointer_type, capsule_generated",
|
|
[
|
|
(m.AsAnotherObject, m.get_from_shared_ptr_valid_capsule, "shared_ptr", True),
|
|
(m.AsAnotherObject, m.get_from_unique_ptr_valid_capsule, "unique_ptr", True),
|
|
],
|
|
)
|
|
def test_as_void_ptr_capsule_unsupported(ctor, caller, pointer_type, capsule_generated):
|
|
obj = ctor()
|
|
with pytest.raises(RuntimeError) as excinfo:
|
|
caller(obj)
|
|
assert pointer_type in str(excinfo.value)
|
|
assert obj.capsule_generated == capsule_generated
|
|
|
|
|
|
def test_type_with_getattr():
|
|
obj = m.TypeWithGetattr()
|
|
assert obj.get_42() == 42
|
|
assert obj.something == "GetAttr: something"
|