test_pickle.py 517 B

123456789101112131415161718192021
  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_error():
  10. class ErroneousPickleable(object):
  11. def __reduce__(self):
  12. return 12345
  13. with pytest.raises(PicklingError):
  14. dumps(ErroneousPickleable())