MCPcopy Create free account
hub / github.com/pybind/pybind11 / test_shared_ptr_and_references

Function test_shared_ptr_and_references

tests/test_smart_ptr.py:176–204  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

174
175@pytest.mark.skipif("env.GRAALPY", reason="Cannot reliably trigger GC")
176def test_shared_ptr_and_references():
177 s = m.SharedPtrRef()
178 stats = ConstructorStats.get(m.A)
179 assert stats.alive() == 2
180
181 ref = s.ref # init_holder_helper(holder_ptr=false, owned=false)
182 assert stats.alive() == 2
183 assert s.set_ref(ref)
184 with pytest.raises(RuntimeError) as excinfo:
185 assert s.set_holder(ref)
186 assert "Unable to cast from non-held to held instance" in str(excinfo.value)
187
188 copy = s.copy # init_holder_helper(holder_ptr=false, owned=true)
189 assert stats.alive() == 3
190 assert s.set_ref(copy)
191 assert s.set_holder(copy)
192
193 holder_ref = s.holder_ref # init_holder_helper(holder_ptr=true, owned=false)
194 assert stats.alive() == 3
195 assert s.set_ref(holder_ref)
196 assert s.set_holder(holder_ref)
197
198 holder_copy = s.holder_copy # init_holder_helper(holder_ptr=true, owned=true)
199 assert stats.alive() == 3
200 assert s.set_ref(holder_copy)
201 assert s.set_holder(holder_copy)
202
203 del ref, copy, holder_ref, holder_copy, s
204 assert stats.alive() == 0
205
206
207@pytest.mark.skipif("env.GRAALPY", reason="Cannot reliably trigger GC")

Callers

nothing calls this directly

Calls 3

strClass · 0.85
aliveMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected