()
| 115 | |
| 116 | |
| 117 | def 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 | |
| 135 | def test_new_style_pickle_getstate_pos_only(): |
nothing calls this directly
no test coverage detected