test_unique_ptr_member.py 836 Bytes
Newer Older
1
2
3
4
5
6
# -*- coding: utf-8 -*-
import pytest

from pybind11_tests import unique_ptr_member as m


7
8
9
def test_make_unique_pointee():
    obj = m.make_unique_pointee()
    assert obj.get_int() == 213
10
11


12
13
14
15
16
@pytest.mark.parametrize(
    "give_up_ownership_via",
    ["give_up_ownership_via_unique_ptr", "give_up_ownership_via_shared_ptr"],
)
def test_pointee_and_ptr_owner(give_up_ownership_via):
17
18
    obj = m.pointee()
    assert obj.get_int() == 213
19
20
    owner = m.ptr_owner(obj)
    with pytest.raises(RuntimeError) as exc_info:
21
        obj.get_int()
22
23
24
25
    assert (
        str(exc_info.value)
        == "Missing value for wrapped C++ type: Python instance is uninitialized or was disowned."
    )
26
    assert owner.is_owner()
27
    reclaimed = getattr(owner, give_up_ownership_via)()
28
    assert not owner.is_owner()
29
    assert reclaimed.get_int() == 213