test_pythontask.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. from panda3d.core import PythonTask
  2. import pytest
  3. import types
  4. import sys
  5. def test_pythontask_property_builtin():
  6. task = PythonTask()
  7. # Read-write property
  8. assert task.name == ""
  9. task.name = "ABC"
  10. # Read-only property
  11. assert task.dt == 0.0
  12. with pytest.raises(AttributeError):
  13. task.dt = 1.0
  14. assert task.dt == 0.0
  15. # Non-existent property
  16. with pytest.raises(AttributeError):
  17. task.abc
  18. def test_pythontask_property_custom():
  19. task = PythonTask()
  20. assert not hasattr(task, 'custom_field')
  21. task.custom_field = 1.0
  22. assert hasattr(task, 'custom_field')
  23. assert task.custom_field == 1.0
  24. task.custom_field = 2.0
  25. assert task.custom_field == 2.0
  26. del task.custom_field
  27. assert not hasattr(task, 'custom_field')
  28. def test_pythontask_property_override():
  29. task = PythonTask()
  30. assert isinstance(task.gather, types.BuiltinMethodType)
  31. task.gather = 123
  32. assert task.gather == 123
  33. del task.gather
  34. assert isinstance(task.gather, types.BuiltinMethodType)
  35. def test_pythontask_dict_get():
  36. task = PythonTask()
  37. d = task.__dict__
  38. rc1 = sys.getrefcount(d)
  39. task.__dict__
  40. task.__dict__
  41. rc2 = sys.getrefcount(d)
  42. assert rc1 == rc2
  43. def test_pythontask_dict_set():
  44. task = PythonTask()
  45. d = {}
  46. rc1 = sys.getrefcount(d)
  47. task.__dict__ = d
  48. rc2 = sys.getrefcount(d)
  49. assert rc1 + 1 == rc2
  50. task.__dict__ = {}
  51. rc2 = sys.getrefcount(d)
  52. assert rc1 == rc2