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

Function test_with_wp_owner

tests/test_potentially_slicing_weak_ptr.py:131–159  ·  view source on GitHub ↗
(holder_kind, set_meth, expected_code)

Source from the content-addressed store, hash-verified

129@pytest.mark.parametrize("set_meth", ["set_wp", "set_wp_potentially_slicing"])
130@pytest.mark.parametrize("holder_kind", ["SH", "SP"])
131def test_with_wp_owner(holder_kind, set_meth, expected_code):
132 wpo = WP_OWNER_TYPES[holder_kind]()
133 assert wpo.get_code() == -999
134 assert wpo.get_trampoline_state() == "sp nullptr"
135
136 obj = VIRT_BASE_TYPES[holder_kind][expected_code]()
137 assert obj.get_code() == expected_code
138
139 getattr(wpo, set_meth)(obj)
140 if (
141 holder_kind == "SP"
142 or expected_code == 100
143 or set_meth == "set_wp_potentially_slicing"
144 ):
145 assert wpo.get_code() == expected_code
146 else:
147 assert wpo.get_code() == -999 # see issue #5623 (weak_ptr expired) and PR #5624
148 if expected_code == 100:
149 expected_trampoline_state = "dynamic_cast failed"
150 elif holder_kind == "SH" and set_meth == "set_wp":
151 expected_trampoline_state = "sp nullptr"
152 else:
153 expected_trampoline_state = "trampoline alive"
154 assert wpo.get_trampoline_state() == expected_trampoline_state
155
156 del obj
157 gc.collect()
158 if GC_IS_RELIABLE:
159 assert wpo.get_code() == -999
160
161
162def test_potentially_slicing_weak_ptr_not_convertible_error():

Callers

nothing calls this directly

Calls 3

getattrFunction · 0.85
get_codeMethod · 0.45
get_trampoline_stateMethod · 0.45

Tested by

no test coverage detected