test_active_collection.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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_active_collection(self):
  13. """
  14. See if active collection index is working
  15. layer.collections.active_index works recursively
  16. """
  17. import bpy
  18. import os
  19. ROOT = self.get_root()
  20. filepath_layers = os.path.join(ROOT, 'layers.blend')
  21. # open file
  22. bpy.ops.wm.open_mainfile('EXEC_DEFAULT', filepath=filepath_layers)
  23. self.rename_collections()
  24. # create sub-collections
  25. three_b = bpy.data.objects.get('T.3b')
  26. three_c = bpy.data.objects.get('T.3c')
  27. scene = bpy.context.scene
  28. subzero = scene.master_collection.collections['1'].collections.new('sub-zero')
  29. scorpion = subzero.collections.new('scorpion')
  30. subzero.objects.link(three_b)
  31. scorpion.objects.link(three_c)
  32. layer = scene.view_layers.new('Fresh new Layer')
  33. layer.collections.link(subzero)
  34. lookup = [
  35. 'Master Collection',
  36. '1',
  37. 'sub-zero',
  38. 'scorpion',
  39. '2',
  40. '3',
  41. '4',
  42. '5',
  43. 'sub-zero',
  44. 'scorpion']
  45. for i, name in enumerate(lookup):
  46. layer.collections.active_index = i
  47. self.assertEqual(
  48. name, layer.collections.active.name,
  49. "Collection index mismatch: [{0}] : {1} != {2}".format(
  50. i, name, layer.collections.active.name))
  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()