7from pybind11_tests
import pickling
as m
11 assert m.simple_callable() == 20220426
13 serialized = pickle.dumps(m.simple_callable)
14 deserialized = pickle.loads(serialized)
15 assert deserialized() == 20220426
19 with pytest.raises(TypeError)
as excinfo:
20 pickle.dumps(m.simple_callable)
21 assert re.search(
"can.*t pickle .*PyCapsule.* object",
str(excinfo.value))
24@pytest.mark.parametrize("cls_name", ["Pickleable", "PickleableNew"])
31 data = pickle.dumps(p, 2)
32 p2 = pickle.loads(data)
33 assert p2.value() == p.value()
34 assert p2.extra1() == p.extra1()
35 assert p2.extra2() == p.extra2()
38@pytest.mark.xfail("env.PYPY")
39@pytest.mark.parametrize("cls_name", ["PickleableWithDict", "PickleableWithDictNew"])
44 p.dynamic =
"Attribute"
46 data = pickle.dumps(p, pickle.HIGHEST_PROTOCOL)
47 p2 = pickle.loads(data)
48 assert p2.value == p.value
49 assert p2.extra == p.extra
50 assert p2.dynamic == p.dynamic
54 from pybind11_tests
import enums
as e
56 data = pickle.dumps(e.EOne, 2)
57 assert e.EOne == pickle.loads(data)
70 p.stored_in_dict = 303
71 data = pickle.dumps(p, pickle.HIGHEST_PROTOCOL)
72 p2 = pickle.loads(data)
75 assert p2.stored_in_dict == 303
79 p = m.make_SimpleCppDerivedAsBase()
80 assert m.check_dynamic_cast_SimpleCppDerived(p)
84 with pytest.raises(AttributeError):
87 data = pickle.dumps(p, pickle.HIGHEST_PROTOCOL)
88 p2 = pickle.loads(data)
93 assert not m.check_dynamic_cast_SimpleCppDerived(p2)
object getattr(handle obj, handle name)
void setattr(handle obj, handle name, handle value)
bool isinstance(handle obj)
\rst Return true if obj is an instance of T.
def test_roundtrip_simple_cpp_derived()
def test_roundtrip_with_dict(cls_name)
def test_roundtrip(cls_name)
def test_pickle_simple_callable()
def test_roundtrip_simple_py_derived()