2024-06-22 06:00:13 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2024-07-31 13:17:31 +00:00
|
|
|
import pytest
|
|
|
|
|
2021-04-09 05:56:46 +00:00
|
|
|
import pybind11_tests.class_sh_trampoline_unique_ptr as m
|
|
|
|
|
2024-08-04 16:16:44 +00:00
|
|
|
if not m.defined_PYBIND11_HAS_INTERNALS_WITH_SMART_HOLDER_SUPPORT:
|
2024-07-31 13:17:31 +00:00
|
|
|
pytest.skip("smart_holder not available.", allow_module_level=True)
|
|
|
|
|
2021-04-09 05:56:46 +00:00
|
|
|
|
|
|
|
class MyClass(m.Class):
|
|
|
|
def foo(self):
|
2021-04-10 06:08:44 +00:00
|
|
|
return 10 + self.get_val()
|
2021-04-09 05:56:46 +00:00
|
|
|
|
|
|
|
def clone(self):
|
2021-04-10 06:08:44 +00:00
|
|
|
cloned = MyClass()
|
|
|
|
cloned.set_val(self.get_val() + 3)
|
|
|
|
return cloned
|
2021-04-09 05:56:46 +00:00
|
|
|
|
|
|
|
|
2021-04-10 06:08:44 +00:00
|
|
|
def test_m_clone():
|
2021-04-09 05:56:46 +00:00
|
|
|
obj = MyClass()
|
2021-04-10 06:08:44 +00:00
|
|
|
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).
|