File: test_class_sh_trampoline_self_life_support.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 (38 lines) | stat: -rw-r--r-- 872 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
32
33
34
35
36
37
38
from __future__ import annotations

import pytest

import pybind11_tests.class_sh_trampoline_self_life_support as m


class PyBig5(m.Big5):
    pass


def test_m_big5():
    obj = m.Big5("Seed")
    assert obj.history == "Seed"
    o1, o2 = m.action(obj, 0)
    assert o1 is not obj
    assert o1.history == "Seed"
    with pytest.raises(ValueError) as excinfo:
        _ = obj.history
    assert "Python instance was disowned" in str(excinfo.value)
    assert o2 is None


@pytest.mark.parametrize(
    ("action_id", "expected_history"),
    [
        (0, "Seed_CpCtor"),
        (1, "Seed_MvCtor"),
        (2, "Seed_OpEqLv"),
        (3, "Seed_OpEqRv"),
    ],
)
def test_py_big5(action_id, expected_history):
    obj = PyBig5("Seed")
    assert obj.history == "Seed"
    o1, o2 = m.action(obj, action_id)
    assert o1 is obj
    assert o2.history == expected_history