forked from bartvdbraak/blender
Layer: Adding unittest for a problem with selectability evaluation
This is currently failing (and causing the object_delete test to fail). To be fixed separately
This commit is contained in:
parent
ee6f858c91
commit
db6b4639fc
@ -69,6 +69,7 @@ RENDER_LAYER_TEST(evaluation_selectability_b)
|
|||||||
RENDER_LAYER_TEST(evaluation_selectability_c)
|
RENDER_LAYER_TEST(evaluation_selectability_c)
|
||||||
RENDER_LAYER_TEST(evaluation_selectability_d)
|
RENDER_LAYER_TEST(evaluation_selectability_d)
|
||||||
RENDER_LAYER_TEST(evaluation_selectability_e)
|
RENDER_LAYER_TEST(evaluation_selectability_e)
|
||||||
|
RENDER_LAYER_TEST(evaluation_selectability_f)
|
||||||
RENDER_LAYER_TEST(object_add_cylinder)
|
RENDER_LAYER_TEST(object_add_cylinder)
|
||||||
RENDER_LAYER_TEST(object_add_empty)
|
RENDER_LAYER_TEST(object_add_empty)
|
||||||
RENDER_LAYER_TEST(object_add_torus)
|
RENDER_LAYER_TEST(object_add_torus)
|
||||||
@ -76,7 +77,8 @@ RENDER_LAYER_TEST(object_add_no_collection_cylinder)
|
|||||||
RENDER_LAYER_TEST(object_add_no_collection_empty)
|
RENDER_LAYER_TEST(object_add_no_collection_empty)
|
||||||
RENDER_LAYER_TEST(object_add_no_collection_torus)
|
RENDER_LAYER_TEST(object_add_no_collection_torus)
|
||||||
RENDER_LAYER_TEST(object_copy)
|
RENDER_LAYER_TEST(object_copy)
|
||||||
RENDER_LAYER_TEST(object_delete)
|
RENDER_LAYER_TEST(object_delete_a)
|
||||||
|
RENDER_LAYER_TEST(object_delete_b)
|
||||||
RENDER_LAYER_TEST(object_link_a)
|
RENDER_LAYER_TEST(object_link_a)
|
||||||
RENDER_LAYER_TEST(object_link_b)
|
RENDER_LAYER_TEST(object_link_b)
|
||||||
RENDER_LAYER_TEST(object_link_c)
|
RENDER_LAYER_TEST(object_link_c)
|
||||||
|
@ -382,6 +382,67 @@ class RenderLayerTesting(unittest.TestCase):
|
|||||||
),
|
),
|
||||||
"Scene copy \"{0}\" test failed".format(copy_mode.title()))
|
"Scene copy \"{0}\" test failed".format(copy_mode.title()))
|
||||||
|
|
||||||
|
def do_object_delete(self, del_mode):
|
||||||
|
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')
|
||||||
|
filepath_reference_json = os.path.join(ROOT, 'layers_object_delete.json')
|
||||||
|
|
||||||
|
# open file
|
||||||
|
bpy.ops.wm.open_mainfile('EXEC_DEFAULT', filepath=filepath_layers)
|
||||||
|
self.rename_collections()
|
||||||
|
|
||||||
|
# create sub-collections
|
||||||
|
three_b = bpy.data.objects.get('T.3b')
|
||||||
|
three_d = bpy.data.objects.get('T.3d')
|
||||||
|
|
||||||
|
scene = bpy.context.scene
|
||||||
|
|
||||||
|
# mangle the file a bit with some objects linked across collections
|
||||||
|
subzero = scene.master_collection.collections['1'].collections.new('sub-zero')
|
||||||
|
scorpion = subzero.collections.new('scorpion')
|
||||||
|
subzero.objects.link(three_d)
|
||||||
|
scorpion.objects.link(three_b)
|
||||||
|
scorpion.objects.link(three_d)
|
||||||
|
|
||||||
|
# object to delete
|
||||||
|
ob = three_d
|
||||||
|
|
||||||
|
# delete object
|
||||||
|
if del_mode == 'DATA':
|
||||||
|
bpy.data.objects.remove(ob, do_unlink=True)
|
||||||
|
|
||||||
|
elif del_mode == 'OPERATOR':
|
||||||
|
bpy.context.scene.update() # update depsgraph
|
||||||
|
bpy.ops.object.select_all(action='DESELECT')
|
||||||
|
ob.select_set(action='SELECT')
|
||||||
|
self.assertTrue(ob.select_get())
|
||||||
|
bpy.ops.object.delete()
|
||||||
|
|
||||||
|
# save file
|
||||||
|
filepath_generated = os.path.join(dirpath, 'generated.blend')
|
||||||
|
bpy.ops.wm.save_mainfile('EXEC_DEFAULT', filepath=filepath_generated)
|
||||||
|
|
||||||
|
# get the generated json
|
||||||
|
datas = query_scene(filepath_generated, 'Main', (get_scene_collections, get_layers))
|
||||||
|
self.assertTrue(datas, "Data is not valid")
|
||||||
|
|
||||||
|
filepath_generated_json = os.path.join(dirpath, "generated.json")
|
||||||
|
with open(filepath_generated_json, "w") as f:
|
||||||
|
for data in datas:
|
||||||
|
f.write(dump(data))
|
||||||
|
|
||||||
|
self.assertTrue(compare_files(
|
||||||
|
filepath_generated_json,
|
||||||
|
filepath_reference_json,
|
||||||
|
),
|
||||||
|
"Scene dump files differ")
|
||||||
|
|
||||||
def cleanup_tree(self):
|
def cleanup_tree(self):
|
||||||
"""
|
"""
|
||||||
Remove any existent layer and collections,
|
Remove any existent layer and collections,
|
||||||
|
48
tests/python/render_layer/test_evaluation_selectability_f.py
Normal file
48
tests/python/render_layer/test_evaluation_selectability_f.py
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
# ############################################################
|
||||||
|
# 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_selectability(self):
|
||||||
|
import bpy
|
||||||
|
scene = bpy.context.scene
|
||||||
|
|
||||||
|
cube = bpy.data.objects.new('guinea pig', bpy.data.meshes.new('mesh'))
|
||||||
|
scene_collection = scene.master_collection.collections.new('collection')
|
||||||
|
layer_collection = scene.render_layers.active.collections.link(scene_collection)
|
||||||
|
|
||||||
|
bpy.context.scene.update() # update depsgraph
|
||||||
|
|
||||||
|
scene_collection.objects.link(cube)
|
||||||
|
|
||||||
|
self.assertFalse(layer_collection.hide)
|
||||||
|
self.assertFalse(layer_collection.hide_select)
|
||||||
|
|
||||||
|
bpy.context.scene.update() # update depsgraph
|
||||||
|
cube.select_set(action='SELECT')
|
||||||
|
self.assertTrue(cube.select_get())
|
||||||
|
|
||||||
|
# ############################################################
|
||||||
|
# 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()
|
@ -1,103 +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_object_delete(self, del_mode):
|
|
||||||
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')
|
|
||||||
filepath_reference_json = os.path.join(ROOT, 'layers_object_delete.json')
|
|
||||||
|
|
||||||
# open file
|
|
||||||
bpy.ops.wm.open_mainfile('EXEC_DEFAULT', filepath=filepath_layers)
|
|
||||||
self.rename_collections()
|
|
||||||
|
|
||||||
# create sub-collections
|
|
||||||
three_b = bpy.data.objects.get('T.3b')
|
|
||||||
three_d = bpy.data.objects.get('T.3d')
|
|
||||||
|
|
||||||
scene = bpy.context.scene
|
|
||||||
|
|
||||||
# mangle the file a bit with some objects linked across collections
|
|
||||||
subzero = scene.master_collection.collections['1'].collections.new('sub-zero')
|
|
||||||
scorpion = subzero.collections.new('scorpion')
|
|
||||||
subzero.objects.link(three_d)
|
|
||||||
scorpion.objects.link(three_b)
|
|
||||||
scorpion.objects.link(three_d)
|
|
||||||
|
|
||||||
# object to delete
|
|
||||||
ob = three_d
|
|
||||||
|
|
||||||
# delete object
|
|
||||||
if del_mode == 'DATA':
|
|
||||||
bpy.data.objects.remove(ob, do_unlink=True)
|
|
||||||
|
|
||||||
elif del_mode == 'OPERATOR':
|
|
||||||
bpy.ops.object.select_all(action='DESELECT')
|
|
||||||
ob.select_set(action='SELECT')
|
|
||||||
bpy.ops.object.delete()
|
|
||||||
|
|
||||||
# save file
|
|
||||||
filepath_generated = os.path.join(dirpath, 'generated.blend')
|
|
||||||
bpy.ops.wm.save_mainfile('EXEC_DEFAULT', filepath=filepath_generated)
|
|
||||||
|
|
||||||
# get the generated json
|
|
||||||
datas = query_scene(filepath_generated, 'Main', (get_scene_collections, get_layers))
|
|
||||||
self.assertTrue(datas, "Data is not valid")
|
|
||||||
|
|
||||||
filepath_generated_json = os.path.join(dirpath, "generated.json")
|
|
||||||
with open(filepath_generated_json, "w") as f:
|
|
||||||
for data in datas:
|
|
||||||
f.write(dump(data))
|
|
||||||
|
|
||||||
self.assertTrue(compare_files(
|
|
||||||
filepath_generated_json,
|
|
||||||
filepath_reference_json,
|
|
||||||
),
|
|
||||||
"Scene dump files differ")
|
|
||||||
|
|
||||||
def test_object_delete_data(self):
|
|
||||||
"""
|
|
||||||
See if objects are removed correctly from all related collections
|
|
||||||
bpy.data.objects.remove()
|
|
||||||
"""
|
|
||||||
self.do_object_delete('DATA')
|
|
||||||
|
|
||||||
def test_object_delete_operator(self):
|
|
||||||
"""
|
|
||||||
See if new objects are added to the correct collection
|
|
||||||
bpy.ops.object.del()
|
|
||||||
"""
|
|
||||||
self.do_object_delete('OPERATOR')
|
|
||||||
|
|
||||||
|
|
||||||
# ############################################################
|
|
||||||
# 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()
|
|
37
tests/python/render_layer/test_object_delete_a.py
Normal file
37
tests/python/render_layer/test_object_delete_a.py
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
# ############################################################
|
||||||
|
# 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_object_delete_data(self):
|
||||||
|
"""
|
||||||
|
See if objects are removed correctly from all related collections
|
||||||
|
bpy.data.objects.remove()
|
||||||
|
"""
|
||||||
|
self.do_object_delete('DATA')
|
||||||
|
|
||||||
|
|
||||||
|
# ############################################################
|
||||||
|
# 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()
|
37
tests/python/render_layer/test_object_delete_b.py
Normal file
37
tests/python/render_layer/test_object_delete_b.py
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
# ############################################################
|
||||||
|
# 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_object_delete_operator(self):
|
||||||
|
"""
|
||||||
|
See if new objects are added to the correct collection
|
||||||
|
bpy.ops.object.del()
|
||||||
|
"""
|
||||||
|
self.do_object_delete('OPERATOR')
|
||||||
|
|
||||||
|
|
||||||
|
# ############################################################
|
||||||
|
# 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()
|
Loading…
Reference in New Issue
Block a user