test_background_set.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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_background_set(self):
  13. """
  14. See if background sets are properly added and removed
  15. """
  16. import bpy
  17. background_scene = bpy.data.scenes[0]
  18. main_scene = bpy.data.scenes.new('main')
  19. bpy.context.window.scene = main_scene
  20. # Update depsgraph.
  21. bpy.context.view_layer.update()
  22. # Safety check, there should be no objects in thew newly created scene.
  23. self.assertEqual(0, len(bpy.context.depsgraph.objects))
  24. # Now set the background set, and objects relationship.
  25. main_scene.background_set = background_scene
  26. background_scene.objects[0].parent = background_scene.objects[1]
  27. # Update depsgraph.
  28. bpy.context.view_layer.update()
  29. # Test if objects were properly added to depsgraph.
  30. self.assertEqual(3, len(bpy.context.depsgraph.objects))
  31. # We now check if the objects are properly flagged as from set
  32. # These objects can't be possible nor show their origins or
  33. # relationship lines
  34. for ob in bpy.context.depsgraph.objects:
  35. self.assertTrue(ob.is_from_set)
  36. # Test if removing is working fine.
  37. main_scene.background_set = None
  38. # Update depsgraph.
  39. bpy.context.view_layer.update()
  40. self.assertEqual(0, len(bpy.context.depsgraph.objects))
  41. # ############################################################
  42. # Main - Same For All Render Layer Tests
  43. # ############################################################
  44. if __name__ == '__main__':
  45. UnitTesting._extra_arguments = setup_extra_arguments(__file__)
  46. unittest.main()