4 from pybind11_tests
import ConstructorStats
5 from pybind11_tests
import call_policies
as m
8 @pytest.mark.xfail(
"env.PYPY", reason=
"sometimes comes out 1 off on PyPy", strict=
False)
10 n_inst = ConstructorStats.detail_reg_inst()
13 assert capture ==
"Allocating parent." 16 assert ConstructorStats.detail_reg_inst() == n_inst + 1
26 assert ConstructorStats.detail_reg_inst() == n_inst
27 assert capture ==
"Releasing parent." 31 assert capture ==
"Allocating parent." 33 p.addChildKeepAlive(m.Child())
34 assert ConstructorStats.detail_reg_inst() == n_inst + 2
35 assert capture ==
"Allocating child." 38 assert ConstructorStats.detail_reg_inst() == n_inst
49 assert ConstructorStats.detail_reg_inst() == n_inst + 2
52 assert ConstructorStats.detail_reg_inst() == n_inst + 2
54 assert ConstructorStats.detail_reg_inst() == n_inst
56 with pytest.raises(RuntimeError)
as excinfo:
58 assert str(excinfo.value) ==
"Could not activate keep_alive!" 62 n_inst = ConstructorStats.detail_reg_inst()
65 assert capture ==
"Allocating parent." 68 assert ConstructorStats.detail_reg_inst() == n_inst + 1
78 assert ConstructorStats.detail_reg_inst() == n_inst
79 assert capture ==
"Releasing parent." 83 assert capture ==
"Allocating parent." 85 p.returnChildKeepAlive()
86 assert ConstructorStats.detail_reg_inst() == n_inst + 2
87 assert capture ==
"Allocating child." 90 assert ConstructorStats.detail_reg_inst() == n_inst
100 assert ConstructorStats.detail_reg_inst() == n_inst + 1
102 m.Parent.staticFunction(p)
103 assert ConstructorStats.detail_reg_inst() == n_inst + 2
104 assert capture ==
"Allocating child." 107 assert ConstructorStats.detail_reg_inst() == n_inst
118 @pytest.mark.xfail(
"env.PYPY", reason=
"_PyObject_GetDictPtr is unimplemented")
120 n_inst = ConstructorStats.detail_reg_inst()
122 p.addChildKeepAlive(m.Child())
123 assert ConstructorStats.detail_reg_inst() == n_inst + 2
128 assert ConstructorStats.detail_reg_inst() == n_inst
139 class Derived(m.Parent):
142 n_inst = ConstructorStats.detail_reg_inst()
144 p.addChildKeepAlive(m.Child())
145 assert ConstructorStats.detail_reg_inst() == n_inst + 2
150 assert ConstructorStats.detail_reg_inst() == n_inst
161 class Derived(m.Parent, m.Child):
163 m.Parent.__init__(self)
164 m.Child.__init__(self)
166 n_inst = ConstructorStats.detail_reg_inst()
168 p.addChildKeepAlive(m.Child())
170 assert ConstructorStats.detail_reg_inst() == n_inst + 3
175 assert ConstructorStats.detail_reg_inst() == n_inst
187 n_inst = ConstructorStats.detail_reg_inst()
190 assert capture ==
"Allocating parent." 192 p.returnNullChildKeepAliveChild()
193 assert ConstructorStats.detail_reg_inst() == n_inst + 1
197 assert ConstructorStats.detail_reg_inst() == n_inst
198 assert capture ==
"Releasing parent." 202 assert capture ==
"Allocating parent." 204 p.returnNullChildKeepAliveParent()
205 assert ConstructorStats.detail_reg_inst() == n_inst + 1
209 assert ConstructorStats.detail_reg_inst() == n_inst
210 assert capture ==
"Releasing parent." 214 n_inst = ConstructorStats.detail_reg_inst()
217 p = m.Parent(m.Child())
218 assert ConstructorStats.detail_reg_inst() == n_inst + 2
228 assert ConstructorStats.detail_reg_inst() == n_inst
239 assert m.unguarded_call() ==
"unguarded" 240 assert m.guarded_call() ==
"guarded" 242 assert m.multiple_guards_correct_order() ==
"guarded & guarded" 243 assert m.multiple_guards_wrong_order() ==
"unguarded & guarded" 246 assert m.with_gil() ==
"GIL held" 247 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)