test_group_d.py 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. # ############################################################
  2. # Importing - Same For All Render Layer Tests
  3. # ############################################################
  4. import unittest
  5. import os
  6. import sys
  7. from view_layer_common import *
  8. # ############################################################
  9. # Testing
  10. # ############################################################
  11. class UnitTesting(ViewLayerTesting):
  12. def test_group_write_load(self):
  13. """
  14. See if saving/loading is working for groups
  15. """
  16. import bpy
  17. scene = bpy.context.scene
  18. layer_collection = bpy.context.layer_collection
  19. while len(scene.view_layers) > 1:
  20. scene.view_layers.remove(scene.view_layers[1])
  21. # create group
  22. group = layer_collection.create_group()
  23. self.assertEqual(1, len(bpy.data.groups))
  24. self.assertEqual(1, bpy.data.groups[0].users)
  25. self.assertEqual(3, len(bpy.data.groups[0].objects))
  26. import os
  27. import tempfile
  28. with tempfile.TemporaryDirectory() as dirpath:
  29. filepath = os.path.join(dirpath, 'layers.blend')
  30. for i in range(3):
  31. # save and re-open file
  32. bpy.ops.wm.save_mainfile('EXEC_DEFAULT', filepath=filepath)
  33. bpy.ops.wm.open_mainfile('EXEC_DEFAULT', filepath=filepath)
  34. self.assertEqual(1, len(bpy.data.groups))
  35. self.assertEqual(1, bpy.data.groups[0].users)
  36. self.assertEqual(3, len(bpy.data.groups[0].objects))
  37. # empty the group of objects
  38. group = bpy.data.groups[0]
  39. while group.objects:
  40. group.view_layer.collections[0].collection.objects.unlink(group.objects[0])
  41. # save and re-open file
  42. bpy.ops.wm.save_mainfile('EXEC_DEFAULT', filepath=filepath)
  43. bpy.ops.wm.open_mainfile('EXEC_DEFAULT', filepath=filepath)
  44. self.assertEqual(1, len(bpy.data.groups))
  45. self.assertEqual(0, bpy.data.groups[0].users)
  46. self.assertEqual(0, len(bpy.data.groups[0].objects))
  47. # save and re-open file
  48. bpy.ops.wm.save_mainfile('EXEC_DEFAULT', filepath=filepath)
  49. bpy.ops.wm.open_mainfile('EXEC_DEFAULT', filepath=filepath)
  50. self.assertEqual(0, len(bpy.data.groups))
  51. # ############################################################
  52. # Main - Same For All Render Layer Tests
  53. # ############################################################
  54. if __name__ == '__main__':
  55. UnitTesting._extra_arguments = setup_extra_arguments(__file__)
  56. unittest.main()