pybind11/tests/test_class_sh_trampoline_unique_ptr.py
Ralf W. Grosse-Kunstleve 6c922614ed
Adding reclaim_disowned logic & miscellaneous naming and documentation improvements. (#2943)
* Using new smart_holder::reclaim_disowned in smart_holder_type_caster for unique_ptr.

* Systematically renaming was_disowned to is_disowned (because disowning is now reversible: reclaim_disowned).

* Systematically renaming virtual_overrider_self_life_support to trampoline_self_life_support (to reuse existing terminology instead of introducing new one).

* Systematically renaming test_class_sh_with_alias to test_class_sh_trampoline_basic.

* Adding a Trampolines and std::unique_ptr section to README_smart_holder.rst.

* MSVC compatibility.
2021-04-09 23:08:44 -07:00

32 lines
749 B
Python

# -*- coding: utf-8 -*-
import pybind11_tests.class_sh_trampoline_unique_ptr as m
class MyClass(m.Class):
def foo(self):
return 10 + self.get_val()
def clone(self):
cloned = MyClass()
cloned.set_val(self.get_val() + 3)
return cloned
def test_m_clone():
obj = MyClass()
while True:
obj.set_val(5)
obj = m.clone(obj)
assert obj.get_val() == 5 + 3
assert obj.foo() == 10 + 5 + 3
return # Comment out for manual leak checking (use `top` command).
def test_m_clone_and_foo():
obj = MyClass()
obj.set_val(7)
while True:
assert m.clone_and_foo(obj) == 10 + 7 + 3
return # Comment out for manual leak checking (use `top` command).