forked from bartvdbraak/blender
Unittest: split object_add in individual test files
(and small cleanup in unittest) This is required to the upcoming unittest + bugfix
This commit is contained in:
parent
4c8d8da2e7
commit
8261a84ffb
@ -64,7 +64,9 @@ RENDER_LAYER_TEST(active_collection)
|
|||||||
RENDER_LAYER_TEST(object_delete)
|
RENDER_LAYER_TEST(object_delete)
|
||||||
RENDER_LAYER_TEST(link)
|
RENDER_LAYER_TEST(link)
|
||||||
RENDER_LAYER_TEST(operator_context)
|
RENDER_LAYER_TEST(operator_context)
|
||||||
RENDER_LAYER_TEST(object_add)
|
RENDER_LAYER_TEST(object_add_cylinder)
|
||||||
|
RENDER_LAYER_TEST(object_add_empty)
|
||||||
|
RENDER_LAYER_TEST(object_add_torus)
|
||||||
RENDER_LAYER_TEST(object_copy)
|
RENDER_LAYER_TEST(object_copy)
|
||||||
RENDER_LAYER_TEST(evaluation_visibility_a)
|
RENDER_LAYER_TEST(evaluation_visibility_a)
|
||||||
RENDER_LAYER_TEST(evaluation_visibility_b)
|
RENDER_LAYER_TEST(evaluation_visibility_b)
|
||||||
|
@ -199,18 +199,6 @@ class RenderLayerTesting(unittest.TestCase):
|
|||||||
cls.pretest_import_blendfile()
|
cls.pretest_import_blendfile()
|
||||||
cls.pretest_parsing()
|
cls.pretest_parsing()
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def setUp(cls):
|
|
||||||
"""Runs once per test"""
|
|
||||||
import bpy
|
|
||||||
bpy.ops.wm.read_factory_settings()
|
|
||||||
|
|
||||||
def path_exists(self, filepath):
|
|
||||||
import os
|
|
||||||
self.assertTrue(
|
|
||||||
os.path.exists(filepath),
|
|
||||||
"Test file \"{0}\" not found".format(filepath))
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_root(cls):
|
def get_root(cls):
|
||||||
"""
|
"""
|
||||||
@ -243,3 +231,81 @@ class RenderLayerTesting(unittest.TestCase):
|
|||||||
import_blendfile()
|
import_blendfile()
|
||||||
import blendfile
|
import blendfile
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
"""Runs once per test"""
|
||||||
|
import bpy
|
||||||
|
bpy.ops.wm.read_factory_settings()
|
||||||
|
|
||||||
|
def path_exists(self, filepath):
|
||||||
|
import os
|
||||||
|
self.assertTrue(
|
||||||
|
os.path.exists(filepath),
|
||||||
|
"Test file \"{0}\" not found".format(filepath))
|
||||||
|
|
||||||
|
def do_object_add(self, filepath_json, add_mode):
|
||||||
|
"""
|
||||||
|
Testing for adding objects and see if they
|
||||||
|
go to the right collection
|
||||||
|
"""
|
||||||
|
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')
|
||||||
|
|
||||||
|
# open file
|
||||||
|
bpy.ops.wm.open_mainfile('EXEC_DEFAULT', filepath=filepath_layers)
|
||||||
|
|
||||||
|
# create sub-collections
|
||||||
|
three_b = bpy.data.objects.get('T.3b')
|
||||||
|
three_c = bpy.data.objects.get('T.3c')
|
||||||
|
|
||||||
|
scene = bpy.context.scene
|
||||||
|
subzero = scene.master_collection.collections['1'].collections.new('sub-zero')
|
||||||
|
scorpion = subzero.collections.new('scorpion')
|
||||||
|
subzero.objects.link(three_b)
|
||||||
|
scorpion.objects.link(three_c)
|
||||||
|
layer = scene.render_layers.new('Fresh new Layer')
|
||||||
|
layer.collections.link(subzero)
|
||||||
|
|
||||||
|
# change active collection
|
||||||
|
layer.collections.active_index = 3
|
||||||
|
self.assertEqual(layer.collections.active.name, 'scorpion', "Run: test_syncing_object_add")
|
||||||
|
|
||||||
|
# change active layer
|
||||||
|
override = bpy.context.copy()
|
||||||
|
override["render_layer"] = layer
|
||||||
|
override["scene_collection"] = layer.collections.active.collection
|
||||||
|
|
||||||
|
# add new objects
|
||||||
|
if add_mode == 'EMPTY':
|
||||||
|
bpy.ops.object.add(override) # 'Empty'
|
||||||
|
|
||||||
|
elif add_mode == 'CYLINDER':
|
||||||
|
bpy.ops.mesh.primitive_cylinder_add(override) # 'Cylinder'
|
||||||
|
|
||||||
|
elif add_mode == 'TORUS':
|
||||||
|
bpy.ops.mesh.primitive_torus_add(override) # 'Torus'
|
||||||
|
|
||||||
|
# save file
|
||||||
|
filepath_objects = os.path.join(dirpath, 'objects.blend')
|
||||||
|
bpy.ops.wm.save_mainfile('EXEC_DEFAULT', filepath=filepath_objects)
|
||||||
|
|
||||||
|
# get the generated json
|
||||||
|
datas = query_scene(filepath_objects, 'Main', (get_scene_collections, get_layers))
|
||||||
|
self.assertTrue(datas, "Data is not valid")
|
||||||
|
|
||||||
|
filepath_objects_json = os.path.join(dirpath, "objects.json")
|
||||||
|
with open(filepath_objects_json, "w") as f:
|
||||||
|
for data in datas:
|
||||||
|
f.write(dump(data))
|
||||||
|
|
||||||
|
self.assertTrue(compare_files(
|
||||||
|
filepath_objects_json,
|
||||||
|
filepath_json,
|
||||||
|
),
|
||||||
|
"Scene dump files differ")
|
||||||
|
|
||||||
|
@ -1,125 +0,0 @@
|
|||||||
# ./blender.bin --background -noaudio --python tests/python/render_layer/test_scene_copy.py -- --testdir="/data/lib/tests/"
|
|
||||||
|
|
||||||
# ############################################################
|
|
||||||
# Importing - Same For All Render Layer Tests
|
|
||||||
# ############################################################
|
|
||||||
|
|
||||||
import unittest
|
|
||||||
|
|
||||||
import os, sys
|
|
||||||
sys.path.append(os.path.dirname(__file__))
|
|
||||||
|
|
||||||
from render_layer_common import *
|
|
||||||
|
|
||||||
|
|
||||||
# ############################################################
|
|
||||||
# Testing
|
|
||||||
# ############################################################
|
|
||||||
|
|
||||||
class UnitTesting(RenderLayerTesting):
|
|
||||||
def do_object_add(self, filepath_json, add_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')
|
|
||||||
|
|
||||||
# open file
|
|
||||||
bpy.ops.wm.open_mainfile('EXEC_DEFAULT', filepath=filepath_layers)
|
|
||||||
|
|
||||||
# create sub-collections
|
|
||||||
three_b = bpy.data.objects.get('T.3b')
|
|
||||||
three_c = bpy.data.objects.get('T.3c')
|
|
||||||
|
|
||||||
scene = bpy.context.scene
|
|
||||||
subzero = scene.master_collection.collections['1'].collections.new('sub-zero')
|
|
||||||
scorpion = subzero.collections.new('scorpion')
|
|
||||||
subzero.objects.link(three_b)
|
|
||||||
scorpion.objects.link(three_c)
|
|
||||||
layer = scene.render_layers.new('Fresh new Layer')
|
|
||||||
layer.collections.link(subzero)
|
|
||||||
|
|
||||||
# change active collection
|
|
||||||
layer.collections.active_index = 3
|
|
||||||
self.assertEqual(layer.collections.active.name, 'scorpion', "Run: test_syncing_object_add")
|
|
||||||
|
|
||||||
# change active layer
|
|
||||||
override = bpy.context.copy()
|
|
||||||
override["render_layer"] = layer
|
|
||||||
override["scene_collection"] = layer.collections.active.collection
|
|
||||||
|
|
||||||
# add new objects
|
|
||||||
if add_mode == 'EMPTY':
|
|
||||||
bpy.ops.object.add(override) # 'Empty'
|
|
||||||
|
|
||||||
elif add_mode == 'CYLINDER':
|
|
||||||
bpy.ops.mesh.primitive_cylinder_add(override) # 'Cylinder'
|
|
||||||
|
|
||||||
elif add_mode == 'TORUS':
|
|
||||||
bpy.ops.mesh.primitive_torus_add(override) # 'Torus'
|
|
||||||
|
|
||||||
# save file
|
|
||||||
filepath_objects = os.path.join(dirpath, 'objects.blend')
|
|
||||||
bpy.ops.wm.save_mainfile('EXEC_DEFAULT', filepath=filepath_objects)
|
|
||||||
|
|
||||||
# get the generated json
|
|
||||||
datas = query_scene(filepath_objects, 'Main', (get_scene_collections, get_layers))
|
|
||||||
self.assertTrue(datas, "Data is not valid")
|
|
||||||
|
|
||||||
filepath_objects_json = os.path.join(dirpath, "objects.json")
|
|
||||||
with open(filepath_objects_json, "w") as f:
|
|
||||||
for data in datas:
|
|
||||||
f.write(dump(data))
|
|
||||||
|
|
||||||
self.assertTrue(compare_files(
|
|
||||||
filepath_objects_json,
|
|
||||||
filepath_json,
|
|
||||||
),
|
|
||||||
"Scene dump files differ")
|
|
||||||
|
|
||||||
def test_syncing_object_add_empty(self):
|
|
||||||
"""
|
|
||||||
See if new objects are added to the correct collection
|
|
||||||
bpy.ops.object.add()
|
|
||||||
"""
|
|
||||||
import os
|
|
||||||
ROOT = self.get_root()
|
|
||||||
filepath_json = os.path.join(ROOT, 'layers_object_add_empty.json')
|
|
||||||
self.do_object_add(filepath_json, 'EMPTY')
|
|
||||||
|
|
||||||
def test_syncing_object_add_cylinder(self):
|
|
||||||
"""
|
|
||||||
See if new objects are added to the correct collection
|
|
||||||
bpy.ops.mesh.primitive_cylinder_add()
|
|
||||||
"""
|
|
||||||
import os
|
|
||||||
ROOT = self.get_root()
|
|
||||||
filepath_json = os.path.join(ROOT, 'layers_object_add_cylinder.json')
|
|
||||||
self.do_object_add(filepath_json, 'CYLINDER')
|
|
||||||
|
|
||||||
def test_syncing_object_add_torus(self):
|
|
||||||
"""
|
|
||||||
See if new objects are added to the correct collection
|
|
||||||
bpy.ops.mesh.primitive_torus_add()
|
|
||||||
"""
|
|
||||||
import os
|
|
||||||
ROOT = self.get_root()
|
|
||||||
filepath_json = os.path.join(ROOT, 'layers_object_add_torus.json')
|
|
||||||
self.do_object_add(filepath_json, 'TORUS')
|
|
||||||
|
|
||||||
|
|
||||||
# ############################################################
|
|
||||||
# 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()
|
|
42
tests/python/render_layer/test_object_add_cylinder.py
Normal file
42
tests/python/render_layer/test_object_add_cylinder.py
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
# ./blender.bin --background -noaudio --python tests/python/render_layer/test_scene_copy.py -- --testdir="/data/lib/tests/"
|
||||||
|
|
||||||
|
# ############################################################
|
||||||
|
# Importing - Same For All Render Layer Tests
|
||||||
|
# ############################################################
|
||||||
|
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
import os, sys
|
||||||
|
sys.path.append(os.path.dirname(__file__))
|
||||||
|
|
||||||
|
from render_layer_common import *
|
||||||
|
|
||||||
|
|
||||||
|
# ############################################################
|
||||||
|
# Testing
|
||||||
|
# ############################################################
|
||||||
|
|
||||||
|
class UnitTesting(RenderLayerTesting):
|
||||||
|
def test_syncing_object_add_cylinder(self):
|
||||||
|
"""
|
||||||
|
See if new objects are added to the correct collection
|
||||||
|
bpy.ops.mesh.primitive_cylinder_add()
|
||||||
|
"""
|
||||||
|
import os
|
||||||
|
ROOT = self.get_root()
|
||||||
|
filepath_json = os.path.join(ROOT, 'layers_object_add_cylinder.json')
|
||||||
|
self.do_object_add(filepath_json, 'CYLINDER')
|
||||||
|
|
||||||
|
|
||||||
|
# ############################################################
|
||||||
|
# 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()
|
42
tests/python/render_layer/test_object_add_empty.py
Normal file
42
tests/python/render_layer/test_object_add_empty.py
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
# ./blender.bin --background -noaudio --python tests/python/render_layer/test_scene_copy.py -- --testdir="/data/lib/tests/"
|
||||||
|
|
||||||
|
# ############################################################
|
||||||
|
# Importing - Same For All Render Layer Tests
|
||||||
|
# ############################################################
|
||||||
|
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
import os, sys
|
||||||
|
sys.path.append(os.path.dirname(__file__))
|
||||||
|
|
||||||
|
from render_layer_common import *
|
||||||
|
|
||||||
|
|
||||||
|
# ############################################################
|
||||||
|
# Testing
|
||||||
|
# ############################################################
|
||||||
|
|
||||||
|
class UnitTesting(RenderLayerTesting):
|
||||||
|
def test_syncing_object_add_empty(self):
|
||||||
|
"""
|
||||||
|
See if new objects are added to the correct collection
|
||||||
|
bpy.ops.object.add()
|
||||||
|
"""
|
||||||
|
import os
|
||||||
|
ROOT = self.get_root()
|
||||||
|
filepath_json = os.path.join(ROOT, 'layers_object_add_empty.json')
|
||||||
|
self.do_object_add(filepath_json, 'EMPTY')
|
||||||
|
|
||||||
|
|
||||||
|
# ############################################################
|
||||||
|
# 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()
|
42
tests/python/render_layer/test_object_add_torus.py
Normal file
42
tests/python/render_layer/test_object_add_torus.py
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
# ./blender.bin --background -noaudio --python tests/python/render_layer/test_scene_copy.py -- --testdir="/data/lib/tests/"
|
||||||
|
|
||||||
|
# ############################################################
|
||||||
|
# Importing - Same For All Render Layer Tests
|
||||||
|
# ############################################################
|
||||||
|
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
import os, sys
|
||||||
|
sys.path.append(os.path.dirname(__file__))
|
||||||
|
|
||||||
|
from render_layer_common import *
|
||||||
|
|
||||||
|
|
||||||
|
# ############################################################
|
||||||
|
# Testing
|
||||||
|
# ############################################################
|
||||||
|
|
||||||
|
class UnitTesting(RenderLayerTesting):
|
||||||
|
def test_syncing_object_add_torus(self):
|
||||||
|
"""
|
||||||
|
See if new objects are added to the correct collection
|
||||||
|
bpy.ops.mesh.primitive_torus_add()
|
||||||
|
"""
|
||||||
|
import os
|
||||||
|
ROOT = self.get_root()
|
||||||
|
filepath_json = os.path.join(ROOT, 'layers_object_add_torus.json')
|
||||||
|
self.do_object_add(filepath_json, 'TORUS')
|
||||||
|
|
||||||
|
|
||||||
|
# ############################################################
|
||||||
|
# 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