mirror of
https://github.com/pybind/pybind11.git
synced 2026-04-20 14:59:27 +00:00
Add dynamic attribute support
This commit is contained in:
@@ -3,10 +3,10 @@ try:
|
||||
except ImportError:
|
||||
import pickle
|
||||
|
||||
from pybind11_tests import Pickleable
|
||||
|
||||
|
||||
def test_roundtrip():
|
||||
from pybind11_tests import Pickleable
|
||||
|
||||
p = Pickleable("test_value")
|
||||
p.setExtra1(15)
|
||||
p.setExtra2(48)
|
||||
@@ -16,3 +16,17 @@ def test_roundtrip():
|
||||
assert p2.value() == p.value()
|
||||
assert p2.extra1() == p.extra1()
|
||||
assert p2.extra2() == p.extra2()
|
||||
|
||||
|
||||
def test_roundtrip_with_dict():
|
||||
from pybind11_tests import PickleableWithDict
|
||||
|
||||
p = PickleableWithDict("test_value")
|
||||
p.extra = 15
|
||||
p.dynamic = "Attribute"
|
||||
|
||||
data = pickle.dumps(p, pickle.HIGHEST_PROTOCOL)
|
||||
p2 = pickle.loads(data)
|
||||
assert p2.value == p.value
|
||||
assert p2.extra == p.extra
|
||||
assert p2.dynamic == p.dynamic
|
||||
|
||||
Reference in New Issue
Block a user