Layers: Fix scene copying after IDProperty changes
(also unittest: split scene copy in 4 tests)
This commit is contained in:
@@ -330,6 +330,9 @@ Scene *BKE_scene_copy(Main *bmain, Scene *sce, int type)
|
||||
}
|
||||
new_sl = new_sl->next;
|
||||
}
|
||||
|
||||
IDPropertyTemplate val = {0};
|
||||
scen->collection_properties = IDP_New(IDP_GROUP, &val, ROOT_PROP);
|
||||
}
|
||||
|
||||
/* copy color management settings */
|
||||
@@ -443,6 +446,12 @@ Scene *BKE_scene_copy(Main *bmain, Scene *sce, int type)
|
||||
|
||||
BKE_previewimg_id_copy(&scen->id, &sce->id);
|
||||
|
||||
if (type != SCE_COPY_NEW) {
|
||||
if (sce->collection_properties) {
|
||||
IDP_MergeGroup(scen->collection_properties, sce->collection_properties, true);
|
||||
}
|
||||
}
|
||||
|
||||
return scen;
|
||||
}
|
||||
|
||||
|
@@ -138,5 +138,8 @@ RENDER_LAYER_TEST(move_into_layer_collection_i)
|
||||
RENDER_LAYER_TEST(move_into_layer_collection_j)
|
||||
RENDER_LAYER_TEST(layer_linking)
|
||||
RENDER_LAYER_TEST(layer_syncinc)
|
||||
RENDER_LAYER_TEST(scene_copy)
|
||||
RENDER_LAYER_TEST(scene_copy_a)
|
||||
RENDER_LAYER_TEST(scene_copy_b)
|
||||
RENDER_LAYER_TEST(scene_copy_c)
|
||||
RENDER_LAYER_TEST(scene_copy_d)
|
||||
RENDER_LAYER_TEST(scene_write_read)
|
||||
|
@@ -346,6 +346,42 @@ class RenderLayerTesting(unittest.TestCase):
|
||||
self.assertEqual(master_collection, bpy.context.scene.master_collection)
|
||||
master_collection.objects.link(bpy.data.objects.new('object', None))
|
||||
|
||||
def do_scene_copy(self, filepath_json_reference, copy_mode, data_callbacks):
|
||||
import bpy
|
||||
import os
|
||||
import tempfile
|
||||
import filecmp
|
||||
|
||||
ROOT = self.get_root()
|
||||
with tempfile.TemporaryDirectory() as dirpath:
|
||||
filepath_layers = os.path.join(ROOT, 'layers.blend')
|
||||
|
||||
(self.path_exists(f) for f in (
|
||||
filepath_layers,
|
||||
filepath_json_reference,
|
||||
))
|
||||
|
||||
filepath_saved = os.path.join(dirpath, '{0}.blend'.format(copy_mode))
|
||||
filepath_json = os.path.join(dirpath, "{0}.json".format(copy_mode))
|
||||
|
||||
bpy.ops.wm.open_mainfile('EXEC_DEFAULT', filepath=filepath_layers)
|
||||
self.rename_collections()
|
||||
bpy.ops.scene.new(type=copy_mode)
|
||||
bpy.ops.wm.save_mainfile('EXEC_DEFAULT', filepath=filepath_saved)
|
||||
|
||||
datas = query_scene(filepath_saved, 'Main.001', data_callbacks)
|
||||
self.assertTrue(datas, "Data is not valid")
|
||||
|
||||
with open(filepath_json, "w") as f:
|
||||
for data in datas:
|
||||
f.write(dump(data))
|
||||
|
||||
self.assertTrue(compare_files(
|
||||
filepath_json,
|
||||
filepath_json_reference,
|
||||
),
|
||||
"Scene copy \"{0}\" test failed".format(copy_mode.title()))
|
||||
|
||||
def cleanup_tree(self):
|
||||
"""
|
||||
Remove any existent layer and collections,
|
||||
|
@@ -1,119 +0,0 @@
|
||||
# ############################################################
|
||||
# Importing - Same For All Render Layer Tests
|
||||
# ############################################################
|
||||
|
||||
import unittest
|
||||
import os
|
||||
import sys
|
||||
|
||||
sys.path.append(os.path.dirname(__file__))
|
||||
from render_layer_common import *
|
||||
|
||||
|
||||
# ############################################################
|
||||
# Testing
|
||||
# ############################################################
|
||||
|
||||
class UnitTesting(RenderLayerTesting):
|
||||
def do_scene_copy(self, filepath_json_reference, copy_mode, data_callbacks):
|
||||
import bpy
|
||||
import os
|
||||
import tempfile
|
||||
import filecmp
|
||||
|
||||
ROOT = self.get_root()
|
||||
with tempfile.TemporaryDirectory() as dirpath:
|
||||
filepath_layers = os.path.join(ROOT, 'layers.blend')
|
||||
|
||||
(self.path_exists(f) for f in (
|
||||
filepath_layers,
|
||||
filepath_json_reference,
|
||||
))
|
||||
|
||||
filepath_saved = os.path.join(dirpath, '{0}.blend'.format(copy_mode))
|
||||
filepath_json = os.path.join(dirpath, "{0}.json".format(copy_mode))
|
||||
|
||||
bpy.ops.wm.open_mainfile('EXEC_DEFAULT', filepath=filepath_layers)
|
||||
self.rename_collections()
|
||||
bpy.ops.scene.new(type=copy_mode)
|
||||
bpy.ops.wm.save_mainfile('EXEC_DEFAULT', filepath=filepath_saved)
|
||||
|
||||
datas = query_scene(filepath_saved, 'Main.001', data_callbacks)
|
||||
self.assertTrue(datas, "Data is not valid")
|
||||
|
||||
with open(filepath_json, "w") as f:
|
||||
for data in datas:
|
||||
f.write(dump(data))
|
||||
|
||||
self.assertTrue(compare_files(
|
||||
filepath_json,
|
||||
filepath_json_reference,
|
||||
),
|
||||
"Scene copy \"{0}\" test failed".format(copy_mode.title()))
|
||||
|
||||
def test_scene_collections_copy_full(self):
|
||||
"""
|
||||
See if scene copying 'FULL_COPY' is working for scene collections
|
||||
"""
|
||||
import os
|
||||
ROOT = self.get_root()
|
||||
|
||||
filepath_layers_json_copy = os.path.join(ROOT, 'layers_copy_full_simple.json')
|
||||
self.do_scene_copy(
|
||||
filepath_layers_json_copy,
|
||||
'FULL_COPY',
|
||||
(get_scene_collections,))
|
||||
|
||||
def test_scene_collections_link(self):
|
||||
"""
|
||||
See if scene copying 'LINK_OBJECTS' is working for scene collections
|
||||
"""
|
||||
import os
|
||||
ROOT = self.get_root()
|
||||
|
||||
# note: nothing should change, so using `layers_simple.json`
|
||||
filepath_layers_json_copy = os.path.join(ROOT, 'layers_simple.json')
|
||||
self.do_scene_copy(
|
||||
filepath_layers_json_copy,
|
||||
'LINK_OBJECTS',
|
||||
(get_scene_collections,))
|
||||
|
||||
def test_scene_layers_copy(self):
|
||||
"""
|
||||
See if scene copying 'FULL_COPY' is working for scene layers
|
||||
"""
|
||||
import os
|
||||
ROOT = self.get_root()
|
||||
|
||||
filepath_layers_json_copy = os.path.join(ROOT, 'layers_copy_full.json')
|
||||
self.do_scene_copy(
|
||||
filepath_layers_json_copy,
|
||||
'FULL_COPY',
|
||||
(get_scene_collections, get_layers))
|
||||
|
||||
def test_scene_layers_link(self):
|
||||
"""
|
||||
See if scene copying 'FULL_COPY' is working for scene layers
|
||||
"""
|
||||
import os
|
||||
ROOT = self.get_root()
|
||||
|
||||
filepath_layers_json_copy = os.path.join(ROOT, 'layers_copy_link.json')
|
||||
self.do_scene_copy(
|
||||
filepath_layers_json_copy,
|
||||
'LINK_OBJECTS',
|
||||
(get_scene_collections, get_layers))
|
||||
|
||||
|
||||
# ############################################################
|
||||
# Main - Same For All Render Layer Tests
|
||||
# ############################################################
|
||||
|
||||
if __name__ == '__main__':
|
||||
import sys
|
||||
|
||||
extra_arguments = sys.argv[sys.argv.index("--") + 1:] if "--" in sys.argv else []
|
||||
sys.argv = [__file__] + (sys.argv[sys.argv.index("--") + 2:] if "--" in sys.argv else [])
|
||||
|
||||
UnitTesting._extra_arguments = extra_arguments
|
||||
unittest.main()
|
43
tests/python/render_layer/test_scene_copy_a.py
Normal file
43
tests/python/render_layer/test_scene_copy_a.py
Normal file
@@ -0,0 +1,43 @@
|
||||
# ############################################################
|
||||
# Importing - Same For All Render Layer Tests
|
||||
# ############################################################
|
||||
|
||||
import unittest
|
||||
import os
|
||||
import sys
|
||||
|
||||
sys.path.append(os.path.dirname(__file__))
|
||||
from render_layer_common import *
|
||||
|
||||
|
||||
# ############################################################
|
||||
# Testing
|
||||
# ############################################################
|
||||
|
||||
class UnitTesting(RenderLayerTesting):
|
||||
def test_scene_collections_copy_full(self):
|
||||
"""
|
||||
See if scene copying 'FULL_COPY' is working for scene collections
|
||||
"""
|
||||
import os
|
||||
ROOT = self.get_root()
|
||||
|
||||
filepath_layers_json_copy = os.path.join(ROOT, 'layers_copy_full_simple.json')
|
||||
self.do_scene_copy(
|
||||
filepath_layers_json_copy,
|
||||
'FULL_COPY',
|
||||
(get_scene_collections,))
|
||||
|
||||
|
||||
# ############################################################
|
||||
# Main - Same For All Render Layer Tests
|
||||
# ############################################################
|
||||
|
||||
if __name__ == '__main__':
|
||||
import sys
|
||||
|
||||
extra_arguments = sys.argv[sys.argv.index("--") + 1:] if "--" in sys.argv else []
|
||||
sys.argv = [__file__] + (sys.argv[sys.argv.index("--") + 2:] if "--" in sys.argv else [])
|
||||
|
||||
UnitTesting._extra_arguments = extra_arguments
|
||||
unittest.main()
|
44
tests/python/render_layer/test_scene_copy_b.py
Normal file
44
tests/python/render_layer/test_scene_copy_b.py
Normal file
@@ -0,0 +1,44 @@
|
||||
# ############################################################
|
||||
# Importing - Same For All Render Layer Tests
|
||||
# ############################################################
|
||||
|
||||
import unittest
|
||||
import os
|
||||
import sys
|
||||
|
||||
sys.path.append(os.path.dirname(__file__))
|
||||
from render_layer_common import *
|
||||
|
||||
|
||||
# ############################################################
|
||||
# Testing
|
||||
# ############################################################
|
||||
|
||||
class UnitTesting(RenderLayerTesting):
|
||||
def test_scene_collections_link(self):
|
||||
"""
|
||||
See if scene copying 'LINK_OBJECTS' is working for scene collections
|
||||
"""
|
||||
import os
|
||||
ROOT = self.get_root()
|
||||
|
||||
# note: nothing should change, so using `layers_simple.json`
|
||||
filepath_layers_json_copy = os.path.join(ROOT, 'layers_simple.json')
|
||||
self.do_scene_copy(
|
||||
filepath_layers_json_copy,
|
||||
'LINK_OBJECTS',
|
||||
(get_scene_collections,))
|
||||
|
||||
|
||||
# ############################################################
|
||||
# Main - Same For All Render Layer Tests
|
||||
# ############################################################
|
||||
|
||||
if __name__ == '__main__':
|
||||
import sys
|
||||
|
||||
extra_arguments = sys.argv[sys.argv.index("--") + 1:] if "--" in sys.argv else []
|
||||
sys.argv = [__file__] + (sys.argv[sys.argv.index("--") + 2:] if "--" in sys.argv else [])
|
||||
|
||||
UnitTesting._extra_arguments = extra_arguments
|
||||
unittest.main()
|
43
tests/python/render_layer/test_scene_copy_c.py
Normal file
43
tests/python/render_layer/test_scene_copy_c.py
Normal file
@@ -0,0 +1,43 @@
|
||||
# ############################################################
|
||||
# Importing - Same For All Render Layer Tests
|
||||
# ############################################################
|
||||
|
||||
import unittest
|
||||
import os
|
||||
import sys
|
||||
|
||||
sys.path.append(os.path.dirname(__file__))
|
||||
from render_layer_common import *
|
||||
|
||||
|
||||
# ############################################################
|
||||
# Testing
|
||||
# ############################################################
|
||||
|
||||
class UnitTesting(RenderLayerTesting):
|
||||
def test_scene_layers_copy(self):
|
||||
"""
|
||||
See if scene copying 'FULL_COPY' is working for scene layers
|
||||
"""
|
||||
import os
|
||||
ROOT = self.get_root()
|
||||
|
||||
filepath_layers_json_copy = os.path.join(ROOT, 'layers_copy_full.json')
|
||||
self.do_scene_copy(
|
||||
filepath_layers_json_copy,
|
||||
'FULL_COPY',
|
||||
(get_scene_collections, get_layers))
|
||||
|
||||
|
||||
# ############################################################
|
||||
# Main - Same For All Render Layer Tests
|
||||
# ############################################################
|
||||
|
||||
if __name__ == '__main__':
|
||||
import sys
|
||||
|
||||
extra_arguments = sys.argv[sys.argv.index("--") + 1:] if "--" in sys.argv else []
|
||||
sys.argv = [__file__] + (sys.argv[sys.argv.index("--") + 2:] if "--" in sys.argv else [])
|
||||
|
||||
UnitTesting._extra_arguments = extra_arguments
|
||||
unittest.main()
|
43
tests/python/render_layer/test_scene_copy_d.py
Normal file
43
tests/python/render_layer/test_scene_copy_d.py
Normal file
@@ -0,0 +1,43 @@
|
||||
# ############################################################
|
||||
# Importing - Same For All Render Layer Tests
|
||||
# ############################################################
|
||||
|
||||
import unittest
|
||||
import os
|
||||
import sys
|
||||
|
||||
sys.path.append(os.path.dirname(__file__))
|
||||
from render_layer_common import *
|
||||
|
||||
|
||||
# ############################################################
|
||||
# Testing
|
||||
# ############################################################
|
||||
|
||||
class UnitTesting(RenderLayerTesting):
|
||||
def test_scene_layers_link(self):
|
||||
"""
|
||||
See if scene copying 'FULL_COPY' is working for scene layers
|
||||
"""
|
||||
import os
|
||||
ROOT = self.get_root()
|
||||
|
||||
filepath_layers_json_copy = os.path.join(ROOT, 'layers_copy_link.json')
|
||||
self.do_scene_copy(
|
||||
filepath_layers_json_copy,
|
||||
'LINK_OBJECTS',
|
||||
(get_scene_collections, get_layers))
|
||||
|
||||
|
||||
# ############################################################
|
||||
# Main - Same For All Render Layer Tests
|
||||
# ############################################################
|
||||
|
||||
if __name__ == '__main__':
|
||||
import sys
|
||||
|
||||
extra_arguments = sys.argv[sys.argv.index("--") + 1:] if "--" in sys.argv else []
|
||||
sys.argv = [__file__] + (sys.argv[sys.argv.index("--") + 2:] if "--" in sys.argv else [])
|
||||
|
||||
UnitTesting._extra_arguments = extra_arguments
|
||||
unittest.main()
|
Reference in New Issue
Block a user