File: test_class_sh_trampoline_unique_ptr.py

package info (click to toggle)
pybind11 3.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,448 kB
  • sloc: cpp: 27,239; python: 13,512; ansic: 4,244; makefile: 204; sh: 36
file content (31 lines) | stat: -rw-r--r-- 760 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from __future__ import annotations

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).