[Bf-blender-cvs] [225f638afd4] soc-2021-geometry-nodes-regression-test: Created a script for running blend file with pre-loaded modifier
Himanshi Kalra
noreply at git.blender.org
Thu Jun 17 07:46:16 CEST 2021
Commit: 225f638afd4a1820c2d71aff61f598282c6a6aad
Author: Himanshi Kalra
Date: Thu Jun 10 16:29:13 2021 +0530
Branches: soc-2021-geometry-nodes-regression-test
https://developer.blender.org/rB225f638afd4a1820c2d71aff61f598282c6a6aad
Created a script for running blend file with pre-loaded modifier
===================================================================
M tests/python/CMakeLists.txt
A tests/python/geo_node_test.py
===================================================================
diff --git a/tests/python/CMakeLists.txt b/tests/python/CMakeLists.txt
index 92cebb7d274..e7ce78a1d59 100644
--- a/tests/python/CMakeLists.txt
+++ b/tests/python/CMakeLists.txt
@@ -740,6 +740,21 @@ if(WITH_COMPOSITOR)
endif()
+set(geo_node_tests
+ geometry
+ mesh
+ points
+)
+
+foreach(geo_node_test ${geo_node_tests})
+
+ add_blender_test(
+ geo_node_${geo_node_test}_test
+ ${TEST_SRC_DIR}/geometry_nodes/${geo_node_test}
+ --python ${TEST_PYTHON_DIR}/geo_node_test.py
+ )
+endforeach()
+
if(WITH_OPENGL_DRAW_TESTS)
if(NOT OPENIMAGEIO_IDIFF)
MESSAGE(STATUS "Disabling OpenGL draw tests because OIIO idiff does not exist")
diff --git a/tests/python/geo_node_test.py b/tests/python/geo_node_test.py
new file mode 100644
index 00000000000..a684aeaf54d
--- /dev/null
+++ b/tests/python/geo_node_test.py
@@ -0,0 +1,113 @@
+# Load a blend file
+# Select the object
+# Apply the GN modifier on a duplicated object
+# Compare the result
+# If test pass, print("SUCESS")
+# If test fail, print("FAIL")
+ # Update tests if BLENDER_TEST_UPDATE flag is set.
+# Display result of failed tests [?]
+
+# Code to be re-used from Mesh Test
+# Depending on what all we want to use
+ ## the mesh comparison code
+ ## -- run-test code
+# Code to be re-used from a Compositor
+ ## Edit Cmake to iterate over directories.
+
+### Questions ###
+# Usage of __slots__ (only getting save memory, optimize) [Can Skip specific to Compositor]
+# How to keep track of failed tests.
+# Every blend file will run the test script and no memory.
+# For compositor, it only tells which directory has a failed test, not the exact file name
+# Pre-decide on the name of the test object and expected object ? Default name of the modifier?
+# Should I make it generic for any modifier or just geometry nodes?
+
+
+### RUN TEST COMMAND ###
+# blender -b path_to_blend_file --python path/to/geo_node_test.py
+
+import bpy
+import os
+
+def get_objects():
+ try:
+ test_object = bpy.data.objects["test_obj"]
+ except:
+ raise Exception("No test object found!")
+ try:
+ expected_object = bpy.data.objects["expected_obj"]
+ except:
+ raise Exception("No expected object found!")
+ return [test_object, expected_object]
+
+def apply_modifier(evaluated_object):
+ """
+ Apply all modifiers added to the current object [Discuss]
+ """
+ bpy.ops.object.mode_set(mode="OBJECT")
+ bpy.ops.object.select_all(action="DESELECT")
+ bpy.context.view_layer.objects.active = evaluated_object
+
+ modifiers_list = evaluated_object.modifiers
+
+ if modifiers_list[0].type == "NODES":
+ bpy.ops.object.modifier_apply(modifier=modifiers_list[0].name)
+ else:
+ raise Exception("Modifier not of Geometry Nodes type")
+ return evaluated_object
+
+
+def compare_mesh(evaluated_object, expected_object):
+ evaluated_data = evaluated_object.data
+ exp_data = expected_object.data
+ result = evaluated_data.unit_test_compare(mesh=exp_data)
+ if result == "Same":
+ print("PASS")
+ else:
+ failed_test(evaluated_object, expected_object, result)
+
+def passed_test():
+ pass
+
+def failed_test(evaluated_object, expected_object, result):
+ """
+ [Need discussion]
+ """
+ update_test_flag = os.getenv('BLENDER_TEST_UPDATE') is not None
+ if not update_test_flag:
+ print("Test failed with {}".format(result))
+ return
+
+ evaluated_object.location = expected_object.location
+ expected_object_name = expected_object.name
+ bpy.data.objects.remove(expected_object, do_unlink=True)
+ evaluated_object.name = expected_object_name
+
+ # Save file.
+ bpy.ops.wm.save_as_mainfile(filepath=bpy.data.filepath)
+
+ print("The test file was updated with new expected object")
+ print("The blend file was saved.")
+
+def duplicate_test_object(test_object):
+ # Duplicate test object.
+ bpy.ops.object.mode_set(mode="OBJECT")
+ bpy.ops.object.select_all(action="DESELECT")
+ bpy.context.view_layer.objects.active = test_object
+
+ test_object.select_set(True)
+ bpy.ops.object.duplicate()
+ evaluated_object = bpy.context.active_object
+ evaluated_object.name = "evaluated_object"
+ return evaluated_object
+
+def main():
+ test_object, expected_object = get_objects()
+ evaluated_object = duplicate_test_object(test_object)
+ evaluated_object = apply_modifier(evaluated_object)
+ compare_mesh(evaluated_object, expected_object)
+
+
+
+if __name__ == "__main__":
+ main()
\ No newline at end of file
More information about the Bf-blender-cvs
mailing list