File: test_class_sh_trampoline_basic.py

package info (click to toggle)
pybind11 3.0.1-3
  • 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 (35 lines) | stat: -rw-r--r-- 977 bytes parent folder | download | duplicates (2)
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
32
33
34
35
from __future__ import annotations

from pybind11_tests import class_sh_trampoline_basic as m


class PyDrvd(m.Abase):
    def __init__(self, val):
        super().__init__(val)

    def Add(self, other_val):
        return self.Get() * 100 + other_val


def test_drvd_add():
    drvd = PyDrvd(74)
    assert drvd.Add(38) == (74 * 10 + 3) * 100 + 38


def test_drvd_add_in_cpp_raw_ptr():
    drvd = PyDrvd(52)
    assert m.AddInCppRawPtr(drvd, 27) == ((52 * 10 + 3) * 100 + 27) * 10 + 7


def test_drvd_add_in_cpp_shared_ptr():
    while True:
        drvd = PyDrvd(36)
        assert m.AddInCppSharedPtr(drvd, 56) == ((36 * 10 + 3) * 100 + 56) * 100 + 11
        return  # Comment out for manual leak checking (use `top` command).


def test_drvd_add_in_cpp_unique_ptr():
    while True:
        drvd = PyDrvd(25)
        assert m.AddInCppUniquePtr(drvd, 83) == ((25 * 10 + 3) * 100 + 83) * 100 + 13
        return  # Comment out for manual leak checking (use `top` command).