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

Function test_roundtrip_simple_cpp_derived

tests/test_pickling.py:117–132  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

115
116
117def test_roundtrip_simple_cpp_derived():
118 p = m.make_SimpleCppDerivedAsBase()
119 assert m.check_dynamic_cast_SimpleCppDerived(p)
120 p.num = 404
121 if not env.PYPY:
122 # To ensure that this unit test is not accidentally invalidated.
123 with pytest.raises(AttributeError):
124 # Mimics the `setstate` C++ implementation.
125 setattr(p, "__dict__", {}) # noqa: B010
126 data = pickle.dumps(p, pickle.HIGHEST_PROTOCOL)
127 p2 = pickle.loads(data)
128 assert isinstance(p2, m.SimpleBase)
129 assert p2.num == 404
130 # Issue #3062: pickleable base C++ classes can incur object slicing
131 # if derived typeid is not registered with pybind11
132 assert not m.check_dynamic_cast_SimpleCppDerived(p2)
133
134
135def test_new_style_pickle_getstate_pos_only():

Callers

nothing calls this directly

Calls 2

setattrFunction · 0.85
isinstanceFunction · 0.85

Tested by

no test coverage detected