6 from pybind11_tests
import call_policies
as m
7 from pybind11_tests
import ConstructorStats
10 @pytest.mark.xfail(
"env.PYPY", reason=
"sometimes comes out 1 off on PyPy", strict=
False)
12 n_inst = ConstructorStats.detail_reg_inst()
15 assert capture ==
"Allocating parent." 18 assert ConstructorStats.detail_reg_inst() == n_inst + 1
25 assert ConstructorStats.detail_reg_inst() == n_inst
26 assert capture ==
"Releasing parent." 30 assert capture ==
"Allocating parent." 32 p.addChildKeepAlive(m.Child())
33 assert ConstructorStats.detail_reg_inst() == n_inst + 2
34 assert capture ==
"Allocating child." 37 assert ConstructorStats.detail_reg_inst() == n_inst
45 n_inst = ConstructorStats.detail_reg_inst()
48 assert capture ==
"Allocating parent." 51 assert ConstructorStats.detail_reg_inst() == n_inst + 1
58 assert ConstructorStats.detail_reg_inst() == n_inst
59 assert capture ==
"Releasing parent." 63 assert capture ==
"Allocating parent." 65 p.returnChildKeepAlive()
66 assert ConstructorStats.detail_reg_inst() == n_inst + 2
67 assert capture ==
"Allocating child." 70 assert ConstructorStats.detail_reg_inst() == n_inst
78 @pytest.mark.xfail(
"env.PYPY", reason=
"_PyObject_GetDictPtr is unimplemented")
80 n_inst = ConstructorStats.detail_reg_inst()
82 p.addChildKeepAlive(m.Child())
83 assert ConstructorStats.detail_reg_inst() == n_inst + 2
88 assert ConstructorStats.detail_reg_inst() == n_inst
96 class Derived(m.Parent):
99 n_inst = ConstructorStats.detail_reg_inst()
101 p.addChildKeepAlive(m.Child())
102 assert ConstructorStats.detail_reg_inst() == n_inst + 2
107 assert ConstructorStats.detail_reg_inst() == n_inst
108 assert capture ==
""" 115 class Derived(m.Parent, m.Child):
117 m.Parent.__init__(self)
118 m.Child.__init__(self)
120 n_inst = ConstructorStats.detail_reg_inst()
122 p.addChildKeepAlive(m.Child())
124 assert ConstructorStats.detail_reg_inst() == n_inst + 3
129 assert ConstructorStats.detail_reg_inst() == n_inst
130 assert capture ==
""" 138 n_inst = ConstructorStats.detail_reg_inst()
141 assert capture ==
"Allocating parent." 143 p.returnNullChildKeepAliveChild()
144 assert ConstructorStats.detail_reg_inst() == n_inst + 1
148 assert ConstructorStats.detail_reg_inst() == n_inst
149 assert capture ==
"Releasing parent." 153 assert capture ==
"Allocating parent." 155 p.returnNullChildKeepAliveParent()
156 assert ConstructorStats.detail_reg_inst() == n_inst + 1
160 assert ConstructorStats.detail_reg_inst() == n_inst
161 assert capture ==
"Releasing parent." 165 n_inst = ConstructorStats.detail_reg_inst()
168 p = m.Parent(m.Child())
169 assert ConstructorStats.detail_reg_inst() == n_inst + 2
170 assert capture ==
""" 176 assert ConstructorStats.detail_reg_inst() == n_inst
177 assert capture ==
""" 184 assert m.unguarded_call() ==
"unguarded" 185 assert m.guarded_call() ==
"guarded" 187 assert m.multiple_guards_correct_order() ==
"guarded & guarded" 188 assert m.multiple_guards_wrong_order() ==
"unguarded & guarded" 191 assert m.with_gil() ==
"GIL held" 192 assert m.without_gil() ==
"GIL released" bool hasattr(handle obj, handle name)
def test_keep_alive_constructor(capture)
def test_alive_gc_multi_derived(capture)
def test_keep_alive_return_value(capture)
def test_return_none(capture)
def test_alive_gc(capture)
def test_keep_alive_argument(capture)
def test_alive_gc_derived(capture)