test_pickle.py 936 B

1234567891011121314151617181920212223242526272829303132333435
  1. from direct.stdpy.pickle import dumps, loads, PicklingError
  2. import pytest
  3. def test_reduce_persist():
  4. from panda3d.core import NodePath
  5. parent = NodePath("parent")
  6. child = parent.attach_new_node("child")
  7. parent2, child2 = loads(dumps([parent, child]))
  8. assert tuple(parent2.children) == (child2,)
  9. def test_pickle_copy():
  10. from panda3d.core import PandaNode, NodePath
  11. # Make two Python wrappers pointing to the same node
  12. node1 = PandaNode("node")
  13. node2 = NodePath(node1).node()
  14. assert node1.this == node2.this
  15. assert id(node1) != id(node2)
  16. # Test that pickling and loading still results in the same node object.
  17. node1, node2 = loads(dumps([node1, node2]))
  18. assert node1 == node2
  19. def test_pickle_error():
  20. class ErroneousPickleable(object):
  21. def __reduce__(self):
  22. return 12345
  23. with pytest.raises(PicklingError):
  24. dumps(ErroneousPickleable())