[Bf-blender-cvs] [8261a84ffb] blender2.8: Unittest: split object_add in individual test files

Dalai Felinto noreply at git.blender.org
Fri Feb 24 10:14:46 CET 2017


Commit: 8261a84ffbe6d6a88389f374656135cef53e5b15
Author: Dalai Felinto
Date:   Thu Feb 23 12:26:48 2017 +0100
Branches: blender2.8
https://developer.blender.org/rB8261a84ffbe6d6a88389f374656135cef53e5b15

Unittest: split object_add in individual test files

(and small cleanup in unittest)

This is required to the upcoming unittest + bugfix

===================================================================

M	tests/python/render_layer/CMakeLists.txt
M	tests/python/render_layer/render_layer_common.py
D	tests/python/render_layer/test_object_add.py
A	tests/python/render_layer/test_object_add_cylinder.py
A	tests/python/render_layer/test_object_add_empty.py
A	tests/python/render_layer/test_object_add_torus.py

===================================================================

diff --git a/tests/python/render_layer/CMakeLists.txt b/tests/python/render_layer/CMakeLists.txt
index f47b193f8c..ff98d95cc0 100644
--- a/tests/python/render_layer/CMakeLists.txt
+++ b/tests/python/render_layer/CMakeLists.txt
@@ -64,7 +64,9 @@ RENDER_LAYER_TEST(active_collection)
 RENDER_LAYER_TEST(object_delete)
 RENDER_LAYER_TEST(link)
 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(evaluation_visibility_a)
 RENDER_LAYER_TEST(evaluation_visibility_b)
diff --git a/tests/python/render_layer/render_layer_common.py b/tests/python/render_layer/render_layer_common.py
index 4a289936b2..e551518ac5 100644
--- a/tests/python/render_layer/render_layer_common.py
+++ b/tests/python/render_layer/render_layer_common.py
@@ -200,18 +200,6 @@ class RenderLayerTesting(unittest.TestCase):
         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
     def get_root(cls):
         """
         return the folder with the test files
@@ -243,3 +231,81 @@ class RenderLayerTesting(unittest.TestCase):
         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")
+
diff --git a/tests/python/render_layer/test_object_add.py b/tests/python/render_layer/test_object_add.py
deleted file mode 100644
index 4c9402bd2f..0000000000
--- a/tests/python/render_layer/test_object_add.py
+++ /dev/null
@@ -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()
diff --git a/tests/python/render_layer/test_object_add_cylinder.py b/tests/python/render_layer/test_object_add_cylinder.py
new file mode 100644
index 0000000000..99ac0eebfb
--- /dev/null
+++ b/tests/python/render_layer/test_object_add_cylinder.py
@@ -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):
+  

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list