Commit: a7d2ca5064e449747c1ad0b02037d6bf527c0d61
Author: calra123
Date:   Sun Jul 12 01:25:59 2020 +0530
Branches: soc-2020-testing-frameworks
https://developer.blender.org/rBa7d2ca5064e449747c1ad0b02037d6bf527c0d61

Post Review: Added DeformModifierTest class to run Deform Tests by name, added 
run test by name for Modifers and Operators, removed deform flag, modifier is 
applied separately

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

M       tests/python/deform_modifiers.py
M       tests/python/modifiers.py
M       tests/python/modules/mesh_test.py

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

diff --git a/tests/python/deform_modifiers.py b/tests/python/deform_modifiers.py
index d0277f4b498..03e0b4105b3 100644
--- a/tests/python/deform_modifiers.py
+++ b/tests/python/deform_modifiers.py
@@ -3,7 +3,7 @@ import sys
 import bpy
 
 sys.path.append(os.path.dirname(os.path.realpath(__file__)))
-from modules.mesh_test import MeshTest, ModifierSpec, ObjectOperatorSpec, 
DeformModifierSpec
+from modules.mesh_test import MeshTest, ModifierSpec, ObjectOperatorSpec, 
DeformModifierSpec, DeformModifierTest
 
 tests = [
 
@@ -12,7 +12,7 @@ tests = [
 
     MeshTest("SurfaceDeform", "testObjMonkeySurfaceDeform", 
"expObjMonkeySurfaceDeform",
              [DeformModifierSpec(10, [ModifierSpec('surface_deform', 
'SURFACE_DEFORM', {'target': bpy.data.objects["Cube"]})],
-              ObjectOperatorSpec('surfacedeform_bind', {'modifier': 
'surface_deform'}))], True, True),
+              ObjectOperatorSpec('surfacedeform_bind', {'modifier': 
'surface_deform'}))]),
 
     # Mesh Deform Test, finally can bind to the Target object.
     # Actual deformation occurs by animating imitating user input.
@@ -20,7 +20,7 @@ tests = [
     MeshTest("MeshDeform", "testObjMonkeyMeshDeform", "expObjMonkeyMeshDeform",
              [DeformModifierSpec(10, [ModifierSpec('mesh_deform', 
'MESH_DEFORM', {'object': bpy.data.objects["MeshCube"],
                                                                                
  'precision': 2})],
-                                 ObjectOperatorSpec('meshdeform_bind', 
{'modifier': 'mesh_deform'}))], True, True),
+                                 ObjectOperatorSpec('meshdeform_bind', 
{'modifier': 'mesh_deform'}))]),
 
 
     # Surface Deform Test, finally can bind to the Target object.
@@ -29,7 +29,7 @@ tests = [
     MeshTest("Hook", "testObjHookPlane", "expObjHookPlane",
              [DeformModifierSpec(10, [ModifierSpec('hook', 'HOOK',
                                                   {'object': 
bpy.data.objects["Empty"], 'falloff_radius': 1,
-                                                   'vertex_group': 
'Group'})])], True, True),
+                                                   'vertex_group': 
'Group'})])]),
 
 
     # Laplacian Deform Test, first a hook is attached.
@@ -39,20 +39,27 @@ tests = [
                                  [ModifierSpec('hook2', 'HOOK', {'object': 
bpy.data.objects["Empty.001"],
                                                                 
'vertex_group': 'hook_vg'}),
                                  ModifierSpec('laplace', 'LAPLACIANDEFORM', 
{'vertex_group': 'laplace_vg'})],
-                                 ObjectOperatorSpec('laplaciandeform_bind', 
{'modifier':'laplace'}))], True, True),
+                                 ObjectOperatorSpec('laplaciandeform_bind', 
{'modifier':'laplace'}))]),
 
 
     MeshTest("WarpPlane", "testObjPlaneWarp", "expObjPlaneWarp",
              [DeformModifierSpec(10, [ModifierSpec('warp', 'WARP',
                                                    {'object_from': 
bpy.data.objects["From"], 'object_to': bpy.data.objects["To"],
-                                                    })])], True, True),
+                                                    })])]),
 
 
 
 ]
+
+deform_tests = DeformModifierTest(tests)
 command = list(sys.argv)
 for i, cmd in enumerate(command):
     if cmd == "--run-all-tests":
-        for mesh_test in tests:
-            mesh_test.run_test()
+        deform_tests.apply_modifiers = True
+        deform_tests.run_all_tests()
+        break
+    elif cmd == "--run-test":
+        deform_tests.apply_modifiers = False
+        name = str(command[i + 1])
+        deform_tests.run_test(name)
         break
diff --git a/tests/python/modifiers.py b/tests/python/modifiers.py
index ee68b9d385e..f0b2ef77c37 100644
--- a/tests/python/modifiers.py
+++ b/tests/python/modifiers.py
@@ -278,8 +278,8 @@ def main():
             break
         elif cmd == "--run-test":
             modifiers_test.apply_modifiers = False
-            index = int(command[i + 1])
-            modifiers_test.run_test(index)
+            name = str(command[i + 1])
+            modifiers_test.run_test(name)
             break
 
 
diff --git a/tests/python/modules/mesh_test.py 
b/tests/python/modules/mesh_test.py
index b7686e78fe6..d8c81396f41 100644
--- a/tests/python/modules/mesh_test.py
+++ b/tests/python/modules/mesh_test.py
@@ -165,7 +165,7 @@ class MeshTest:
     the public method run_test().
     """
 
-    def __init__(self, test_name: str, test_object_name: str, 
expected_object_name: str, operations_stack=None, apply_modifiers=False, 
apply_object_operator=False, threshold=None):
+    def __init__(self, test_name: str, test_object_name: str, 
expected_object_name: str, operations_stack=None, apply_modifiers=False, 
threshold=None):
         """
         Constructs a MeshTest object. Raises a KeyError if objects with names 
expected_object_name
         or test_object_name don't exist.
@@ -174,7 +174,7 @@ class MeshTest:
                                 geometry after running the operations.
         :param operations_stack: list - stack holding operations to perform on 
the test_object.
         :param apply_modifier: bool - True if we want to apply the modifiers 
right after adding them to the object.
-                               This affects operations of type ModifierSpec 
only.
+                               This affects operations of type ModifierSpec 
and DeformModifierSpec.
         :param test_name: str - unique test name identifier.
         """
         if operations_stack is None:
@@ -188,7 +188,6 @@ class MeshTest:
                                         type(operation)))
         self.operations_stack = operations_stack
         self.apply_modifier = apply_modifiers
-        self.apply_object_operator = apply_object_operator
         self.threshold = threshold
         self.test_name = test_name
 
@@ -298,13 +297,6 @@ class MeshTest:
                 raise AttributeError("Modifier '{}' has no parameter named 
'{}'".
                                      format(modifier_spec.modifier_type, 
param_name))
 
-        if self.apply_modifier:
-            if not self.apply_object_operator:
-                self._apply_modifier(modifier_spec.modifier_name)
-
-    def _apply_modifier(self, modifier_name):
-        bpy.ops.object.modifier_apply(modifier=modifier_name)
-
     def _bake_current_simulation(self, obj, test_mod_type, test_mod_name, 
frame_end):
         for scene in bpy.data.scenes:
             for modifier in obj.modifiers:
@@ -386,7 +378,7 @@ class MeshTest:
 
     def _apply_object_operator(self, operator: ObjectOperatorSpec):
         """
-        Applies the operator of the modifier.
+        Applies the object operator.
         """
         bpy.ops.object.mode_set(mode='OBJECT')
         object_operator = getattr(bpy.ops.object, operator.operator_name)
@@ -395,11 +387,6 @@ class MeshTest:
         if not object_operator:
             raise AttributeError("No object operator {} 
found!".format(operator.operator_name))
 
-        # # Modifier name should be passed to the "modifier_apply" function,
-        # # since this is an operator of the modifier itself, the parameters 
are the same.
-        # if self.apply_object_operator:
-        #     bpy.ops.object.modifier_apply(**operator.operator_parameters)
-
         if retval != {'FINISHED'}:
             raise RuntimeError("Unexpected operator return value: 
{}".format(retval))
         if self.verbose:
@@ -424,9 +411,10 @@ class MeshTest:
         print("NAME", list(test_object.modifiers))
 
         scene.frame_set(operation.frame_number)
-        if self.apply_object_operator:
+
+        if self.apply_modifier:
             for mod_name in modifier_names:
-                self._apply_modifier(mod_name)
+                bpy.ops.object.modifier_apply(modifier=mod_name)
 
     def run_test(self):
         """
@@ -447,12 +435,15 @@ class MeshTest:
         evaluated_test_object = bpy.context.active_object
         evaluated_test_object.name = "evaluated_object"
         if self.verbose:
+            print()
             print(evaluated_test_object.name, "is set to active")
 
         # Add modifiers and operators.
         for operation in self.operations_stack:
             if isinstance(operation, ModifierSpec):
                 self._add_modifier(evaluated_test_object, operation)
+                if self.apply_modifier:
+                    
bpy.ops.object.modifier_apply(modifier=operation.modifier_name)
 
             elif isinstance(operation, OperatorSpec):
                 self._apply_operator(evaluated_test_object, operation)
@@ -547,13 +538,23 @@ class OperatorTest:
             else:
                 seen_name.add(ele)
 
-    def run_test(self, index: int):
+    def run_test(self, test_name: str):
         """
         Run a single test from operator_tests list
-        :param index: int - index of test
+        :param test_name: str - name of test
         :return: bool - True if test is successful. False otherwise.
         """
-        case = self.operator_tests[index]
+        case = self.operator_tests[0]
+        len_test = len(self.operator_tests)
+        count = 0
+        for index,_ in enumerate(self.operator_tests):
+            if test_name == self.operator_tests[index][2]:
+                case = self.operator_tests[index]
+                break
+            count = count + 1
+        if count == len_test:
+            raise Exception("No test {} found!".format(test_name))
+
         if len(case) != 7:
             raise ValueError("Expected exactly 7 parameters for each test 
case, got {}".format(len(case)))
         select_mode = case[0]
@@ -577,13 +578,14 @@ class OperatorTest:
 
     def run_all_tests(self):
         for index, _ in enumerate(self.operator_tests):
+            test_name = self.operator_tests[index][2]
             if self.verbose:
                 print()
                 print("Running test {}...".format(index))
-            success = self.run_test(index)
+            success = self.run_test(test_name)
 
             if not success:
-                self._failed_tests_list.append(index)
+                self._failed_tests_list.append(test_name)
 
         if len(s

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to