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

Function test_with_sp_owner

tests/test_potentially_slicing_weak_ptr.py:102–125  ·  view source on GitHub ↗
(holder_kind, expected_code)

Source from the content-addressed store, hash-verified

100@pytest.mark.parametrize("expected_code", [100, 200])
101@pytest.mark.parametrize("holder_kind", ["SH", "SP"])
102def test_with_sp_owner(holder_kind, expected_code):
103 spo = SP_OWNER_TYPES[holder_kind]()
104 assert spo.get_code() == -888
105 assert spo.get_trampoline_state() == "sp nullptr"
106
107 obj = VIRT_BASE_TYPES[holder_kind][expected_code]()
108 assert obj.get_code() == expected_code
109
110 spo.set_sp(obj)
111 assert spo.get_code() == expected_code
112 expected_trampoline_state = (
113 "dynamic_cast failed" if expected_code == 100 else "trampoline alive"
114 )
115 assert spo.get_trampoline_state() == expected_trampoline_state
116
117 del obj
118 gc.collect()
119 if holder_kind == "SH":
120 assert spo.get_code() == expected_code
121 elif GC_IS_RELIABLE:
122 assert (
123 spo.get_code() == 100
124 ) # see issue #1333 (inheritance slicing) and PR #5624
125 assert spo.get_trampoline_state() == expected_trampoline_state
126
127
128@pytest.mark.parametrize("expected_code", [100, 200])

Callers

nothing calls this directly

Calls 3

set_spMethod · 0.80
get_codeMethod · 0.45
get_trampoline_stateMethod · 0.45

Tested by

no test coverage detected