Merge branch 'master' into blender2.8
[blender.git] / tests / python / render_layer / test_scene_copy_f.py
1 # ############################################################
2 # Importing - Same For All Render Layer Tests
3 # ############################################################
4
5 import unittest
6 import os
7 import sys
8
9 from render_layer_common import *
10
11
12 # ############################################################
13 # Testing
14 # ############################################################
15
16 class UnitTesting(RenderLayerTesting):
17     def test_shared_layer_collections_copy_full(self):
18         """
19         See if scene copying 'FULL_COPY' is keeping collections visibility
20         and selectability.
21         """
22         import os
23         import bpy
24
25         scene = bpy.context.scene
26
27         hide_lookup = [0, 1, 1, 0]
28         hide_lookup_sub = [1, 0, 1]
29
30         hide_select_lookup = [0, 0, 1, 1]
31         hide_select_lookup_sub = [1, 0, 1, 0]
32         new_collections = []
33
34         # clean everything
35         for layer in scene.render_layers:
36             while layer.collections:
37                 layer.collections.unlink(layer.collections[0])
38
39         # create new collections
40         for i in range(4):
41             collection = scene.master_collection.collections.new(str(i))
42             new_collections.append(collection)
43
44             for j in range(3):
45                 sub_collection = collection.collections.new("{0}:{1}".format(i, j))
46
47         # link to the original scene
48         for layer in scene.render_layers:
49             for i, collection in enumerate(new_collections):
50                 layer.collections.link(collection)
51                 self.assertEqual(layer.collections[-1], layer.collections[i])
52
53                 layer.collections[i].hide = hide_lookup[i]
54                 layer.collections[i].hide_select = hide_select_lookup[i]
55
56                 for j, sub_collection in enumerate(layer.collections[i].collections):
57                     sub_collection.hide = hide_lookup_sub[j]
58                     sub_collection.hide_select = hide_select_lookup_sub[j]
59
60         # copy scene
61         bpy.ops.scene.new(type='FULL_COPY')
62         new_scene = bpy.context.scene
63         self.assertNotEqual(scene, new_scene)
64
65         # update depsgrah
66         scene.update()  # update depsgraph
67
68         # compare scenes
69         for h, layer in enumerate(scene.render_layers):
70             new_layer = new_scene.render_layers[h]
71
72             for i, collection in enumerate(layer.collections):
73                 new_collection = new_layer.collections[i]
74                 self.assertEqual(collection.hide, new_collection.hide)
75                 self.assertEqual(collection.hide_select, new_collection.hide_select)
76
77                 for j, sub_collection in enumerate(layer.collections[i].collections):
78                     new_sub_collection = new_collection.collections[j]
79                     self.assertEqual(sub_collection.hide, new_sub_collection.hide)
80                     self.assertEqual(sub_collection.hide_select, new_sub_collection.hide_select)
81
82
83 # ############################################################
84 # Main - Same For All Render Layer Tests
85 # ############################################################
86
87 if __name__ == '__main__':
88     import sys
89
90     extra_arguments = sys.argv[sys.argv.index("--") + 1:] if "--" in sys.argv else []
91     sys.argv = [__file__] + (sys.argv[sys.argv.index("--") + 2:] if "--" in sys.argv else [])
92
93     UnitTesting._extra_arguments = extra_arguments
94     unittest.main()