Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'tests/python')
-rw-r--r--tests/python/CMakeLists.txt304
-rwxr-xr-xtests/python/alembic_tests.py478
-rw-r--r--tests/python/batch_import.py41
-rw-r--r--tests/python/bl_alembic_import_test.py270
-rw-r--r--tests/python/bl_keymap_completeness.py1
-rw-r--r--tests/python/bl_load_py_modules.py69
-rw-r--r--tests/python/bl_mesh_modifiers.py75
-rw-r--r--tests/python/bl_pyapi_bpy_utils_units.py19
-rw-r--r--tests/python/bl_pyapi_idprop.py204
-rw-r--r--tests/python/bl_pyapi_idprop_datablock.py338
-rw-r--r--tests/python/bl_pyapi_mathutils.py9
-rw-r--r--tests/python/bl_run_operators.py18
-rwxr-xr-xtests/python/cycles_render_tests.py408
-rw-r--r--tests/python/pep8.py1
-rw-r--r--tests/python/rna_info_dump.py1
15 files changed, 1986 insertions, 250 deletions
diff --git a/tests/python/CMakeLists.txt b/tests/python/CMakeLists.txt
index a29b612e0ef..7e42f36c6e4 100644
--- a/tests/python/CMakeLists.txt
+++ b/tests/python/CMakeLists.txt
@@ -18,7 +18,7 @@
#
# ***** END GPL LICENSE BLOCK *****
-# --env-system-scripts allows to run without the install target.
+# --env-system-scripts allows to run without the install target.
# Use '--write-blend=/tmp/test.blend' to view output
@@ -39,83 +39,132 @@ execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${TEST_OUT_DIR})
# all calls to blender use this
if(APPLE)
if(${CMAKE_GENERATOR} MATCHES "Xcode")
- set(TEST_BLENDER_EXE ${EXECUTABLE_OUTPUT_PATH}/Debug/blender.app/Contents/MacOS/blender)
+ set(TEST_BLENDER_EXE_PARAMS --background -noaudio --factory-startup)
else()
- set(TEST_BLENDER_EXE ${EXECUTABLE_OUTPUT_PATH}/blender.app/Contents/MacOS/blender)
+ set(TEST_BLENDER_EXE_PARAMS --background -noaudio --factory-startup --env-system-scripts ${CMAKE_SOURCE_DIR}/release/scripts)
endif()
else()
- set(TEST_BLENDER_EXE ${EXECUTABLE_OUTPUT_PATH}/blender)
+ set(TEST_BLENDER_EXE_PARAMS --background -noaudio --factory-startup --env-system-scripts ${CMAKE_SOURCE_DIR}/release/scripts)
endif()
-# for testing with valgrind prefix: valgrind --track-origins=yes --error-limit=no
-set(TEST_BLENDER_EXE_BARE ${TEST_BLENDER_EXE})
-set(TEST_BLENDER_EXE ${TEST_BLENDER_EXE} --background -noaudio --factory-startup --env-system-scripts ${CMAKE_SOURCE_DIR}/release/scripts)
+# for testing with valgrind prefix: valgrind --track-origins=yes --error-limit=no
+# set(TEST_BLENDER_EXE_BARE ${TEST_BLENDER_EXE})
+# set(TEST_BLENDER_EXE ${TEST_BLENDER_EXE} ${TEST_BLENDER_EXE_PARAMS} )
# ------------------------------------------------------------------------------
# GENERAL PYTHON CORRECTNESS TESTS
-add_test(script_load_keymap ${TEST_BLENDER_EXE}
+add_test(
+ NAME script_load_keymap
+ COMMAND "$<TARGET_FILE:blender>" ${TEST_BLENDER_EXE_PARAMS}
--python ${CMAKE_CURRENT_LIST_DIR}/bl_keymap_completeness.py
)
-add_test(script_load_addons ${TEST_BLENDER_EXE}
+add_test(
+ NAME script_load_addons
+ COMMAND "$<TARGET_FILE:blender>" ${TEST_BLENDER_EXE_PARAMS}
--python ${CMAKE_CURRENT_LIST_DIR}/bl_load_addons.py
)
-add_test(script_load_modules ${TEST_BLENDER_EXE}
+add_test(
+ NAME script_load_modules
+ COMMAND "$<TARGET_FILE:blender>" ${TEST_BLENDER_EXE_PARAMS}
--python ${CMAKE_CURRENT_LIST_DIR}/bl_load_py_modules.py
)
# test running operators doesn't segfault under various conditions
if(USE_EXPERIMENTAL_TESTS)
- add_test(script_run_operators ${TEST_BLENDER_EXE}
+ add_test(
+ NAME script_run_operators
+ COMMAND "$<TARGET_FILE:blender>" ${TEST_BLENDER_EXE_PARAMS}
--python ${CMAKE_CURRENT_LIST_DIR}/bl_run_operators.py
)
endif()
# ------------------------------------------------------------------------------
# PY API TESTS
-add_test(script_pyapi_bpy_path ${TEST_BLENDER_EXE}
+add_test(
+ NAME script_pyapi_bpy_path
+ COMMAND "$<TARGET_FILE:blender>" ${TEST_BLENDER_EXE_PARAMS}
--python ${CMAKE_CURRENT_LIST_DIR}/bl_pyapi_bpy_path.py
)
-add_test(script_pyapi_bpy_utils_units ${TEST_BLENDER_EXE}
+add_test(
+ NAME script_pyapi_bpy_utils_units
+ COMMAND "$<TARGET_FILE:blender>" ${TEST_BLENDER_EXE_PARAMS}
--python ${CMAKE_CURRENT_LIST_DIR}/bl_pyapi_bpy_utils_units.py
)
-# test running mathutils testing script
-add_test(script_pyapi_mathutils ${TEST_BLENDER_EXE}
+add_test(
+ NAME script_pyapi_mathutils
+ COMMAND "$<TARGET_FILE:blender>" ${TEST_BLENDER_EXE_PARAMS}
--python ${CMAKE_CURRENT_LIST_DIR}/bl_pyapi_mathutils.py
)
+add_test(
+ NAME script_pyapi_idprop
+ COMMAND "$<TARGET_FILE:blender>" ${TEST_BLENDER_EXE_PARAMS}
+ --python ${CMAKE_CURRENT_LIST_DIR}/bl_pyapi_idprop.py
+)
+
+add_test(
+ NAME script_pyapi_idprop_datablock
+ COMMAND "$<TARGET_FILE:blender>" ${TEST_BLENDER_EXE_PARAMS}
+ --python ${CMAKE_CURRENT_LIST_DIR}/bl_pyapi_idprop_datablock.py
+)
+
# ------------------------------------------------------------------------------
# MODELING TESTS
-add_test(bevel ${TEST_BLENDER_EXE}
+add_test(
+ NAME bevel
+ COMMAND "$<TARGET_FILE:blender>" ${TEST_BLENDER_EXE_PARAMS}
${TEST_SRC_DIR}/modeling/bevel_regression.blend
--python-text run_tests
)
+add_test(
+ NAME split_faces
+ COMMAND "$<TARGET_FILE:blender>" ${TEST_BLENDER_EXE_PARAMS}
+ ${TEST_SRC_DIR}/modeling/split_faces_test.blend
+ --python-text run_tests
+)
+
+# ------------------------------------------------------------------------------
+# MODIFIERS TESTS
+add_test(
+ NAME modifier_array
+ COMMAND "$<TARGET_FILE:blender>" ${TEST_BLENDER_EXE_PARAMS}
+ ${TEST_SRC_DIR}/modifier_stack/array_test.blend
+ --python-text run_tests
+)
+
# ------------------------------------------------------------------------------
# IO TESTS
# OBJ Import tests
# disabled until updated & working
if(FALSE)
-add_test(import_obj_cube ${TEST_BLENDER_EXE}
+add_test(
+ NAME import_obj_cube
+ COMMAND "$<TARGET_FILE:blender>" ${TEST_BLENDER_EXE_PARAMS}
--python ${CMAKE_CURRENT_LIST_DIR}/bl_test.py --
--run={'FINISHED'}&bpy.ops.import_scene.obj\(filepath='${TEST_SRC_DIR}/io_tests/obj/cube.obj'\)
--md5=39cce4bacac2d1b18fc470380279bc15 --md5_method=SCENE
--write-blend=${TEST_OUT_DIR}/import_obj_cube.blend
)
-add_test(import_obj_nurbs_cyclic ${TEST_BLENDER_EXE}
+add_test(
+ NAME import_obj_nurbs_cyclic
+ COMMAND "$<TARGET_FILE:blender>" ${TEST_BLENDER_EXE_PARAMS}
--python ${CMAKE_CURRENT_LIST_DIR}/bl_test.py --
--run={'FINISHED'}&bpy.ops.import_scene.obj\(filepath='${TEST_SRC_DIR}/io_tests/obj/nurbs_cyclic.obj'\)
--md5=ad3c307e5883224a0492378cd32691ab --md5_method=SCENE
--write-blend=${TEST_OUT_DIR}/import_obj_nurbs_cyclic.blend
)
-add_test(import_obj_makehuman ${TEST_BLENDER_EXE}
+add_test(
+ NAME import_obj_makehuman
+ COMMAND "$<TARGET_FILE:blender>" ${TEST_BLENDER_EXE_PARAMS}
--python ${CMAKE_CURRENT_LIST_DIR}/bl_test.py --
--run={'FINISHED'}&bpy.ops.import_scene.obj\(filepath='${TEST_SRC_DIR}/io_tests/obj/makehuman.obj'\)
--md5=c9f78b185e58358daa4ecaecfa75464e --md5_method=SCENE
@@ -124,7 +173,9 @@ add_test(import_obj_makehuman ${TEST_BLENDER_EXE}
endif()
# OBJ Export tests
-add_test(export_obj_cube ${TEST_BLENDER_EXE}
+add_test(
+ NAME export_obj_cube
+ COMMAND "$<TARGET_FILE:blender>" ${TEST_BLENDER_EXE_PARAMS}
${TEST_SRC_DIR}/io_tests/blend_geometry/all_quads.blend
--python ${CMAKE_CURRENT_LIST_DIR}/bl_test.py --
--run={'FINISHED'}&bpy.ops.export_scene.obj\(filepath='${TEST_OUT_DIR}/export_obj_cube.obj',use_selection=False\)
@@ -133,7 +184,9 @@ add_test(export_obj_cube ${TEST_BLENDER_EXE}
--md5=e80660437ad9bfe082849641c361a233 --md5_method=FILE
)
-add_test(export_obj_nurbs ${TEST_BLENDER_EXE}
+add_test(
+ NAME export_obj_nurbs
+ COMMAND "$<TARGET_FILE:blender>" ${TEST_BLENDER_EXE_PARAMS}
${TEST_SRC_DIR}/io_tests/blend_geometry/nurbs.blend
--python ${CMAKE_CURRENT_LIST_DIR}/bl_test.py --
--run={'FINISHED'}&bpy.ops.export_scene.obj\(filepath='${TEST_OUT_DIR}/export_obj_nurbs.obj',use_selection=False,use_nurbs=True\)
@@ -144,7 +197,9 @@ add_test(export_obj_nurbs ${TEST_BLENDER_EXE}
# disabled until updated & working
if(FALSE)
-add_test(export_obj_all_objects ${TEST_BLENDER_EXE}
+add_test(
+ NAME export_obj_all_objects
+ COMMAND "$<TARGET_FILE:blender>" ${TEST_BLENDER_EXE_PARAMS}
${TEST_SRC_DIR}/io_tests/blend_scene/all_objects.blend
--python ${CMAKE_CURRENT_LIST_DIR}/bl_test.py --
--run={'FINISHED'}&bpy.ops.export_scene.obj\(filepath='${TEST_OUT_DIR}/export_obj_all_objects.obj',use_selection=False,use_nurbs=True\)
@@ -157,21 +212,27 @@ endif()
# PLY Import tests
-add_test(import_ply_cube ${TEST_BLENDER_EXE}
+add_test(
+ NAME import_ply_cube
+ COMMAND "$<TARGET_FILE:blender>" ${TEST_BLENDER_EXE_PARAMS}
--python ${CMAKE_CURRENT_LIST_DIR}/bl_test.py --
--run={'FINISHED'}&bpy.ops.import_mesh.ply\(filepath='${TEST_SRC_DIR}/io_tests/ply/cube_ascii.ply'\)
--md5=527134343c27fc0ea73115b85fbfd3ac --md5_method=SCENE
--write-blend=${TEST_OUT_DIR}/import_ply_cube.blend
)
-add_test(import_ply_bunny ${TEST_BLENDER_EXE}
+add_test(
+ NAME import_ply_bunny
+ COMMAND "$<TARGET_FILE:blender>" ${TEST_BLENDER_EXE_PARAMS}
--python ${CMAKE_CURRENT_LIST_DIR}/bl_test.py --
--run={'FINISHED'}&bpy.ops.import_mesh.ply\(filepath='${TEST_SRC_DIR}/io_tests/ply/bunny2.ply'\)
--md5=6ea5b8533400a17accf928b8fd024eaa --md5_method=SCENE
--write-blend=${TEST_OUT_DIR}/import_ply_bunny.blend
)
-add_test(import_ply_small_holes ${TEST_BLENDER_EXE}
+add_test(
+ NAME import_ply_small_holes
+ COMMAND "$<TARGET_FILE:blender>" ${TEST_BLENDER_EXE_PARAMS}
--python ${CMAKE_CURRENT_LIST_DIR}/bl_test.py --
--run={'FINISHED'}&bpy.ops.import_mesh.ply\(filepath='${TEST_SRC_DIR}/io_tests/ply/many_small_holes.ply'\)
--md5=c3093e26ecae5b6d59fbbcf2a0d0b39f --md5_method=SCENE
@@ -181,7 +242,9 @@ add_test(import_ply_small_holes ${TEST_BLENDER_EXE}
# PLY Export
# disabled until updated & working
if(FALSE)
-add_test(export_ply_cube_all_data ${TEST_BLENDER_EXE}
+add_test(
+ NAME export_ply_cube_all_data
+ COMMAND "$<TARGET_FILE:blender>" ${TEST_BLENDER_EXE_PARAMS}
${TEST_SRC_DIR}/io_tests/blend_geometry/cube_all_data.blend
--python ${CMAKE_CURRENT_LIST_DIR}/bl_test.py --
--run={'FINISHED'}&bpy.ops.export_mesh.ply\(filepath='${TEST_OUT_DIR}/export_ply_cube_all_data.ply'\)
@@ -189,7 +252,9 @@ add_test(export_ply_cube_all_data ${TEST_BLENDER_EXE}
--md5=6adc3748ceae8298496f99d0e7e76c15 --md5_method=FILE
)
-add_test(export_ply_suzanne_all_data ${TEST_BLENDER_EXE}
+add_test(
+ NAME export_ply_suzanne_all_data
+ COMMAND "$<TARGET_FILE:blender>" ${TEST_BLENDER_EXE_PARAMS}
${TEST_SRC_DIR}/io_tests/blend_geometry/suzanne_all_data.blend
--python ${CMAKE_CURRENT_LIST_DIR}/bl_test.py --
--run={'FINISHED'}&bpy.ops.export_mesh.ply\(filepath='${TEST_OUT_DIR}/export_ply_suzanne_all_data.ply'\)
@@ -198,7 +263,9 @@ add_test(export_ply_suzanne_all_data ${TEST_BLENDER_EXE}
)
endif()
-add_test(export_ply_vertices ${TEST_BLENDER_EXE} # lame, add a better one
+add_test(
+ NAME export_ply_vertices # lame, add a better one
+ COMMAND "$<TARGET_FILE:blender>" ${TEST_BLENDER_EXE_PARAMS}
${TEST_SRC_DIR}/io_tests/blend_geometry/vertices.blend
--python ${CMAKE_CURRENT_LIST_DIR}/bl_test.py --
--run={'FINISHED'}&bpy.ops.export_mesh.ply\(filepath='${TEST_OUT_DIR}/export_ply_vertices.ply'\)
@@ -210,21 +277,27 @@ add_test(export_ply_vertices ${TEST_BLENDER_EXE} # lame, add a better one
# STL Import tests
# disabled until updated & working
if(FALSE)
-add_test(import_stl_cube ${TEST_BLENDER_EXE}
+add_test(
+ NAME import_stl_cube
+ COMMAND "$<TARGET_FILE:blender>" ${TEST_BLENDER_EXE_PARAMS}
--python ${CMAKE_CURRENT_LIST_DIR}/bl_test.py --
--run={'FINISHED'}&bpy.ops.import_mesh.stl\(filepath='${TEST_SRC_DIR}/io_tests/stl/cube.stl'\)
--md5=8ceb5bb7e1cb5f4342fa1669988c66b4 --md5_method=SCENE
--write-blend=${TEST_OUT_DIR}/import_stl_cube.blend
)
-add_test(import_stl_conrod ${TEST_BLENDER_EXE}
+add_test(
+ NAME import_stl_conrod
+ COMMAND "$<TARGET_FILE:blender>" ${TEST_BLENDER_EXE_PARAMS}
--python ${CMAKE_CURRENT_LIST_DIR}/bl_test.py --
--run={'FINISHED'}&bpy.ops.import_mesh.stl\(filepath='${TEST_SRC_DIR}/io_tests/stl/conrod.stl'\)
--md5=690a4b8eb9002dcd8631c5a575ea7348 --md5_method=SCENE
--write-blend=${TEST_OUT_DIR}/import_stl_conrod.blend
)
-add_test(import_stl_knot_max_simplified ${TEST_BLENDER_EXE}
+add_test(
+ NAME import_stl_knot_max_simplified
+ COMMAND "$<TARGET_FILE:blender>" ${TEST_BLENDER_EXE_PARAMS}
--python ${CMAKE_CURRENT_LIST_DIR}/bl_test.py --
--run={'FINISHED'}&bpy.ops.import_mesh.stl\(filepath='${TEST_SRC_DIR}/io_tests/stl/knot_max_simplified.stl'\)
--md5=baf82803f45a84ec4ddbad9cef57dd3e --md5_method=SCENE
@@ -235,7 +308,9 @@ endif()
# STL Export
# disabled until updated & working
if(FALSE)
-add_test(export_stl_cube_all_data ${TEST_BLENDER_EXE}
+add_test(
+ NAME export_stl_cube_all_data
+ COMMAND "$<TARGET_FILE:blender>" ${TEST_BLENDER_EXE_PARAMS}
${TEST_SRC_DIR}/io_tests/blend_geometry/cube_all_data.blend
--python ${CMAKE_CURRENT_LIST_DIR}/bl_test.py --
--run={'FINISHED'}&bpy.ops.export_mesh.stl\(filepath='${TEST_OUT_DIR}/export_stl_cube_all_data.stl'\)
@@ -243,7 +318,9 @@ add_test(export_stl_cube_all_data ${TEST_BLENDER_EXE}
--md5=64cb97c0cabb015e1c3f76369835075a --md5_method=FILE
)
-add_test(export_stl_suzanne_all_data ${TEST_BLENDER_EXE}
+add_test(
+ NAME export_stl_suzanne_all_data
+ COMMAND "$<TARGET_FILE:blender>" ${TEST_BLENDER_EXE_PARAMS}
${TEST_SRC_DIR}/io_tests/blend_geometry/suzanne_all_data.blend
--python ${CMAKE_CURRENT_LIST_DIR}/bl_test.py --
--run={'FINISHED'}&bpy.ops.export_mesh.stl\(filepath='${TEST_OUT_DIR}/export_stl_suzanne_all_data.stl'\)
@@ -251,7 +328,9 @@ add_test(export_stl_suzanne_all_data ${TEST_BLENDER_EXE}
--md5=e9b23c97c139ad64961c635105bb9192 --md5_method=FILE
)
-add_test(export_stl_vertices ${TEST_BLENDER_EXE} # lame, add a better one
+add_test(
+ NAME export_stl_vertices # lame, add a better one
+ COMMAND "$<TARGET_FILE:blender>" ${TEST_BLENDER_EXE_PARAMS}
${TEST_SRC_DIR}/io_tests/blend_geometry/vertices.blend
--python ${CMAKE_CURRENT_LIST_DIR}/bl_test.py --
--run={'FINISHED'}&bpy.ops.export_mesh.stl\(filepath='${TEST_OUT_DIR}/export_stl_vertices.stl'\)
@@ -264,21 +343,27 @@ endif()
# X3D Import
# disabled until updated & working
if(FALSE)
-add_test(import_x3d_cube ${TEST_BLENDER_EXE}
+add_test(
+ NAME import_x3d_cube
+ COMMAND "$<TARGET_FILE:blender>" ${TEST_BLENDER_EXE_PARAMS}
--python ${CMAKE_CURRENT_LIST_DIR}/bl_test.py --
--run={'FINISHED'}&bpy.ops.import_scene.x3d\(filepath='${TEST_SRC_DIR}/io_tests/x3d/color_cube.x3d'\)
--md5=3fae9be004199c145941cd3f9f80ad7b --md5_method=SCENE
--write-blend=${TEST_OUT_DIR}/import_x3d_cube.blend
)
-add_test(import_x3d_teapot ${TEST_BLENDER_EXE}
+add_test(
+ NAME import_x3d_teapot
+ COMMAND "$<TARGET_FILE:blender>" ${TEST_BLENDER_EXE_PARAMS}
--python ${CMAKE_CURRENT_LIST_DIR}/bl_test.py --
--run={'FINISHED'}&bpy.ops.import_scene.x3d\(filepath='${TEST_SRC_DIR}/io_tests/x3d/teapot.x3d'\)
--md5=8ee196c71947dce4199d55698501691e --md5_method=SCENE
--write-blend=${TEST_OUT_DIR}/import_x3d_teapot.blend
)
-add_test(import_x3d_suzanne_material ${TEST_BLENDER_EXE}
+add_test(
+ NAME import_x3d_suzanne_material
+ COMMAND "$<TARGET_FILE:blender>" ${TEST_BLENDER_EXE_PARAMS}
--python ${CMAKE_CURRENT_LIST_DIR}/bl_test.py --
--run={'FINISHED'}&bpy.ops.import_scene.x3d\(filepath='${TEST_SRC_DIR}/io_tests/x3d/suzanne_material.x3d'\)
--md5=3edea1353257d8b5a5f071942f417be6 --md5_method=SCENE
@@ -286,7 +371,9 @@ add_test(import_x3d_suzanne_material ${TEST_BLENDER_EXE}
)
# X3D Export
-add_test(export_x3d_cube ${TEST_BLENDER_EXE}
+add_test(
+ NAME export_x3d_cube
+ COMMAND "$<TARGET_FILE:blender>" ${TEST_BLENDER_EXE_PARAMS}
${TEST_SRC_DIR}/io_tests/blend_geometry/all_quads.blend
--python ${CMAKE_CURRENT_LIST_DIR}/bl_test.py --
--run={'FINISHED'}&bpy.ops.export_scene.x3d\(filepath='${TEST_OUT_DIR}/export_x3d_cube.x3d',use_selection=False\)
@@ -294,7 +381,9 @@ add_test(export_x3d_cube ${TEST_BLENDER_EXE}
--md5=05312d278fe41da33560fdfb9bdb268f --md5_method=FILE
)
-add_test(export_x3d_nurbs ${TEST_BLENDER_EXE}
+add_test(
+ NAME export_x3d_nurbs
+ COMMAND "$<TARGET_FILE:blender>" ${TEST_BLENDER_EXE_PARAMS}
${TEST_SRC_DIR}/io_tests/blend_geometry/nurbs.blend
--python ${CMAKE_CURRENT_LIST_DIR}/bl_test.py --
--run={'FINISHED'}&bpy.ops.export_scene.x3d\(filepath='${TEST_OUT_DIR}/export_x3d_nurbs.x3d',use_selection=False\)
@@ -302,7 +391,9 @@ add_test(export_x3d_nurbs ${TEST_BLENDER_EXE}
--md5=4286d4a2aa507ef78b22ddcbdcc88481 --md5_method=FILE
)
-add_test(export_x3d_all_objects ${TEST_BLENDER_EXE}
+add_test(
+ NAME export_x3d_all_objects
+ COMMAND "$<TARGET_FILE:blender>" ${TEST_BLENDER_EXE_PARAMS}
${TEST_SRC_DIR}/io_tests/blend_scene/all_objects.blend
--python ${CMAKE_CURRENT_LIST_DIR}/bl_test.py --
--run={'FINISHED'}&bpy.ops.export_scene.x3d\(filepath='${TEST_OUT_DIR}/export_x3d_all_objects.x3d',use_selection=False\)
@@ -316,21 +407,27 @@ endif()
# 3DS Import
# disabled until updated & working
if(FALSE)
-add_test(import_3ds_cube ${TEST_BLENDER_EXE}
+add_test(
+ NAME import_3ds_cube
+ COMMAND "$<TARGET_FILE:blender>" ${TEST_BLENDER_EXE_PARAMS}
--python ${CMAKE_CURRENT_LIST_DIR}/bl_test.py --
--run={'FINISHED'}&bpy.ops.import_scene.autodesk_3ds\(filepath='${TEST_SRC_DIR}/io_tests/3ds/cube.3ds'\)
--md5=cb5a45c35a343c3f5beca2a918472951 --md5_method=SCENE
--write-blend=${TEST_OUT_DIR}/import_3ds_cube.blend
)
-add_test(import_3ds_hierarchy_lara ${TEST_BLENDER_EXE}
+add_test(
+ NAME import_3ds_hierarchy_lara
+ COMMAND "$<TARGET_FILE:blender>" ${TEST_BLENDER_EXE_PARAMS}
--python ${CMAKE_CURRENT_LIST_DIR}/bl_test.py --
--run={'FINISHED'}&bpy.ops.import_scene.autodesk_3ds\(filepath='${TEST_SRC_DIR}/io_tests/3ds/hierarchy_lara.3ds'\)
--md5=766c873d9fdb5f190e43796cfbae63b6 --md5_method=SCENE
--write-blend=${TEST_OUT_DIR}/import_3ds_hierarchy_lara.blend
)
-add_test(import_3ds_hierarchy_greek_trireme ${TEST_BLENDER_EXE}
+add_test(
+ NAME import_3ds_hierarchy_greek_trireme
+ COMMAND "$<TARGET_FILE:blender>" ${TEST_BLENDER_EXE_PARAMS}
--python ${CMAKE_CURRENT_LIST_DIR}/bl_test.py --
--run={'FINISHED'}&bpy.ops.import_scene.autodesk_3ds\(filepath='${TEST_SRC_DIR}/io_tests/3ds/hierarchy_greek_trireme.3ds'\)
--md5=b62ee30101e8999cb91ef4f8a8760056 --md5_method=SCENE
@@ -341,7 +438,9 @@ endif()
# 3DS Export
# disabled until updated & working
if(FALSE)
-add_test(export_3ds_cube ${TEST_BLENDER_EXE}
+add_test(
+ NAME export_3ds_cube
+ COMMAND "$<TARGET_FILE:blender>" ${TEST_BLENDER_EXE_PARAMS}
${TEST_SRC_DIR}/io_tests/blend_geometry/all_quads.blend
--python ${CMAKE_CURRENT_LIST_DIR}/bl_test.py --
--run={'FINISHED'}&bpy.ops.export_scene.autodesk_3ds\(filepath='${TEST_OUT_DIR}/export_3ds_cube.3ds',use_selection=False\)
@@ -349,7 +448,9 @@ add_test(export_3ds_cube ${TEST_BLENDER_EXE}
--md5=a31f5071b6c6dc7445b9099cdc7f63b3 --md5_method=FILE
)
-add_test(export_3ds_nurbs ${TEST_BLENDER_EXE}
+add_test(
+ NAME export_3ds_nurbs
+ COMMAND "$<TARGET_FILE:blender>" ${TEST_BLENDER_EXE_PARAMS}
${TEST_SRC_DIR}/io_tests/blend_geometry/nurbs.blend
--python ${CMAKE_CURRENT_LIST_DIR}/bl_test.py --
--run={'FINISHED'}&bpy.ops.export_scene.autodesk_3ds\(filepath='${TEST_OUT_DIR}/export_3ds_nurbs.3ds',use_selection=False\)
@@ -357,7 +458,9 @@ add_test(export_3ds_nurbs ${TEST_BLENDER_EXE}
--md5=5bdd21be3c80d814fbc83cb25edb08c2 --md5_method=FILE
)
-add_test(export_3ds_all_objects ${TEST_BLENDER_EXE}
+add_test(
+ NAME export_3ds_all_objects
+ COMMAND "$<TARGET_FILE:blender>" ${TEST_BLENDER_EXE_PARAMS}
${TEST_SRC_DIR}/io_tests/blend_scene/all_objects.blend
--python ${CMAKE_CURRENT_LIST_DIR}/bl_test.py --
--run={'FINISHED'}&bpy.ops.export_scene.autodesk_3ds\(filepath='${TEST_OUT_DIR}/export_3ds_all_objects.3ds',use_selection=False\)
@@ -372,7 +475,9 @@ endif()
# 'use_metadata=False' for reliable md5's
# disabled until updated & working
if(FALSE)
-add_test(export_fbx_cube ${TEST_BLENDER_EXE}
+add_test(
+ NAME export_fbx_cube
+ COMMAND "$<TARGET_FILE:blender>" ${TEST_BLENDER_EXE_PARAMS}
${TEST_SRC_DIR}/io_tests/blend_geometry/all_quads.blend
--python ${CMAKE_CURRENT_LIST_DIR}/bl_test.py --
--run={'FINISHED'}&bpy.ops.export_scene.fbx\(filepath='${TEST_OUT_DIR}/export_fbx_cube.fbx',use_selection=False,use_metadata=False\)
@@ -380,7 +485,9 @@ add_test(export_fbx_cube ${TEST_BLENDER_EXE}
--md5=59a35577462f95f9a0b4e6035226ce9b --md5_method=FILE
)
-add_test(export_fbx_nurbs ${TEST_BLENDER_EXE}
+add_test(
+ NAME export_fbx_nurbs
+ COMMAND "$<TARGET_FILE:blender>" ${TEST_BLENDER_EXE_PARAMS}
${TEST_SRC_DIR}/io_tests/blend_geometry/nurbs.blend
--python ${CMAKE_CURRENT_LIST_DIR}/bl_test.py --
--run={'FINISHED'}&bpy.ops.export_scene.fbx\(filepath='${TEST_OUT_DIR}/export_fbx_nurbs.fbx',use_selection=False,use_metadata=False\)
@@ -388,7 +495,9 @@ add_test(export_fbx_nurbs ${TEST_BLENDER_EXE}
--md5=d31875f18f613fa0c3b16e978f87f6f8 --md5_method=FILE
)
-add_test(export_fbx_all_objects ${TEST_BLENDER_EXE}
+add_test(
+ NAME export_fbx_all_objects
+ COMMAND "$<TARGET_FILE:blender>" ${TEST_BLENDER_EXE_PARAMS}
${TEST_SRC_DIR}/io_tests/blend_scene/all_objects.blend
--python ${CMAKE_CURRENT_LIST_DIR}/bl_test.py --
--run={'FINISHED'}&bpy.ops.export_scene.fbx\(filepath='${TEST_OUT_DIR}/export_fbx_all_objects.fbx',use_selection=False,use_metadata=False\)
@@ -399,25 +508,86 @@ endif()
if(WITH_CYCLES)
if(OPENIMAGEIO_IDIFF AND EXISTS "${TEST_SRC_DIR}/cycles/ctests/shader")
- add_test(cycles_reports_test
- ${CMAKE_CURRENT_LIST_DIR}/cycles_render_tests.py
- -blender "${TEST_BLENDER_EXE_BARE}"
- -testdir "${TEST_SRC_DIR}/cycles/ctests/reports"
- -idiff "${OPENIMAGEIO_IDIFF}"
- )
- add_test(cycles_render_test
- ${CMAKE_CURRENT_LIST_DIR}/cycles_render_tests.py
- -blender "${TEST_BLENDER_EXE_BARE}"
- -testdir "${TEST_SRC_DIR}/cycles/ctests/render"
- -idiff "${OPENIMAGEIO_IDIFF}"
- )
- add_test(cycles_shaders_test
- ${CMAKE_CURRENT_LIST_DIR}/cycles_render_tests.py
- -blender "${TEST_BLENDER_EXE_BARE}"
- -testdir "${TEST_SRC_DIR}/cycles/ctests/shader"
- -idiff "${OPENIMAGEIO_IDIFF}"
- )
+ macro(add_cycles_render_test subject)
+ if(MSVC)
+ add_test(
+ NAME cycles_${subject}_test
+ COMMAND
+ "$<TARGET_FILE_DIR:blender>/${BLENDER_VERSION_MAJOR}.${BLENDER_VERSION_MINOR}/python/bin/python$<$<CONFIG:Debug>:_d>"
+ ${CMAKE_CURRENT_LIST_DIR}/cycles_render_tests.py
+ -blender "$<TARGET_FILE:blender>"
+ -testdir "${TEST_SRC_DIR}/cycles/ctests/${subject}"
+ -idiff "${OPENIMAGEIO_IDIFF}"
+ -outdir "${TEST_OUT_DIR}/cycles"
+ )
+ else()
+ add_test(
+ NAME cycles_${subject}_test
+ COMMAND ${CMAKE_CURRENT_LIST_DIR}/cycles_render_tests.py
+ -blender "$<TARGET_FILE:blender>"
+ -testdir "${TEST_SRC_DIR}/cycles/ctests/${subject}"
+ -idiff "${OPENIMAGEIO_IDIFF}"
+ -outdir "${TEST_OUT_DIR}/cycles"
+ )
+ endif()
+ endmacro()
+ if(WITH_OPENGL_TESTS)
+ add_cycles_render_test(opengl)
+ endif()
+ add_cycles_render_test(bake)
+ add_cycles_render_test(denoise)
+ add_cycles_render_test(displacement)
+ add_cycles_render_test(image_data_types)
+ add_cycles_render_test(image_mapping)
+ add_cycles_render_test(image_texture_limit)
+ add_cycles_render_test(light)
+ add_cycles_render_test(mblur)
+ add_cycles_render_test(reports)
+ add_cycles_render_test(render)
+ add_cycles_render_test(shader)
+ add_cycles_render_test(shader_tangent)
+ add_cycles_render_test(shadow_catcher)
+ add_cycles_render_test(volume)
else()
MESSAGE(STATUS "Disabling Cycles tests because tests folder does not exist")
endif()
endif()
+
+if(WITH_ALEMBIC)
+ find_package_wrapper(Alembic)
+ if(NOT ALEMBIC_FOUND)
+ message(FATAL_ERROR "Alembic is enabled but cannot be found")
+ endif()
+ get_filename_component(real_include_dir ${ALEMBIC_INCLUDE_DIR} REALPATH)
+ get_filename_component(ALEMBIC_ROOT_DIR ${real_include_dir} DIRECTORY)
+
+ if(MSVC)
+ # FIXME, de-duplicate.
+ add_test(
+ NAME alembic_tests
+ COMMAND
+ "$<TARGET_FILE_DIR:blender>/${BLENDER_VERSION_MAJOR}.${BLENDER_VERSION_MINOR}/python/bin/python$<$<CONFIG:Debug>:_d>"
+ ${CMAKE_CURRENT_LIST_DIR}/alembic_tests.py
+ --blender "$<TARGET_FILE:blender>"
+ --testdir "${TEST_SRC_DIR}/alembic"
+ --alembic-root "${ALEMBIC_ROOT_DIR}"
+ )
+ else()
+ add_test(
+ NAME alembic_tests
+ COMMAND ${CMAKE_CURRENT_LIST_DIR}/alembic_tests.py
+ --blender "$<TARGET_FILE:blender>"
+ --testdir "${TEST_SRC_DIR}/alembic"
+ --alembic-root "${ALEMBIC_ROOT_DIR}"
+ )
+ endif()
+
+ add_test(
+ NAME script_alembic_import
+ COMMAND "$<TARGET_FILE:blender>" ${TEST_BLENDER_EXE_PARAMS}
+ --python ${CMAKE_CURRENT_LIST_DIR}/bl_alembic_import_test.py
+ --
+ --testdir "${TEST_SRC_DIR}/alembic"
+ --with-legacy-depsgraph=${WITH_LEGACY_DEPSGRAPH}
+ )
+endif()
diff --git a/tests/python/alembic_tests.py b/tests/python/alembic_tests.py
new file mode 100755
index 00000000000..96a68de9801
--- /dev/null
+++ b/tests/python/alembic_tests.py
@@ -0,0 +1,478 @@
+#!/usr/bin/env python3
+# ##### BEGIN GPL LICENSE BLOCK #####
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# ##### END GPL LICENSE BLOCK #####
+
+# <pep8 compliant>
+
+import argparse
+import functools
+import shutil
+import pathlib
+import subprocess
+import sys
+import tempfile
+import unittest
+
+
+def with_tempdir(wrapped):
+ """Creates a temporary directory for the function, cleaning up after it returns normally.
+
+ When the wrapped function raises an exception, the contents of the temporary directory
+ remain available for manual inspection.
+
+ The wrapped function is called with an extra positional argument containing
+ the pathlib.Path() of the temporary directory.
+ """
+
+ @functools.wraps(wrapped)
+ def decorator(*args, **kwargs):
+ dirname = tempfile.mkdtemp(prefix='blender-alembic-test')
+ try:
+ retval = wrapped(*args, pathlib.Path(dirname), **kwargs)
+ except:
+ print('Exception in %s, not cleaning up temporary directory %s' % (wrapped, dirname))
+ raise
+ else:
+ shutil.rmtree(dirname)
+ return retval
+
+ return decorator
+
+
+class AbcPropError(Exception):
+ """Raised when AbstractAlembicTest.abcprop() finds an error."""
+
+
+class AbstractAlembicTest(unittest.TestCase):
+ @classmethod
+ def setUpClass(cls):
+ import re
+
+ cls.blender = args.blender
+ cls.testdir = pathlib.Path(args.testdir)
+ cls.alembic_root = pathlib.Path(args.alembic_root)
+
+ # 'abcls' outputs ANSI colour codes, even when stdout is not a terminal.
+ # See https://github.com/alembic/alembic/issues/120
+ cls.ansi_remove_re = re.compile(rb'\x1b[^m]*m')
+
+ # 'abcls' array notation, like "name[16]"
+ cls.abcls_array = re.compile(r'^(?P<name>[^\[]+)(\[(?P<arraysize>\d+)\])?$')
+
+ def run_blender(self, filepath: str, python_script: str, timeout: int=300) -> str:
+ """Runs Blender by opening a blendfile and executing a script.
+
+ Returns Blender's stdout + stderr combined into one string.
+
+ :param filepath: taken relative to self.testdir.
+ :param timeout: in seconds
+ """
+
+ blendfile = self.testdir / filepath
+
+ command = (
+ self.blender,
+ '--background',
+ '-noaudio',
+ '--factory-startup',
+ '--enable-autoexec',
+ str(blendfile),
+ '-E', 'CYCLES',
+ '--python-exit-code', '47',
+ '--python-expr', python_script,
+ )
+
+ proc = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
+ timeout=timeout)
+ output = proc.stdout.decode('utf8')
+ if proc.returncode:
+ self.fail('Error %d running Blender:\n%s' % (proc.returncode, output))
+
+ return output
+
+ def abcprop(self, filepath: pathlib.Path, proppath: str) -> dict:
+ """Uses abcls to obtain compound property values from an Alembic object.
+
+ A dict of subproperties is returned, where the values are Python values.
+
+ The Python bindings for Alembic are old, and only compatible with Python 2.x,
+ so that's why we can't use them here, and have to rely on other tooling.
+ """
+ import collections
+
+ abcls = self.alembic_root / 'bin' / 'abcls'
+
+ command = (str(abcls), '-vl', '%s%s' % (filepath, proppath))
+ proc = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
+ timeout=30)
+
+ coloured_output = proc.stdout
+ output = self.ansi_remove_re.sub(b'', coloured_output).decode('utf8')
+
+ # Because of the ANSI colour codes, we need to remove those first before
+ # decoding to text. This means that we cannot use the universal_newlines
+ # parameter to subprocess.run(), and have to do the conversion ourselves
+ output = output.replace('\r\n', '\n').replace('\r', '\n')
+
+ if proc.returncode:
+ raise AbcPropError('Error %d running abcls:\n%s' % (proc.returncode, output))
+
+ # Mapping from value type to callable that can convert a string to Python values.
+ converters = {
+ 'bool_t': int,
+ 'uint8_t': int,
+ 'int16_t': int,
+ 'int32_t': int,
+ 'uint64_t': int,
+ 'float64_t': float,
+ 'float32_t': float,
+ }
+
+ result = {}
+
+ # Ideally we'd get abcls to output JSON, see https://github.com/alembic/alembic/issues/121
+ lines = collections.deque(output.split('\n'))
+ while lines:
+ info = lines.popleft()
+ if not info:
+ continue
+ parts = info.split()
+ proptype = parts[0]
+
+ if proptype == 'CompoundProperty':
+ # To read those, call self.abcprop() on it.
+ continue
+ if len(parts) < 2:
+ raise ValueError('Error parsing result from abcprop: %s', info.strip())
+ valtype_and_arrsize, name_and_extent = parts[1:]
+
+ # Parse name and extent
+ m = self.abcls_array.match(name_and_extent)
+ if not m:
+ self.fail('Unparsable name/extent from abcls: %s' % name_and_extent)
+ name, extent = m.group('name'), m.group('arraysize')
+
+ if extent != '1':
+ self.fail('Unsupported extent %s for property %s/%s' % (extent, proppath, name))
+
+ # Parse type
+ m = self.abcls_array.match(valtype_and_arrsize)
+ if not m:
+ self.fail('Unparsable value type from abcls: %s' % valtype_and_arrsize)
+ valtype, scalarsize = m.group('name'), m.group('arraysize')
+
+ # Convert values
+ try:
+ conv = converters[valtype]
+ except KeyError:
+ self.fail('Unsupported type %s for property %s/%s' % (valtype, proppath, name))
+
+ def convert_single_line(linevalue):
+ try:
+ if scalarsize is None:
+ return conv(linevalue)
+ else:
+ return [conv(v.strip()) for v in linevalue.split(',')]
+ except ValueError as ex:
+ return str(ex)
+
+ if proptype == 'ScalarProperty':
+ value = lines.popleft()
+ result[name] = convert_single_line(value)
+ elif proptype == 'ArrayProperty':
+ arrayvalue = []
+ # Arrays consist of a variable number of items, and end in a blank line.
+ while True:
+ linevalue = lines.popleft()
+ if not linevalue:
+ break
+ arrayvalue.append(convert_single_line(linevalue))
+ result[name] = arrayvalue
+ else:
+ self.fail('Unsupported type %s for property %s/%s' % (proptype, proppath, name))
+
+ return result
+
+ def assertAlmostEqualFloatArray(self, actual, expect, places=6, delta=None):
+ """Asserts that the arrays of floats are almost equal."""
+
+ self.assertEqual(len(actual), len(expect),
+ 'Actual array has %d items, expected %d' % (len(actual), len(expect)))
+
+ for idx, (act, exp) in enumerate(zip(actual, expect)):
+ self.assertAlmostEqual(act, exp, places=places, delta=delta,
+ msg='%f != %f at index %d' % (act, exp, idx))
+
+
+class HierarchicalAndFlatExportTest(AbstractAlembicTest):
+ @with_tempdir
+ def test_hierarchical_export(self, tempdir: pathlib.Path):
+ abc = tempdir / 'cubes_hierarchical.abc'
+ script = "import bpy; bpy.ops.wm.alembic_export(filepath='%s', start=1, end=1, " \
+ "renderable_only=True, visible_layers_only=True, flatten=False)" % abc.as_posix()
+ self.run_blender('cubes-hierarchy.blend', script)
+
+ # Now check the resulting Alembic file.
+ xform = self.abcprop(abc, '/Cube/Cube_002/Cube_012/.xform')
+ self.assertEqual(1, xform['.inherits'])
+ self.assertAlmostEqualFloatArray(
+ xform['.vals'],
+ [1.0, 0.0, 0.0, 0.0,
+ 0.0, 1.0, 0.0, 0.0,
+ 0.0, 0.0, 1.0, 0.0,
+ 3.07484, -2.92265, 0.0586434, 1.0]
+ )
+
+ @with_tempdir
+ def test_flat_export(self, tempdir: pathlib.Path):
+ abc = tempdir / 'cubes_flat.abc'
+ script = "import bpy; bpy.ops.wm.alembic_export(filepath='%s', start=1, end=1, " \
+ "renderable_only=True, visible_layers_only=True, flatten=True)" % abc.as_posix()
+ self.run_blender('cubes-hierarchy.blend', script)
+
+ # Now check the resulting Alembic file.
+ xform = self.abcprop(abc, '/Cube_012/.xform')
+ self.assertEqual(0, xform['.inherits'])
+
+ self.assertAlmostEqualFloatArray(
+ xform['.vals'],
+ [0.343134, 0.485243, 0.804238, 0,
+ 0.0, 0.856222, -0.516608, 0,
+ -0.939287, 0.177266, 0.293799, 0,
+ 1, 3, 4, 1],
+ )
+
+
+class DupliGroupExportTest(AbstractAlembicTest):
+ @with_tempdir
+ def test_hierarchical_export(self, tempdir: pathlib.Path):
+ abc = tempdir / 'dupligroup_hierarchical.abc'
+ script = "import bpy; bpy.ops.wm.alembic_export(filepath='%s', start=1, end=1, " \
+ "renderable_only=True, visible_layers_only=True, flatten=False)" % abc.as_posix()
+ self.run_blender('dupligroup-scene.blend', script)
+
+ # Now check the resulting Alembic file.
+ xform = self.abcprop(abc, '/Real_Cube/Linked_Suzanne/Cylinder/Suzanne/.xform')
+ self.assertEqual(1, xform['.inherits'])
+ self.assertAlmostEqualFloatArray(
+ xform['.vals'],
+ [1.0, 0.0, 0.0, 0.0,
+ 0.0, 1.0, 0.0, 0.0,
+ 0.0, 0.0, 1.0, 0.0,
+ 0.0, 2.0, 0.0, 1.0]
+ )
+
+ @with_tempdir
+ def test_flat_export(self, tempdir: pathlib.Path):
+ abc = tempdir / 'dupligroup_hierarchical.abc'
+ script = "import bpy; bpy.ops.wm.alembic_export(filepath='%s', start=1, end=1, " \
+ "renderable_only=True, visible_layers_only=True, flatten=True)" % abc.as_posix()
+ self.run_blender('dupligroup-scene.blend', script)
+
+ # Now check the resulting Alembic file.
+ xform = self.abcprop(abc, '/Suzanne/.xform')
+ self.assertEqual(0, xform['.inherits'])
+
+ self.assertAlmostEqualFloatArray(
+ xform['.vals'],
+ [1.5, 0.0, 0.0, 0.0,
+ 0.0, 1.5, 0.0, 0.0,
+ 0.0, 0.0, 1.5, 0.0,
+ 2.0, 3.0, 0.0, 1.0]
+ )
+
+
+class CurveExportTest(AbstractAlembicTest):
+ @with_tempdir
+ def test_export_single_curve(self, tempdir: pathlib.Path):
+ abc = tempdir / 'single-curve.abc'
+ script = "import bpy; bpy.ops.wm.alembic_export(filepath='%s', start=1, end=1, " \
+ "renderable_only=True, visible_layers_only=True, flatten=False)" % abc.as_posix()
+ self.run_blender('single-curve.blend', script)
+
+ # Now check the resulting Alembic file.
+ abcprop = self.abcprop(abc, '/NurbsCurve/NurbsCurveShape/.geom')
+ self.assertEqual(abcprop['.orders'], [4])
+
+ abcprop = self.abcprop(abc, '/NurbsCurve/NurbsCurveShape/.geom/.userProperties')
+ self.assertEqual(abcprop['blender:resolution'], 10)
+
+
+class HairParticlesExportTest(AbstractAlembicTest):
+ """Tests exporting with/without hair/particles.
+
+ Just a basic test to ensure that the enabling/disabling works, and that export
+ works at all. NOT testing the quality/contents of the exported file.
+ """
+
+ def _do_test(self, tempdir: pathlib.Path, export_hair: bool, export_particles: bool) -> pathlib.Path:
+ abc = tempdir / 'hair-particles.abc'
+ script = "import bpy; bpy.ops.wm.alembic_export(filepath='%s', start=1, end=1, " \
+ "renderable_only=True, visible_layers_only=True, flatten=False, " \
+ "export_hair=%r, export_particles=%r, as_background_job=False)" \
+ % (abc.as_posix(), export_hair, export_particles)
+ self.run_blender('hair-particles.blend', script)
+ return abc
+
+ @with_tempdir
+ def test_with_both(self, tempdir: pathlib.Path):
+ abc = self._do_test(tempdir, True, True)
+
+ abcprop = self.abcprop(abc, '/Suzanne/Hair system/.geom')
+ self.assertIn('nVertices', abcprop)
+
+ abcprop = self.abcprop(abc, '/Suzanne/Non-hair particle system/.geom')
+ self.assertIn('.velocities', abcprop)
+
+ abcprop = self.abcprop(abc, '/Suzanne/SuzanneShape/.geom')
+ self.assertIn('.faceIndices', abcprop)
+
+ @with_tempdir
+ def test_with_hair_only(self, tempdir: pathlib.Path):
+ abc = self._do_test(tempdir, True, False)
+
+ abcprop = self.abcprop(abc, '/Suzanne/Hair system/.geom')
+ self.assertIn('nVertices', abcprop)
+
+ self.assertRaises(AbcPropError, self.abcprop, abc,
+ '/Suzanne/Non-hair particle system/.geom')
+
+ abcprop = self.abcprop(abc, '/Suzanne/SuzanneShape/.geom')
+ self.assertIn('.faceIndices', abcprop)
+
+ @with_tempdir
+ def test_with_particles_only(self, tempdir: pathlib.Path):
+ abc = self._do_test(tempdir, False, True)
+
+ self.assertRaises(AbcPropError, self.abcprop, abc, '/Suzanne/Hair system/.geom')
+
+ abcprop = self.abcprop(abc, '/Suzanne/Non-hair particle system/.geom')
+ self.assertIn('.velocities', abcprop)
+
+ abcprop = self.abcprop(abc, '/Suzanne/SuzanneShape/.geom')
+ self.assertIn('.faceIndices', abcprop)
+
+ @with_tempdir
+ def test_with_neither(self, tempdir: pathlib.Path):
+ abc = self._do_test(tempdir, False, False)
+
+ self.assertRaises(AbcPropError, self.abcprop, abc, '/Suzanne/Hair system/.geom')
+ self.assertRaises(AbcPropError, self.abcprop, abc,
+ '/Suzanne/Non-hair particle system/.geom')
+
+ abcprop = self.abcprop(abc, '/Suzanne/SuzanneShape/.geom')
+ self.assertIn('.faceIndices', abcprop)
+
+
+class LongNamesExportTest(AbstractAlembicTest):
+ @with_tempdir
+ def test_export_long_names(self, tempdir: pathlib.Path):
+ abc = tempdir / 'long-names.abc'
+ script = "import bpy; bpy.ops.wm.alembic_export(filepath='%s', start=1, end=1, " \
+ "renderable_only=False, visible_layers_only=False, flatten=False)" % abc.as_posix()
+ self.run_blender('long-names.blend', script)
+
+ name_parts = [
+ 'foG9aeLahgoh5goacee1dah6Hethaghohjaich5pasizairuWigee1ahPeekiGh',
+ 'yoNgoisheedah2ua0eigh2AeCaiTee5bo0uphoo7Aixephah9racahvaingeeH4',
+ 'zuthohnoi1thooS3eezoo8seuph2Boo5aefacaethuvee1aequoonoox1sookie',
+ 'wugh4ciTh3dipiepeequait5uug7thiseek5ca7Eijei5ietaizokohhaecieto',
+ 'up9aeheenein9oteiX6fohP3thiez6Ahvah0oohah1ep2Eesho4Beboechaipoh',
+ 'coh4aehiacheTh0ue0eegho9oku1lohl4loht9ohPoongoow7dasiego6yimuis',
+ 'lohtho8eigahfeipohviepajaix4it2peeQu6Iefee1nevihaes4cee2soh4noy',
+ 'kaht9ahv0ieXaiyih7ohxe8bah7eeyicahjoa2ohbu7Choxua7oongah6sei4bu',
+ 'deif0iPaechohkee5nahx6oi2uJeeN7ze3seunohJibe4shai0mah5Iesh3Quai',
+ 'ChohDahshooNee0NeNohthah0eiDeese3Vu6ohShil1Iey9ja0uebi2quiShae6',
+ 'Dee1kai7eiph2ahh2nufah3zai3eexeengohQue1caj0eeW0xeghi3eshuadoot',
+ 'aeshiup3aengajoog0AhCoo5tiu3ieghaeGhie4Tu1ohh1thee8aepheingah1E',
+ 'ooRa6ahciolohshaifoopeo9ZeiGhae2aech4raisheiWah9AaNga0uas9ahquo',
+ 'thaepheip2aip6shief4EaXopei8ohPo0ighuiXah2ashowai9nohp4uach6Mei',
+ 'ohph4yaev3quieji3phophiem3OoNuisheepahng4waithae3Naichai7aw3noo',
+ 'aibeawaneBahmieyuph8ieng8iopheereeD2uu9Uyee5bei2phahXeir8eeJ8oo',
+ 'ooshahphei2hoh3uth5chaen7ohsai6uutiesucheichai8ungah9Gie1Aiphie',
+ 'eiwohchoo7ere2iebohn4Aapheichaelooriiyaoxaik7ooqua7aezahx0aeJei',
+ 'Vah0ohgohphiefohTheshieghichaichahch5moshoo0zai5eeva7eisi4yae8T',
+ 'EibeeN0fee0Gohnguz8iec6yeigh7shuNg4eingu3siph9joucahpeidoom4ree',
+ 'iejiu3shohheeZahHusheimeefaihoh5eecachu5eeZie9ceisugu9taidohT3U',
+ 'eex6dilakaix5Eetai7xiCh5Jaa8aiD4Ag3tuij1aijohv5fo0heevah8hohs3m',
+ 'ohqueeNgahraew6uraemohtoo5qua3oojiex6ohqu6Aideibaithaiphuriquie',
+ 'cei0eiN4Shiey7Aeluy3unohboo5choiphahc2mahbei5paephaiKeso1thoog1',
+ 'ieghif4ohKequ7ong0jah5ooBah0eiGh1caechahnahThae9Shoo0phopashoo4',
+ 'roh9er3thohwi5am8iequeequuSh3aic0voocai3ihi5nie2abahphupiegh7vu',
+ 'uv3Quei7wujoo5beingei2aish5op4VaiX0aebai7iwoaPee5pei8ko9IepaPig',
+ 'co7aegh5beitheesi9lu7jeeQu3johgeiphee9cheichi8aithuDehu2gaeNein',
+ 'thai3Tiewoo4nuir1ohy4aithiuZ7shae1luuwei5phibohriepe2paeci1Ach8',
+ 'phoi3ribah7ufuvoh8eigh1oB6deeBaiPohphaghiPieshahfah5EiCi3toogoo',
+ 'aiM8geil7ooreinee4Cheiwea4yeec8eeshi7Sei4Shoo3wu6ohkaNgooQu1mai',
+ 'agoo3faciewah9ZeesiXeereek7am0eigaeShie3Tisu8haReeNgoo0ci2Hae5u',
+ 'Aesatheewiedohshaephaenohbooshee8eu7EiJ8isal1laech2eiHo0noaV3ta',
+ 'liunguep3ooChoo4eir8ahSie8eenee0oo1TooXu8Cais8Aimo4eir6Phoo3xei',
+ 'toe9heepeobein3teequachemei0Cejoomef9ujie3ohwae9AiNgiephi3ep0de',
+ 'ua6xooY9uzaeB3of6sheiyaedohoiS5Eev0Aequ9ahm1zoa5Aegh3ooz9ChahDa',
+ 'eevasah6Bu9wi7EiwiequumahkaeCheegh6lui8xoh4eeY4ieneavah8phaibun',
+ 'AhNgei2sioZeeng6phaecheemeehiShie5eFeiTh6ooV8iiphabud0die4siep4',
+ 'kushe6Xieg6ahQuoo9aex3aipheefiec1esa7OhBuG0ueziep9phai5eegh1vie',
+ 'Jie5yu8aafuQuoh9shaep3moboh3Pooy7och8oC6obeik6jaew2aiLooweib3ch',
+ 'ohohjajaivaiRail3odaimei6aekohVaicheip2wu7phieg5Gohsaing2ahxaiy',
+ 'hahzaht6yaiYu9re9jah9loisiit4ahtoh2quoh9xohishioz4oo4phofu3ogha',
+ 'pu4oorea0uh2tahB8aiZoonge1aophaes6ogaiK9ailaigeej4zoVou8ielotee',
+ 'cae2thei3Luphuqu0zeeG8leeZuchahxaicai4ui4Eedohte9uW6gae8Geeh0ea',
+ 'air7tuy7ohw5sho2Tahpai8aep4so5ria7eaShus5weaqu0Naquei2xaeyoo2ae',
+ 'vohge4aeCh7ahwoo7Jaex6sohl0Koong4Iejisei8Coir0iemeiz9uru9Iebaep',
+ 'aepeidie8aiw6waish9gie4Woolae2thuj5phae4phexux7gishaeph4Deu7ooS',
+ 'vahc5ia0xohHooViT0uyuxookiaquu2ogueth0ahquoudeefohshai8aeThahba',
+ 'mun3oagah2eequaenohfoo8DaigeghoozaV2eiveeQuee7kah0quaa6tiesheet',
+ 'ooSet4IdieC4ugow3za0die4ohGoh1oopoh6luaPhaeng4Eechea1hae0eimie5',
+ 'iedeimadaefu2NeiPaey2jooloov5iehiegeakoo4ueso7aeK9ahqu2Thahkaes',
+ 'nahquah9Quuu2uuf0aJah7eishi2siegh8ue5eiJa2EeVu8ebohkepoh4dahNgo',
+ 'io1bie7chioPiej5ae2oohe2fee6ooP2thaeJohjohb9Se8tang3eipaifeimai',
+ 'oungoqu6dieneejiechez1xeD2Zi9iox2Ahchaiy9ithah3ohVoolu2euQuuawo',
+ 'thaew0veigei4neishohd8mecaixuqu7eeshiex1chaigohmoThoghoitoTa0Eo',
+ 'ahroob2phohvaiz0Ohteik2ohtakie6Iu1vitho8IyiyeeleeShae9defaiw9ki',
+ 'DohHoothohzeaxolai3Toh5eJie7ahlah9reF0ohn1chaipoogain2aibahw4no',
+ 'aif8lo5she4aich5cho2rie8ieJaujeem2Joongeedae4vie3tah1Leequaix1O',
+ 'Aang0Shaih6chahthie1ahZ7aewei9thiethee7iuThah3yoongi8ahngiobaa5',
+ 'iephoBuayoothah0Ru6aichai4aiw8deg1umongauvaixai3ohy6oowohlee8ei',
+ 'ohn5shigoameer0aejohgoh8oChohlaecho9jie6shu0ahg9Bohngau6paevei9',
+ 'edahghaishak0paigh1eecuich3aad7yeB0ieD6akeeliem2beifufaekee6eat',
+ 'hiechahgheloh2zo7Ieghaiph0phahhu8aeyuiKie1xeipheech9zai4aeme0ee',
+ 'Cube'
+ ]
+ name = '/' + '/'.join(name_parts)
+
+ # Now check the resulting Alembic file.
+ abcprop = self.abcprop(abc, '%s/.xform' % name)
+ self.assertEqual(abcprop['.vals'], [
+ 1.0, 0.0, 0.0, 0.0,
+ 0.0, 1.0, 0.0, 0.0,
+ 0.0, 0.0, 1.0, 0.0,
+ 0.0, 3.0, 0.0, 1.0,
+ ])
+
+ abcprop = self.abcprop(abc, '%s/CubeShape/.geom' % name)
+ self.assertIn('.faceCounts', abcprop)
+
+
+if __name__ == '__main__':
+ parser = argparse.ArgumentParser()
+ parser.add_argument('--blender', required=True)
+ parser.add_argument('--testdir', required=True)
+ parser.add_argument('--alembic-root', required=True)
+ args, remaining = parser.parse_known_args()
+
+ unittest.main(argv=sys.argv[0:1] + remaining)
diff --git a/tests/python/batch_import.py b/tests/python/batch_import.py
index 8fc679a7c15..a6e2469349b 100644
--- a/tests/python/batch_import.py
+++ b/tests/python/batch_import.py
@@ -48,29 +48,17 @@ import os
import sys
-def clear_scene():
- import bpy
- unique_obs = set()
- for scene in bpy.data.scenes:
- for obj in scene.objects[:]:
- scene.objects.unlink(obj)
- unique_obs.add(obj)
-
- # remove obdata, for now only worry about the startup scene
- for bpy_data_iter in (bpy.data.objects, bpy.data.meshes, bpy.data.lamps, bpy.data.cameras):
- for id_data in bpy_data_iter:
- bpy_data_iter.remove(id_data)
-
-
-def batch_import(operator="",
- path="",
- save_path="",
- match="",
- start=0,
- end=sys.maxsize,
- ):
+def batch_import(
+ operator="",
+ path="",
+ save_path="",
+ match="",
+ start=0,
+ end=sys.maxsize,
+):
import addon_utils
_reset_all = addon_utils.reset_all # XXX, hack
+ _disable_all = addon_utils.disable_all # XXX, hack
import fnmatch
@@ -84,10 +72,8 @@ def batch_import(operator="",
def file_generator(path):
for dirpath, dirnames, filenames in os.walk(path):
-
- # skip '.svn'
- if dirpath.startswith("."):
- continue
+ # skip '.git'
+ dirnames[:] = [d for d in dirnames if not d.startswith(".")]
for filename in filenames:
if pattern_match(filename):
@@ -116,11 +102,12 @@ def batch_import(operator="",
# hack so loading the new file doesn't undo our loaded addons
addon_utils.reset_all = lambda: None # XXX, hack
+ addon_utils.disable_all = lambda: None # XXX, hack
- bpy.ops.wm.read_factory_settings()
+ bpy.ops.wm.read_factory_settings(use_empty=True)
addon_utils.reset_all = _reset_all # XXX, hack
- clear_scene()
+ addon_utils.disable_all = _disable_all # XXX, hack
result = op(filepath=f)
diff --git a/tests/python/bl_alembic_import_test.py b/tests/python/bl_alembic_import_test.py
new file mode 100644
index 00000000000..c3a4af26e11
--- /dev/null
+++ b/tests/python/bl_alembic_import_test.py
@@ -0,0 +1,270 @@
+# ##### BEGIN GPL LICENSE BLOCK #####
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# ##### END GPL LICENSE BLOCK #####
+
+# <pep8 compliant>
+
+"""
+./blender.bin --background -noaudio --factory-startup --python tests/python/bl_alembic_import_test.py -- --testdir /path/to/lib/tests/alembic
+"""
+
+import pathlib
+import sys
+import unittest
+
+import bpy
+
+args = None
+
+
+class AbstractAlembicTest(unittest.TestCase):
+ @classmethod
+ def setUpClass(cls):
+ cls.testdir = args.testdir
+
+ def setUp(self):
+ self.assertTrue(self.testdir.exists(),
+ 'Test dir %s should exist' % self.testdir)
+
+ # Make sure we always start with a known-empty file.
+ bpy.ops.wm.open_mainfile(filepath=str(self.testdir / "empty.blend"))
+
+ def assertAlmostEqualFloatArray(self, actual, expect, places=6, delta=None):
+ """Asserts that the arrays of floats are almost equal."""
+
+ self.assertEqual(len(actual), len(expect),
+ 'Actual array has %d items, expected %d' % (len(actual), len(expect)))
+
+ for idx, (act, exp) in enumerate(zip(actual, expect)):
+ self.assertAlmostEqual(act, exp, places=places, delta=delta,
+ msg='%f != %f at index %d' % (act, exp, idx))
+
+
+class SimpleImportTest(AbstractAlembicTest):
+ def test_import_cube_hierarchy(self):
+ res = bpy.ops.wm.alembic_import(
+ filepath=str(self.testdir / "cubes-hierarchy.abc"),
+ as_background_job=False)
+ self.assertEqual({'FINISHED'}, res)
+
+ # The objects should be linked to scene_collection in Blender 2.8,
+ # and to scene in Blender 2.7x.
+ objects = bpy.context.scene.objects
+ self.assertEqual(13, len(objects))
+
+ # Test the hierarchy.
+ self.assertIsNone(objects['Cube'].parent)
+ self.assertEqual(objects['Cube'], objects['Cube_001'].parent)
+ self.assertEqual(objects['Cube'], objects['Cube_002'].parent)
+ self.assertEqual(objects['Cube'], objects['Cube_003'].parent)
+ self.assertEqual(objects['Cube_003'], objects['Cube_004'].parent)
+ self.assertEqual(objects['Cube_003'], objects['Cube_005'].parent)
+ self.assertEqual(objects['Cube_003'], objects['Cube_006'].parent)
+
+ def test_inherit_or_not(self):
+ res = bpy.ops.wm.alembic_import(
+ filepath=str(self.testdir / "T52022-inheritance.abc"),
+ as_background_job=False)
+ self.assertEqual({'FINISHED'}, res)
+
+ # The objects should be linked to scene_collection in Blender 2.8,
+ # and to scene in Blender 2.7x.
+ objects = bpy.context.scene.objects
+
+ # ABC parent is top-level object, which translates to nothing in Blender
+ self.assertIsNone(objects['locator1'].parent)
+
+ # ABC parent is locator1, but locator2 has "inherits Xforms" = false, which
+ # translates to "no parent" in Blender.
+ self.assertIsNone(objects['locator2'].parent)
+
+ # Shouldn't have inherited the ABC parent's transform.
+ x, y, z = objects['locator2'].matrix_world.to_translation()
+ self.assertAlmostEqual(0, x)
+ self.assertAlmostEqual(0, y)
+ self.assertAlmostEqual(2, z)
+
+ # ABC parent is inherited and translates to normal parent in Blender.
+ self.assertEqual(objects['locator2'], objects['locatorShape2'].parent)
+
+ # Should have inherited its ABC parent's transform.
+ x, y, z = objects['locatorShape2'].matrix_world.to_translation()
+ self.assertAlmostEqual(0, x)
+ self.assertAlmostEqual(0, y)
+ self.assertAlmostEqual(2, z)
+
+
+ def test_select_after_import(self):
+ # Add a sphere, so that there is something in the scene, selected, and active,
+ # before we do the Alembic import.
+ bpy.ops.mesh.primitive_uv_sphere_add()
+ sphere = bpy.context.active_object
+ self.assertEqual('Sphere', sphere.name)
+ self.assertEqual([sphere], bpy.context.selected_objects)
+
+ bpy.ops.wm.alembic_import(
+ filepath=str(self.testdir / "cubes-hierarchy.abc"),
+ as_background_job=False)
+
+ # The active object is probably the first one that was imported, but this
+ # behaviour is not defined. At least it should be one of the cubes, and
+ # not the sphere.
+ self.assertNotEqual(sphere, bpy.context.active_object)
+ self.assertTrue('Cube' in bpy.context.active_object.name)
+
+ # All cubes should be selected, but the sphere shouldn't be.
+ for ob in bpy.data.objects:
+ self.assertEqual('Cube' in ob.name, ob.select)
+
+ def test_change_path_constraint(self):
+ import math
+
+ fname = 'cube-rotating1.abc'
+ abc = self.testdir / fname
+ relpath = bpy.path.relpath(str(abc))
+
+ res = bpy.ops.wm.alembic_import(filepath=str(abc), as_background_job=False)
+ self.assertEqual({'FINISHED'}, res)
+ cube = bpy.context.active_object
+
+ # Check that the file loaded ok.
+ bpy.context.scene.frame_set(10)
+ x, y, z = cube.matrix_world.to_euler('XYZ')
+ self.assertAlmostEqual(x, 0)
+ self.assertAlmostEqual(y, 0)
+ self.assertAlmostEqual(z, math.pi / 2, places=5)
+
+ # Change path from absolute to relative. This should not break the animation.
+ bpy.context.scene.frame_set(1)
+ bpy.data.cache_files[fname].filepath = relpath
+ bpy.context.scene.frame_set(10)
+
+ x, y, z = cube.matrix_world.to_euler('XYZ')
+ self.assertAlmostEqual(x, 0)
+ self.assertAlmostEqual(y, 0)
+ self.assertAlmostEqual(z, math.pi / 2, places=5)
+
+ # Replace the Alembic file; this should apply new animation.
+ bpy.data.cache_files[fname].filepath = relpath.replace('1.abc', '2.abc')
+ bpy.context.scene.update()
+
+ if args.with_legacy_depsgraph:
+ bpy.context.scene.frame_set(10)
+
+ x, y, z = cube.matrix_world.to_euler('XYZ')
+ self.assertAlmostEqual(x, math.pi / 2, places=5)
+ self.assertAlmostEqual(y, 0)
+ self.assertAlmostEqual(z, 0)
+
+ def test_change_path_modifier(self):
+ import math
+
+ fname = 'animated-mesh.abc'
+ abc = self.testdir / fname
+ relpath = bpy.path.relpath(str(abc))
+
+ res = bpy.ops.wm.alembic_import(filepath=str(abc), as_background_job=False)
+ self.assertEqual({'FINISHED'}, res)
+ plane = bpy.context.active_object
+
+ # Check that the file loaded ok.
+ bpy.context.scene.frame_set(6)
+ mesh = plane.to_mesh(bpy.context.scene, True, 'RENDER')
+ self.assertAlmostEqual(-1, mesh.vertices[0].co.x)
+ self.assertAlmostEqual(-1, mesh.vertices[0].co.y)
+ self.assertAlmostEqual(0.5905638933181763, mesh.vertices[0].co.z)
+
+ # Change path from absolute to relative. This should not break the animation.
+ bpy.context.scene.frame_set(1)
+ bpy.data.cache_files[fname].filepath = relpath
+ bpy.context.scene.frame_set(6)
+
+ mesh = plane.to_mesh(bpy.context.scene, True, 'RENDER')
+ self.assertAlmostEqual(1, mesh.vertices[3].co.x)
+ self.assertAlmostEqual(1, mesh.vertices[3].co.y)
+ self.assertAlmostEqual(0.5905638933181763, mesh.vertices[3].co.z)
+
+ def test_import_long_names(self):
+ # This file contains very long names. The longest name is 4047 chars.
+ bpy.ops.wm.alembic_import(
+ filepath=str(self.testdir / "long-names.abc"),
+ as_background_job=False)
+
+ self.assertIn('Cube', bpy.data.objects)
+ self.assertEqual('CubeShape', bpy.data.objects['Cube'].data.name)
+
+
+class VertexColourImportTest(AbstractAlembicTest):
+ def test_import_from_houdini(self):
+ # Houdini saved "face-varying", and as RGB.
+ res = bpy.ops.wm.alembic_import(
+ filepath=str(self.testdir / "vertex-colours-houdini.abc"),
+ as_background_job=False)
+ self.assertEqual({'FINISHED'}, res)
+
+ ob = bpy.context.active_object
+ layer = ob.data.vertex_colors['Cf'] # MeshLoopColorLayer
+
+ # Test some known-good values.
+ self.assertAlmostEqualFloatArray(layer.data[0].color, (0, 0, 0))
+ self.assertAlmostEqualFloatArray(layer.data[98].color, (0.9019607, 0.4745098, 0.2666666))
+ self.assertAlmostEqualFloatArray(layer.data[99].color, (0.8941176, 0.4705882, 0.2627451))
+
+ def test_import_from_blender(self):
+ # Blender saved per-vertex, and as RGBA.
+ res = bpy.ops.wm.alembic_import(
+ filepath=str(self.testdir / "vertex-colours-blender.abc"),
+ as_background_job=False)
+ self.assertEqual({'FINISHED'}, res)
+
+ ob = bpy.context.active_object
+ layer = ob.data.vertex_colors['Cf'] # MeshLoopColorLayer
+
+ # Test some known-good values.
+ self.assertAlmostEqualFloatArray(layer.data[0].color, (1.0, 0.0156862, 0.3607843))
+ self.assertAlmostEqualFloatArray(layer.data[98].color, (0.0941176, 0.1215686, 0.9137254))
+ self.assertAlmostEqualFloatArray(layer.data[99].color, (0.1294117, 0.3529411, 0.7529411))
+
+
+def main():
+ global args
+ import argparse
+
+ if '--' in sys.argv:
+ argv = [sys.argv[0]] + sys.argv[sys.argv.index('--') + 1:]
+ else:
+ argv = sys.argv
+
+ parser = argparse.ArgumentParser()
+ parser.add_argument('--testdir', required=True, type=pathlib.Path)
+ parser.add_argument('--with-legacy-depsgraph', default=False,
+ type=lambda v: v in {'ON', 'YES', 'TRUE'})
+ args, remaining = parser.parse_known_args(argv)
+
+ unittest.main(argv=remaining)
+
+
+if __name__ == "__main__":
+ import traceback
+ # So a python error exits Blender itself too
+ try:
+ main()
+ except SystemExit:
+ raise
+ except:
+ traceback.print_exc()
+ sys.exit(1)
diff --git a/tests/python/bl_keymap_completeness.py b/tests/python/bl_keymap_completeness.py
index 00322907f69..652ed449a3c 100644
--- a/tests/python/bl_keymap_completeness.py
+++ b/tests/python/bl_keymap_completeness.py
@@ -80,5 +80,6 @@ def main():
import sys
sys.exit(1)
+
if __name__ == "__main__":
main()
diff --git a/tests/python/bl_load_py_modules.py b/tests/python/bl_load_py_modules.py
index c13679d16f0..39e7bd33d44 100644
--- a/tests/python/bl_load_py_modules.py
+++ b/tests/python/bl_load_py_modules.py
@@ -36,6 +36,9 @@ BLACKLIST = {
"cycles",
"io_export_dxf", # TODO, check on why this fails
'io_import_dxf', # Because of cydxfentity.so dependency
+
+ # The unpacked wheel is only loaded when actually used, not directly on import:
+ os.path.join("io_blend_utils", "blender_bam-unpacked.whl"),
}
# Some modules need to add to the `sys.path`.
@@ -90,9 +93,8 @@ def addon_modules_sorted():
def source_list(path, filename_check=None):
from os.path import join
for dirpath, dirnames, filenames in os.walk(path):
- # skip '.svn'
- if dirpath.startswith("."):
- continue
+ # skip '.git'
+ dirnames[:] = [d for d in dirnames if not d.startswith(".")]
for filename in filenames:
filepath = join(dirpath, filename)
@@ -120,6 +122,8 @@ def load_addons():
def load_modules():
+ VERBOSE = os.environ.get("BLENDER_VERBOSE") is not None
+
modules = []
module_paths = []
@@ -159,6 +163,14 @@ def load_modules():
del module_names
#
+ # test we tested all files except for presets and templates
+ ignore_paths = [
+ os.sep + "presets" + os.sep,
+ os.sep + "templates" + os.sep,
+ ] + ([(os.sep + f + os.sep) for f in BLACKLIST] +
+ [(os.sep + f + ".py") for f in BLACKLIST])
+
+ #
# now submodules
for m in modules:
filepath = m.__file__
@@ -175,15 +187,35 @@ def load_modules():
for f in MODULE_SYS_PATHS.get(mod_name_full, ())
])
- __import__(mod_name_full)
- mod_imp = sys.modules[mod_name_full]
-
- sys.path[:] = sys_path_back
-
- # check we load what we ask for.
- assert(os.path.samefile(mod_imp.__file__, submod_full))
-
- modules.append(mod_imp)
+ try:
+ __import__(mod_name_full)
+ mod_imp = sys.modules[mod_name_full]
+
+ sys.path[:] = sys_path_back
+
+ # check we load what we ask for.
+ assert(os.path.samefile(mod_imp.__file__, submod_full))
+
+ modules.append(mod_imp)
+ except Exception as e:
+ import traceback
+ # Module might fail to import, but we don't want whole test to fail here.
+ # Reasoning:
+ # - This module might be in ignored list (for example, preset or template),
+ # so failing here will cause false-positive test failure.
+ # - If this is module which should not be ignored, it is not added to list
+ # of successfully loaded modules, meaning the test will catch this
+ # import failure.
+ # - We want to catch all failures of this script instead of stopping on
+ # a first big failure.
+ do_print = True
+ if not VERBOSE:
+ for ignore in ignore_paths:
+ if ignore in submod_full:
+ do_print = False
+ break
+ if do_print:
+ traceback.print_exc()
#
# check which filepaths we didn't load
@@ -202,20 +234,11 @@ def load_modules():
for f in loaded_files:
source_files.remove(f)
- #
- # test we tested all files except for presets and templates
- ignore_paths = [
- os.sep + "presets" + os.sep,
- os.sep + "templates" + os.sep,
- ] + ([(os.sep + f + os.sep) for f in BLACKLIST] +
- [(os.sep + f + ".py") for f in BLACKLIST])
-
for f in source_files:
- ok = False
for ignore in ignore_paths:
if ignore in f:
- ok = True
- if not ok:
+ break
+ else:
raise Exception("Source file %r not loaded in test" % f)
print("loaded %d modules" % len(loaded_files))
diff --git a/tests/python/bl_mesh_modifiers.py b/tests/python/bl_mesh_modifiers.py
index 526a54a49a2..bff2c31984c 100644
--- a/tests/python/bl_mesh_modifiers.py
+++ b/tests/python/bl_mesh_modifiers.py
@@ -31,7 +31,6 @@
import math
USE_QUICK_RENDER = False
-IS_BMESH = hasattr(__import__("bpy").types, "LoopColors")
# -----------------------------------------------------------------------------
# utility functions
@@ -203,13 +202,8 @@ def defaults_object(obj):
mesh.show_normal_vertex = True
- # lame!
- if IS_BMESH:
- for poly in mesh.polygons:
- poly.use_smooth = True
- else:
- for face in mesh.faces:
- face.use_smooth = True
+ for poly in mesh.polygons:
+ poly.use_smooth = True
def defaults_modifier(mod):
@@ -220,16 +214,14 @@ def defaults_modifier(mod):
# -----------------------------------------------------------------------------
# models (utils)
+def mesh_bmesh_poly_elems(poly, elems):
+ vert_start = poly.loop_start
+ vert_total = poly.loop_total
+ return elems[vert_start:vert_start + vert_total]
-if IS_BMESH:
- def mesh_bmesh_poly_elems(poly, elems):
- vert_start = poly.loop_start
- vert_total = poly.loop_total
- return elems[vert_start:vert_start + vert_total]
-
- def mesh_bmesh_poly_vertices(poly):
- return [loop.vertex_index
- for loop in mesh_bmesh_poly_elems(poly, poly.id_data.loops)]
+def mesh_bmesh_poly_vertices(poly):
+ return [loop.vertex_index
+ for loop in mesh_bmesh_poly_elems(poly, poly.id_data.loops)]
def mesh_bounds(mesh):
@@ -258,21 +250,14 @@ def mesh_uv_add(obj):
uv_lay = obj.data.uv_textures.new()
- if IS_BMESH:
- # XXX, odd that we need to do this. until UV's and texface
- # are separated we will need to keep it
- uv_loops = obj.data.uv_layers[-1]
- uv_list = uv_loops.data[:]
- for poly in obj.data.polygons:
- poly_uvs = mesh_bmesh_poly_elems(poly, uv_list)
- for i, c in enumerate(poly_uvs):
- c.uv = uvs[i % 4]
- else:
- for uv in uv_lay.data:
- uv.uv1 = uvs[0]
- uv.uv2 = uvs[1]
- uv.uv3 = uvs[2]
- uv.uv4 = uvs[3]
+ # XXX, odd that we need to do this. until UV's and texface
+ # are separated we will need to keep it
+ uv_loops = obj.data.uv_layers[-1]
+ uv_list = uv_loops.data[:]
+ for poly in obj.data.polygons:
+ poly_uvs = mesh_bmesh_poly_elems(poly, uv_list)
+ for i, c in enumerate(poly_uvs):
+ c.uv = uvs[i % 4]
return uv_lay
@@ -296,21 +281,12 @@ def mesh_vcol_add(obj, mode=0):
mesh = obj.data
- if IS_BMESH:
- col_list = vcol_lay.data[:]
- for poly in mesh.polygons:
- face_verts = mesh_bmesh_poly_vertices(poly)
- poly_cols = mesh_bmesh_poly_elems(poly, col_list)
- for i, c in enumerate(poly_cols):
- c.color = colors_get(face_verts[i])
- else:
- for i, col in enumerate(vcol_lay.data):
- face_verts = mesh.faces[i].vertices
- col.color1 = colors_get(face_verts[0])
- col.color2 = colors_get(face_verts[1])
- col.color3 = colors_get(face_verts[2])
- if len(face_verts) == 4:
- col.color4 = colors_get(face_verts[3])
+ col_list = vcol_lay.data[:]
+ for poly in mesh.polygons:
+ face_verts = mesh_bmesh_poly_vertices(poly)
+ poly_cols = mesh_bmesh_poly_elems(poly, col_list)
+ for i, c in enumerate(poly_cols):
+ c.color = colors_get(face_verts[i])
return vcol_lay
@@ -470,10 +446,7 @@ def modifier_build_add(scene, obj):
defaults_modifier(mod)
# ensure we display some faces
- if IS_BMESH:
- totface = len(obj.data.polygons)
- else:
- totface = len(obj.data.faces)
+ totface = len(obj.data.polygons)
mod.frame_start = totface // 2
mod.frame_duration = totface
diff --git a/tests/python/bl_pyapi_bpy_utils_units.py b/tests/python/bl_pyapi_bpy_utils_units.py
index f40dab4b5eb..251419cb9ef 100644
--- a/tests/python/bl_pyapi_bpy_utils_units.py
+++ b/tests/python/bl_pyapi_bpy_utils_units.py
@@ -32,18 +32,17 @@ class UnitsTesting(unittest.TestCase):
OUTPUT_TESTS = (
# system, type, prec, sep, compat, value, output
##### LENGTH
+ # Note: precision handling is a bit complicated when using multi-units...
('IMPERIAL', 'LENGTH', 3, False, False, 0.3048, "1'"),
('IMPERIAL', 'LENGTH', 3, False, True, 0.3048, "1ft"),
- ('IMPERIAL', 'LENGTH', 3, True, False, 0.3048 * 2 + 0.0254 * 5.5, "2' 5.5\""),
- # Those next two fail, here again because precision ignores order magnitude :/
- #('IMPERIAL', 'LENGTH', 3, False, False, 1609.344 * 1e6, "1000000mi"), # == 1000000.004mi!!!
- #('IMPERIAL', 'LENGTH', 6, False, False, 1609.344 * 1e6, "1000000mi"), # == 1000000.003641mi!!!
- ('METRIC', 'LENGTH', 3, True, False, 1000 * 2 + 0.001 * 15, "2km 1.5cm"),
- ('METRIC', 'LENGTH', 3, True, False, 1234.56789, "1km 234.6m"),
- # Note: precision seems basically unused when using multi units!
- ('METRIC', 'LENGTH', 9, True, False, 1234.56789, "1km 234.6m"),
- ('METRIC', 'LENGTH', 9, False, False, 1234.56789, "1.23456789km"),
- ('METRIC', 'LENGTH', 9, True, False, 1000.000123456789, "1km 0.1mm"),
+ ('IMPERIAL', 'LENGTH', 4, True, False, 0.3048 * 2 + 0.0254 * 5.5, "2' 5.5\""),
+ ('IMPERIAL', 'LENGTH', 3, False, False, 1609.344 * 1e6, "1000000mi"),
+ ('IMPERIAL', 'LENGTH', 6, False, False, 1609.344 * 1e6, "1000000mi"),
+ ('METRIC', 'LENGTH', 3, True, False, 1000 * 2 + 0.001 * 15, "2km 2cm"),
+ ('METRIC', 'LENGTH', 5, True, False, 1234.56789, "1km 234.6m"),
+ ('METRIC', 'LENGTH', 6, True, False, 1234.56789, "1km 234.57m"),
+ ('METRIC', 'LENGTH', 9, False, False, 1234.56789, "1.234568km"),
+ ('METRIC', 'LENGTH', 9, True, False, 1000.000123456789, "1km 0.123mm"),
)
def test_units_inputs(self):
diff --git a/tests/python/bl_pyapi_idprop.py b/tests/python/bl_pyapi_idprop.py
new file mode 100644
index 00000000000..7bf68c16cc7
--- /dev/null
+++ b/tests/python/bl_pyapi_idprop.py
@@ -0,0 +1,204 @@
+# Apache License, Version 2.0
+
+# ./blender.bin --background -noaudio --python tests/python/bl_pyapi_idprop.py -- --verbose
+import bpy
+import unittest
+import numpy as np
+from array import array
+
+
+class TestHelper:
+
+ @property
+ def id(self):
+ return self._id
+
+ def setUp(self):
+ self._id = bpy.context.scene
+ assert(len(self._id.keys()) == 0)
+
+ def tearDown(self):
+ for key in list(self._id.keys()):
+ del self._id[key]
+
+ def assertAlmostEqualSeq(self, list1, list2):
+ self.assertEqual(len(list1), len(list2))
+ for v1, v2 in zip(list1, list2):
+ self.assertAlmostEqual(v1, v2, places=5)
+
+
+class TestIdPropertyCreation(TestHelper, unittest.TestCase):
+
+ def test_name_empty(self):
+ self.id[""] = 4
+ self.assertEqual(self.id[""], 4)
+
+ def test_name_too_long(self):
+ with self.assertRaises(KeyError):
+ self.id["name" * 30] = 4
+
+ def test_int(self):
+ self.id["a"] = 2
+ self.assertEqual(self.id["a"], 2)
+ self.assertTrue(isinstance(self.id["a"], int))
+
+ with self.assertRaises(OverflowError):
+ self.id["a"] = 2 ** 31 # integer <= 2 ** 31-1
+
+ def test_double(self):
+ self.id["a"] = 2.5
+ self.assertEqual(self.id["a"], 2.5)
+ self.assertTrue(isinstance(self.id["a"], float))
+
+ def test_unicode(self):
+ self.id["a"] = "Hello World"
+ self.assertEqual(self.id["a"], "Hello World")
+ self.assertTrue(isinstance(self.id["a"], str))
+
+ def test_bytes(self):
+ self.id["a"] = b"Hello World"
+ self.assertEqual(self.id["a"], b"Hello World")
+ self.assertTrue(isinstance(self.id["a"], bytes))
+
+ def test_sequence_double_list(self):
+ mylist = [1.2, 3.4, 5.6]
+ self.id["a"] = mylist
+ self.assertEqual(self.id["a"].to_list(), mylist)
+ self.assertEqual(self.id["a"].typecode, "d")
+
+ def test_sequence_int_list(self):
+ mylist = [1, 2, 3]
+ self.id["a"] = mylist
+ self.assertEqual(self.id["a"].to_list(), mylist)
+ self.assertEqual(self.id["a"].typecode, "i")
+
+ def test_sequence_float_array(self):
+ mylist = [1.2, 3.4, 5.6]
+ self.id["a"] = array("f", mylist)
+ self.assertAlmostEqualSeq(self.id["a"].to_list(), mylist)
+ self.assertEqual(self.id["a"].typecode, "f")
+
+ def test_sequence_double_array(self):
+ mylist = [1.2, 3.4, 5.6]
+ self.id["a"] = array("d", mylist)
+ self.assertAlmostEqualSeq(self.id["a"].to_list(), mylist)
+ self.assertEqual(self.id["a"].typecode, "d")
+
+ def test_sequence_int_array(self):
+ mylist = [1, 2, 3]
+ self.id["a"] = array("i", mylist)
+ self.assertAlmostEqualSeq(self.id["a"].to_list(), mylist)
+ self.assertEqual(self.id["a"].typecode, "i")
+
+ def test_sequence_other_array(self):
+ mylist = [1, 2, 3]
+ self.id["a"] = array("Q", mylist)
+ self.assertEqual(self.id["a"].to_list(), mylist)
+
+ def test_sequence_mixed_numerical_type(self):
+ self.id["a"] = [1, 2, 3.4, 5]
+ self.assertAlmostEqualSeq(self.id["a"].to_list(), [1.0, 2.0, 3.4, 5.0])
+ self.assertEqual(self.id["a"].typecode, "d")
+
+ def test_sequence_str_list(self):
+ # I'm a bit surprised that this works
+ mylist = ["abc", "qwe"]
+ self.id["a"] = mylist
+ self.assertEqual(self.id["a"], mylist)
+
+ def test_sequence_mixed_type(self):
+ with self.assertRaises(TypeError):
+ mylist = ["abc", 3, "qwe", 3.4]
+ self.id["a"] = mylist
+
+ def test_mapping_simple(self):
+ mydict = {"1": 10, "2": "20", "3": 30.5}
+ self.id["a"] = mydict
+ self.assertEqual(self.id["a"]["1"], mydict["1"])
+ self.assertEqual(self.id["a"]["2"], mydict["2"])
+ self.assertEqual(self.id["a"]["3"], mydict["3"])
+
+ def test_mapping_complex(self):
+ mydict = {
+ "1": [1, 2, 3],
+ "2": {"1": "abc", "2": array("i", [4, 5, 6])},
+ "3": {"1": {"1": 10}, "2": b"qwe"},
+ }
+ self.id["a"] = mydict
+ self.assertEqual(self.id["a"]["1"].to_list(), [1, 2, 3])
+ self.assertEqual(self.id["a"]["2"]["1"], "abc")
+ self.assertEqual(self.id["a"]["2"]["2"].to_list(), [4, 5, 6])
+ self.assertEqual(self.id["a"]["3"]["1"]["1"], 10)
+ self.assertEqual(self.id["a"]["3"]["2"], b"qwe")
+
+ with self.assertRaises(KeyError):
+ a = self.id["a"]["2"]["a"]
+
+ def test_invalid_type(self):
+ with self.assertRaises(TypeError):
+ self.id["a"] = self
+
+
+class TestBufferProtocol(TestHelper, unittest.TestCase):
+
+ def test_int(self):
+ self.id["a"] = array("i", [1, 2, 3, 4, 5])
+ a = np.frombuffer(self.id["a"], self.id["a"].typecode)
+ self.assertEqual(len(a), 5)
+ a[2] = 10
+ self.assertEqual(self.id["a"].to_list(), [1, 2, 10, 4, 5])
+
+ def test_float(self):
+ self.id["a"] = array("f", [1.0, 2.0, 3.0, 4.0])
+ a = np.frombuffer(self.id["a"], self.id["a"].typecode)
+ self.assertEqual(len(a), 4)
+ a[-1] = 10
+ self.assertEqual(self.id["a"].to_list(), [1.0, 2.0, 3.0, 10.0])
+
+ def test_double(self):
+ self.id["a"] = array("d", [1.0, 2.0, 3.0, 4.0])
+ a = np.frombuffer(self.id["a"], self.id["a"].typecode)
+ a[1] = 10
+ self.assertEqual(self.id["a"].to_list(), [1.0, 10.0, 3.0, 4.0])
+
+ def test_full_update(self):
+ self.id["a"] = array("i", [1, 2, 3, 4, 5, 6])
+ a = np.frombuffer(self.id["a"], self.id["a"].typecode)
+ a[:] = [10, 20, 30, 40, 50, 60]
+ self.assertEqual(self.id["a"].to_list(), [10, 20, 30, 40, 50, 60])
+
+ def test_partial_update(self):
+ self.id["a"] = array("i", [1, 2, 3, 4, 5, 6, 7, 8])
+ a = np.frombuffer(self.id["a"], self.id["a"].typecode)
+ a[1:5] = [10, 20, 30, 40]
+ self.assertEqual(self.id["a"].to_list(), [1, 10, 20, 30, 40, 6, 7, 8])
+
+ def test_copy(self):
+ self.id["a"] = array("i", [1, 2, 3, 4, 5])
+ self.id["b"] = self.id["a"]
+ self.assertEqual(self.id["a"].to_list(), self.id["b"].to_list())
+
+ def test_memview_attributes(self):
+ mylist = [1, 2, 3]
+ self.id["a"] = mylist
+
+ view1 = memoryview(self.id["a"])
+ view2 = memoryview(array("i", mylist))
+
+ self.assertEqualMemviews(view1, view2)
+
+ def assertEqualMemviews(self, view1, view2):
+ props_to_compare = (
+ "contiguous", "format", "itemsize", "nbytes", "ndim",
+ "readonly", "shape", "strides", "suboffsets"
+ )
+ for attr in props_to_compare:
+ self.assertEqual(getattr(view1, attr), getattr(view2, attr))
+
+ self.assertEqual(list(view1), list(view2))
+ self.assertEqual(view1.tobytes(), view2.tobytes())
+
+if __name__ == '__main__':
+ import sys
+ sys.argv = [__file__] + (sys.argv[sys.argv.index("--") + 1:] if "--" in sys.argv else [])
+ unittest.main()
diff --git a/tests/python/bl_pyapi_idprop_datablock.py b/tests/python/bl_pyapi_idprop_datablock.py
new file mode 100644
index 00000000000..4acfb83bd95
--- /dev/null
+++ b/tests/python/bl_pyapi_idprop_datablock.py
@@ -0,0 +1,338 @@
+# ##### BEGIN GPL LICENSE BLOCK #####
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# ##### END GPL LICENSE BLOCK #####
+
+import bpy
+import sys
+import os
+import tempfile
+import traceback
+import inspect
+from bpy.types import UIList
+
+arr_len = 100
+ob_cp_count = 100
+lib_path = os.path.join(tempfile.gettempdir(), "lib.blend")
+test_path = os.path.join(tempfile.gettempdir(), "test.blend")
+
+
+def print_fail_msg_and_exit(msg):
+ def __LINE__():
+ try:
+ raise Exception
+ except:
+ return sys.exc_info()[2].tb_frame.f_back.f_back.f_back.f_lineno
+
+ def __FILE__():
+ return inspect.currentframe().f_code.co_filename
+
+ print("'%s': %d >> %s" % (__FILE__(), __LINE__(), msg), file=sys.stderr)
+ sys.stderr.flush()
+ sys.stdout.flush()
+ os._exit(1)
+
+
+def abort_if_false(expr, msg=None):
+ if not expr:
+ if not msg:
+ msg = "test failed"
+ print_fail_msg_and_exit(msg)
+
+
+class TestClass(bpy.types.PropertyGroup):
+ test_prop = bpy.props.PointerProperty(type=bpy.types.Object)
+ name = bpy.props.StringProperty()
+
+
+def get_scene(lib_name, sce_name):
+ for s in bpy.data.scenes:
+ if s.name == sce_name:
+ if (s.library and s.library.name == lib_name) or \
+ (lib_name == None and s.library == None):
+ return s
+
+
+def check_crash(fnc, args=None):
+ try:
+ fnc(args) if args else fnc()
+ except:
+ return
+ print_fail_msg_and_exit("test failed")
+
+
+def init():
+ bpy.utils.register_class(TestClass)
+ bpy.types.Object.prop_array = bpy.props.CollectionProperty(
+ name="prop_array",
+ type=TestClass)
+ bpy.types.Object.prop = bpy.props.PointerProperty(type=bpy.types.Object)
+
+
+def make_lib():
+ bpy.ops.wm.read_factory_settings()
+
+ # datablock pointer to the Camera object
+ bpy.data.objects["Cube"].prop = bpy.data.objects['Camera']
+
+ # array of datablock pointers to the Lamp object
+ for i in range(0, arr_len):
+ a = bpy.data.objects["Cube"].prop_array.add()
+ a.test_prop = bpy.data.objects['Lamp']
+ a.name = a.test_prop.name
+
+ # make unique named copy of the cube
+ ob = bpy.data.objects["Cube"].copy()
+ bpy.context.scene.objects.link(ob)
+
+ bpy.data.objects["Cube.001"].name = "Unique_Cube"
+
+ # duplicating of Cube
+ for i in range(0, ob_cp_count):
+ ob = bpy.data.objects["Cube"].copy()
+ bpy.context.scene.objects.link(ob)
+
+ # nodes
+ bpy.data.scenes["Scene"].use_nodes = True
+ bpy.data.scenes["Scene"].node_tree.nodes['Render Layers']["prop"] =\
+ bpy.data.objects['Camera']
+
+ # rename scene and save
+ bpy.data.scenes["Scene"].name = "Scene_lib"
+ bpy.ops.wm.save_as_mainfile(filepath=lib_path)
+
+
+def check_lib():
+ # check pointer
+ abort_if_false(bpy.data.objects["Cube"].prop == bpy.data.objects['Camera'])
+
+ # check array of pointers in duplicated object
+ for i in range(0, arr_len):
+ abort_if_false(bpy.data.objects["Cube.001"].prop_array[i].test_prop ==
+ bpy.data.objects['Lamp'])
+
+
+def check_lib_linking():
+ # open startup file
+ bpy.ops.wm.read_factory_settings()
+
+ # link scene to the startup file
+ with bpy.data.libraries.load(lib_path, link=True) as (data_from, data_to):
+ data_to.scenes = ["Scene_lib"]
+
+ o = bpy.data.scenes["Scene_lib"].objects['Unique_Cube']
+
+ abort_if_false(o.prop_array[0].test_prop == bpy.data.scenes["Scene_lib"].objects['Lamp'])
+ abort_if_false(o.prop == bpy.data.scenes["Scene_lib"].objects['Camera'])
+ abort_if_false(o.prop.library == o.library)
+
+ bpy.ops.wm.save_as_mainfile(filepath=test_path)
+
+
+def check_linked_scene_copying():
+ # full copy of the scene with datablock props
+ bpy.ops.wm.open_mainfile(filepath=test_path)
+ bpy.data.screens['Default'].scene = bpy.data.scenes["Scene_lib"]
+ bpy.ops.scene.new(type='FULL_COPY')
+
+ # check save/open
+ bpy.ops.wm.save_as_mainfile(filepath=test_path)
+ bpy.ops.wm.open_mainfile(filepath=test_path)
+
+ intern_sce = get_scene(None, "Scene_lib")
+ extern_sce = get_scene("Lib", "Scene_lib")
+
+ # check node's props
+ # we made full copy from linked scene, so pointers must equal each other
+ abort_if_false(intern_sce.node_tree.nodes['Render Layers']["prop"] and
+ intern_sce.node_tree.nodes['Render Layers']["prop"] ==
+ extern_sce.node_tree.nodes['Render Layers']["prop"])
+
+
+def check_scene_copying():
+ # full copy of the scene with datablock props
+ bpy.ops.wm.open_mainfile(filepath=lib_path)
+ bpy.data.screens['Default'].scene = bpy.data.scenes["Scene_lib"]
+ bpy.ops.scene.new(type='FULL_COPY')
+
+ path = test_path + "_"
+ # check save/open
+ bpy.ops.wm.save_as_mainfile(filepath=path)
+ bpy.ops.wm.open_mainfile(filepath=path)
+
+ first_sce = get_scene(None, "Scene_lib")
+ second_sce = get_scene(None, "Scene_lib.001")
+
+ # check node's props
+ # must point to own scene camera
+ abort_if_false(not (first_sce.node_tree.nodes['Render Layers']["prop"] ==
+ second_sce.node_tree.nodes['Render Layers']["prop"]))
+
+
+# count users
+def test_users_counting():
+ bpy.ops.wm.read_factory_settings()
+ lamp_us = bpy.data.objects["Lamp"].data.users
+ n = 1000
+ for i in range(0, n):
+ bpy.data.objects["Cube"]["a%s" % i] = bpy.data.objects["Lamp"].data
+ abort_if_false(bpy.data.objects["Lamp"].data.users == lamp_us + n)
+
+ for i in range(0, int(n / 2)):
+ bpy.data.objects["Cube"]["a%s" % i] = 1
+ abort_if_false(bpy.data.objects["Lamp"].data.users == lamp_us + int(n / 2))
+
+
+# linking
+def test_linking():
+ make_lib()
+ check_lib()
+ check_lib_linking()
+ check_linked_scene_copying()
+ check_scene_copying()
+
+
+# check restrictions for datablock pointers for some classes; GUI for manual testing
+def test_restrictions1():
+ class TEST_Op(bpy.types.Operator):
+ bl_idname = 'scene.test_op'
+ bl_label = 'Test'
+ bl_options = {"INTERNAL"}
+ str_prop = bpy.props.StringProperty(name="str_prop")
+
+ # disallow registration of datablock properties in operators
+ # will be checked in the draw method (test manually)
+ # also, see console:
+ # ValueError: bpy_struct "SCENE_OT_test_op" doesn't support datablock properties
+ id_prop = bpy.props.PointerProperty(type=bpy.types.Object)
+
+ def execute(self, context):
+ return {'FINISHED'}
+
+ # just panel for testing the poll callback with lots of objects
+ class TEST_PT_DatablockProp(bpy.types.Panel):
+ bl_label = "Datablock IDProp"
+ bl_space_type = "PROPERTIES"
+ bl_region_type = "WINDOW"
+ bl_context = "render"
+
+ def draw(self, context):
+ self.layout.prop_search(context.scene, "prop", bpy.data,
+ "objects")
+ self.layout.template_ID(context.scene, "prop1")
+ self.layout.prop_search(context.scene, "prop2", bpy.data, "node_groups")
+
+ op = self.layout.operator("scene.test_op")
+ op.str_prop = "test string"
+
+ def test_fnc(op):
+ op["ob"] = bpy.data.objects['Unique_Cube']
+ check_crash(test_fnc, op)
+ abort_if_false(not hasattr(op, "id_prop"))
+
+ bpy.utils.register_class(TEST_PT_DatablockProp)
+ bpy.utils.register_class(TEST_Op)
+
+ def poll(self, value):
+ return value.name in bpy.data.scenes["Scene_lib"].objects
+
+ def poll1(self, value):
+ return True
+
+ bpy.types.Scene.prop = bpy.props.PointerProperty(type=bpy.types.Object)
+ bpy.types.Scene.prop1 = bpy.props.PointerProperty(type=bpy.types.Object, poll=poll)
+ bpy.types.Scene.prop2 = bpy.props.PointerProperty(type=bpy.types.NodeTree, poll=poll1)
+
+ # check poll effect on UI (poll returns false => red alert)
+ bpy.context.scene.prop = bpy.data.objects["Lamp.001"]
+ bpy.context.scene.prop1 = bpy.data.objects["Lamp.001"]
+
+ # check incorrect type assignment
+ def sub_test():
+ # NodeTree id_prop
+ bpy.context.scene.prop2 = bpy.data.objects["Lamp.001"]
+
+ check_crash(sub_test)
+
+ bpy.context.scene.prop2 = bpy.data.node_groups.new("Shader", "ShaderNodeTree")
+
+ print("Please, test GUI performance manually on the Render tab, '%s' panel" %
+ TEST_PT_DatablockProp.bl_label, file=sys.stderr)
+ sys.stderr.flush()
+
+
+# check some possible regressions
+def test_regressions():
+ bpy.types.Object.prop_str = bpy.props.StringProperty(name="str")
+ bpy.data.objects["Unique_Cube"].prop_str = "test"
+
+ bpy.types.Object.prop_gr = bpy.props.PointerProperty(
+ name="prop_gr",
+ type=TestClass,
+ description="test")
+
+ bpy.data.objects["Unique_Cube"].prop_gr = None
+
+
+# test restrictions for datablock pointers
+def test_restrictions2():
+ class TestClassCollection(bpy.types.PropertyGroup):
+ prop = bpy.props.CollectionProperty(
+ name="prop_array",
+ type=TestClass)
+ bpy.utils.register_class(TestClassCollection)
+
+ class TestPrefs(bpy.types.AddonPreferences):
+ bl_idname = "testprefs"
+ # expecting crash during registering
+ my_prop2 = bpy.props.PointerProperty(type=TestClass)
+
+ prop = bpy.props.PointerProperty(
+ name="prop",
+ type=TestClassCollection,
+ description="test")
+
+ bpy.types.Addon.a = bpy.props.PointerProperty(type=bpy.types.Object)
+
+ class TestUIList(UIList):
+ test = bpy.props.PointerProperty(type=bpy.types.Object)
+ def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
+ layout.prop(item, "name", text="", emboss=False, icon_value=icon)
+
+ check_crash(bpy.utils.register_class, TestPrefs)
+ check_crash(bpy.utils.register_class, TestUIList)
+
+ bpy.utils.unregister_class(TestClassCollection)
+
+
+def main():
+ init()
+ test_users_counting()
+ test_linking()
+ test_restrictions1()
+ check_crash(test_regressions)
+ test_restrictions2()
+
+
+if __name__ == "__main__":
+ try:
+ main()
+ except:
+ import traceback
+
+ traceback.print_exc()
+ sys.stderr.flush()
+ os._exit(1)
diff --git a/tests/python/bl_pyapi_mathutils.py b/tests/python/bl_pyapi_mathutils.py
index 7761b6cb7b1..9ca0376192a 100644
--- a/tests/python/bl_pyapi_mathutils.py
+++ b/tests/python/bl_pyapi_mathutils.py
@@ -260,6 +260,11 @@ class KDTreeTesting(unittest.TestCase):
k.balance()
return k
+ def assertAlmostEqualVector(self, first, second, places=7, msg=None, delta=None):
+ self.assertAlmostEqual(first[0], second[0], places=places, msg=msg, delta=delta)
+ self.assertAlmostEqual(first[1], second[1], places=places, msg=msg, delta=delta)
+ self.assertAlmostEqual(first[2], second[2], places=places, msg=msg, delta=delta)
+
def test_kdtree_single(self):
co = (0,) * 3
index = 2
@@ -360,12 +365,12 @@ class KDTreeTesting(unittest.TestCase):
ret_regular = k_odd.find(co)
self.assertEqual(ret_regular[1] % 2, 1)
ret_filter = k_all.find(co, lambda i: (i % 2) == 1)
- self.assertEqual(ret_regular, ret_filter)
+ self.assertAlmostEqualVector(ret_regular, ret_filter)
ret_regular = k_evn.find(co)
self.assertEqual(ret_regular[1] % 2, 0)
ret_filter = k_all.find(co, lambda i: (i % 2) == 0)
- self.assertEqual(ret_regular, ret_filter)
+ self.assertAlmostEqualVector(ret_regular, ret_filter)
# filter out all values (search odd tree for even values and the reverse)
diff --git a/tests/python/bl_run_operators.py b/tests/python/bl_run_operators.py
index 7e92b424faa..7b6b97e5ad1 100644
--- a/tests/python/bl_run_operators.py
+++ b/tests/python/bl_run_operators.py
@@ -65,6 +65,7 @@ op_blacklist = (
"wm.blenderplayer_start",
"wm.recover_auto_save",
"wm.quit_blender",
+ "wm.window_close",
"wm.url_open",
"wm.doc_view",
"wm.doc_edit",
@@ -99,10 +100,8 @@ def blend_list(mainpath):
def file_list(path, filename_check=None):
for dirpath, dirnames, filenames in os.walk(path):
-
- # skip '.svn'
- if dirpath.startswith("."):
- continue
+ # skip '.git'
+ dirnames[:] = [d for d in dirnames if not d.startswith(".")]
for filename in filenames:
filepath = join(dirpath, filename)
@@ -308,16 +307,7 @@ def run_ops(operators, setup_func=None, reset=True):
# contexts
def ctx_clear_scene(): # copied from batch_import.py
- unique_obs = set()
- for scene in bpy.data.scenes:
- for obj in scene.objects[:]:
- scene.objects.unlink(obj)
- unique_obs.add(obj)
-
- # remove obdata, for now only worry about the startup scene
- for bpy_data_iter in (bpy.data.objects, bpy.data.meshes, bpy.data.lamps, bpy.data.cameras):
- for id_data in bpy_data_iter:
- bpy_data_iter.remove(id_data)
+ bpy.ops.wm.read_factory_settings(use_empty=True)
def ctx_editmode_mesh():
diff --git a/tests/python/cycles_render_tests.py b/tests/python/cycles_render_tests.py
index 78b4b346f24..731996df8ef 100755
--- a/tests/python/cycles_render_tests.py
+++ b/tests/python/cycles_render_tests.py
@@ -2,27 +2,112 @@
# Apache License, Version 2.0
import argparse
+import glob
import os
+import pathlib
+import shlex
import shutil
import subprocess
import sys
+import time
import tempfile
+class COLORS_ANSI:
+ RED = '\033[00;31m'
+ GREEN = '\033[00;32m'
+ ENDC = '\033[0m'
+
+
+class COLORS_DUMMY:
+ RED = ''
+ GREEN = ''
+ ENDC = ''
+
+COLORS = COLORS_DUMMY
+
+
+def print_message(message, type=None, status=''):
+ if type == 'SUCCESS':
+ print(COLORS.GREEN, end="")
+ elif type == 'FAILURE':
+ print(COLORS.RED, end="")
+ status_text = ...
+ if status == 'RUN':
+ status_text = " RUN "
+ elif status == 'OK':
+ status_text = " OK "
+ elif status == 'PASSED':
+ status_text = " PASSED "
+ elif status == 'FAILED':
+ status_text = " FAILED "
+ else:
+ status_text = status
+ if status_text:
+ print("[{}]" . format(status_text), end="")
+ print(COLORS.ENDC, end="")
+ print(" {}" . format(message))
+ sys.stdout.flush()
+
+
def render_file(filepath):
- command = (
- BLENDER,
- "--background",
- "-noaudio",
- "--factory-startup",
- filepath,
- "-E", "CYCLES",
- # Run with OSL enabled
- # "--python-expr", "import bpy; bpy.context.scene.cycles.shading_system = True",
- "-o", TEMP_FILE_MASK,
- "-F", "PNG",
- "-f", "1",
- )
+ dirname = os.path.dirname(filepath)
+ basedir = os.path.dirname(dirname)
+ subject = os.path.basename(dirname)
+
+ custom_args = os.getenv('CYCLESTEST_ARGS')
+ custom_args = shlex.split(custom_args) if custom_args else []
+
+ # OSL and GPU examples
+ # custom_args += ["--python-expr", "import bpy; bpy.context.scene.cycles.shading_system = True"]
+ # custom_args += ["--python-expr", "import bpy; bpy.context.scene.cycles.device = 'GPU'"]
+
+ if subject == 'opengl':
+ command = [
+ BLENDER,
+ "--window-geometry", "0", "0", "1", "1",
+ "-noaudio",
+ "--factory-startup",
+ "--enable-autoexec",
+ filepath,
+ "-E", "CYCLES"]
+ command += custom_args
+ command += [
+ "-o", TEMP_FILE_MASK,
+ "-F", "PNG",
+ '--python', os.path.join(basedir,
+ "util",
+ "render_opengl.py")]
+ elif subject == 'bake':
+ command = [
+ BLENDER,
+ "-b",
+ "-noaudio",
+ "--factory-startup",
+ "--enable-autoexec",
+ filepath,
+ "-E", "CYCLES"]
+ command += custom_args
+ command += [
+ "-o", TEMP_FILE_MASK,
+ "-F", "PNG",
+ '--python', os.path.join(basedir,
+ "util",
+ "render_bake.py")]
+ else:
+ command = [
+ BLENDER,
+ "--background",
+ "-noaudio",
+ "--factory-startup",
+ "--enable-autoexec",
+ filepath,
+ "-E", "CYCLES"]
+ command += custom_args
+ command += [
+ "-o", TEMP_FILE_MASK,
+ "-F", "PNG",
+ "-f", "1"]
try:
output = subprocess.check_output(command)
if VERBOSE:
@@ -50,52 +135,241 @@ def test_get_name(filepath):
filename = os.path.basename(filepath)
return os.path.splitext(filename)[0]
-
-def verify_output(filepath):
+def test_get_images(filepath):
testname = test_get_name(filepath)
dirpath = os.path.dirname(filepath)
- reference_dirpath = os.path.join(dirpath, "reference_renders")
- reference_image = os.path.join(reference_dirpath, testname + ".png")
- failed_image = os.path.join(reference_dirpath, testname + ".fail.png")
- if not os.path.exists(reference_image):
- return False
+
+ old_dirpath = os.path.join(dirpath, "reference_renders")
+ old_img = os.path.join(old_dirpath, testname + ".png")
+
+ ref_dirpath = os.path.join(OUTDIR, os.path.basename(dirpath), "ref")
+ ref_img = os.path.join(ref_dirpath, testname + ".png")
+ if not os.path.exists(ref_dirpath):
+ os.makedirs(ref_dirpath)
+ if os.path.exists(old_img):
+ shutil.copy(old_img, ref_img)
+
+ new_dirpath = os.path.join(OUTDIR, os.path.basename(dirpath))
+ if not os.path.exists(new_dirpath):
+ os.makedirs(new_dirpath)
+ new_img = os.path.join(new_dirpath, testname + ".png")
+
+ diff_dirpath = os.path.join(OUTDIR, os.path.basename(dirpath), "diff")
+ if not os.path.exists(diff_dirpath):
+ os.makedirs(diff_dirpath)
+ diff_img = os.path.join(diff_dirpath, testname + ".diff.png")
+
+ return old_img, ref_img, new_img, diff_img
+
+
+class Report:
+ def __init__(self, testname):
+ self.failed_tests = ""
+ self.passed_tests = ""
+ self.testname = testname
+
+ def output(self):
+ # write intermediate data for single test
+ outdir = os.path.join(OUTDIR, self.testname)
+ if not os.path.exists(outdir):
+ os.makedirs(outdir)
+
+ filepath = os.path.join(outdir, "failed.data")
+ pathlib.Path(filepath).write_text(self.failed_tests)
+
+ filepath = os.path.join(outdir, "passed.data")
+ pathlib.Path(filepath).write_text(self.passed_tests)
+
+ # gather intermediate data for all tests
+ failed_data = sorted(glob.glob(os.path.join(OUTDIR, "*/failed.data")))
+ passed_data = sorted(glob.glob(os.path.join(OUTDIR, "*/passed.data")))
+
+ failed_tests = ""
+ passed_tests = ""
+
+ for filename in failed_data:
+ filepath = os.path.join(OUTDIR, filename)
+ failed_tests += pathlib.Path(filepath).read_text()
+ for filename in passed_data:
+ filepath = os.path.join(OUTDIR, filename)
+ passed_tests += pathlib.Path(filepath).read_text()
+
+ # write html for all tests
+ self.html = """
+<html>
+<head>
+ <title>Cycles Test Report</title>
+ <style>
+ img {{ image-rendering: pixelated; width: 256px; background-color: #000; }}
+ img.render {{
+ background-color: #fff;
+ background-image:
+ -moz-linear-gradient(45deg, #eee 25%, transparent 25%),
+ -moz-linear-gradient(-45deg, #eee 25%, transparent 25%),
+ -moz-linear-gradient(45deg, transparent 75%, #eee 75%),
+ -moz-linear-gradient(-45deg, transparent 75%, #eee 75%);
+ background-image:
+ -webkit-gradient(linear, 0 100%, 100% 0, color-stop(.25, #eee), color-stop(.25, transparent)),
+ -webkit-gradient(linear, 0 0, 100% 100%, color-stop(.25, #eee), color-stop(.25, transparent)),
+ -webkit-gradient(linear, 0 100%, 100% 0, color-stop(.75, transparent), color-stop(.75, #eee)),
+ -webkit-gradient(linear, 0 0, 100% 100%, color-stop(.75, transparent), color-stop(.75, #eee));
+
+ -moz-background-size:50px 50px;
+ background-size:50px 50px;
+ -webkit-background-size:50px 51px; /* override value for shitty webkit */
+
+ background-position:0 0, 25px 0, 25px -25px, 0px 25px;
+ }}
+ table td:first-child {{ width: 256px; }}
+ </style>
+ <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css">
+</head>
+<body>
+ <div class="container">
+ <br/>
+ <h1>Cycles Test Report</h1>
+ <br/>
+ <table class="table table-striped">
+ <thead class="thead-default">
+ <tr><th>Name</th><th>New</th><th>Reference</th><th>Diff</th>
+ </thead>
+ {}{}
+ </table>
+ <br/>
+ </div>
+</body>
+</html>
+ """ . format(failed_tests, passed_tests)
+
+ filepath = os.path.join(OUTDIR, "report.html")
+ pathlib.Path(filepath).write_text(self.html)
+
+ print_message("Report saved to: " + pathlib.Path(filepath).as_uri())
+
+ def relative_url(self, filepath):
+ relpath = os.path.relpath(filepath, OUTDIR)
+ return pathlib.Path(relpath).as_posix()
+
+ def add_test(self, filepath, error):
+ name = test_get_name(filepath)
+ name = name.replace('_', ' ')
+
+ old_img, ref_img, new_img, diff_img = test_get_images(filepath)
+
+ status = error if error else ""
+ style = """ style="background-color: #f99;" """ if error else ""
+
+ new_url = self.relative_url(new_img)
+ ref_url = self.relative_url(ref_img)
+ diff_url = self.relative_url(diff_img)
+
+ test_html = """
+ <tr{}>
+ <td><b>{}</b><br/>{}<br/>{}</td>
+ <td><img src="{}" onmouseover="this.src='{}';" onmouseout="this.src='{}';" class="render"></td>
+ <td><img src="{}" onmouseover="this.src='{}';" onmouseout="this.src='{}';" class="render"></td>
+ <td><img src="{}"></td>
+ </tr>""" . format(style, name, self.testname, status,
+ new_url, ref_url, new_url,
+ ref_url, new_url, ref_url,
+ diff_url)
+
+ if error:
+ self.failed_tests += test_html
+ else:
+ self.passed_tests += test_html
+
+
+def verify_output(report, filepath):
+ old_img, ref_img, new_img, diff_img = test_get_images(filepath)
+
+ # copy new image
+ if os.path.exists(new_img):
+ os.remove(new_img)
+ if os.path.exists(TEMP_FILE):
+ shutil.copy(TEMP_FILE, new_img)
+
+ update = os.getenv('CYCLESTEST_UPDATE')
+
+ if os.path.exists(ref_img):
+ # diff test with threshold
+ command = (
+ IDIFF,
+ "-fail", "0.016",
+ "-failpercent", "1",
+ ref_img,
+ TEMP_FILE,
+ )
+ try:
+ subprocess.check_output(command)
+ failed = False
+ except subprocess.CalledProcessError as e:
+ if VERBOSE:
+ print_message(e.output.decode("utf-8"))
+ failed = e.returncode != 1
+ else:
+ if not update:
+ return False
+
+ failed = True
+
+ if failed and update:
+ # update reference
+ shutil.copy(new_img, ref_img)
+ shutil.copy(new_img, old_img)
+ failed = False
+
+ # generate diff image
command = (
IDIFF,
- "-fail", "0.015",
- "-failpercent", "1",
- reference_image,
- TEMP_FILE,
+ "-o", diff_img,
+ "-abs", "-scale", "16",
+ ref_img,
+ TEMP_FILE
)
+
try:
subprocess.check_output(command)
- failed = False
except subprocess.CalledProcessError as e:
if VERBOSE:
- print(e.output.decode("utf-8"))
- failed = e.returncode != 1
- if failed:
- shutil.copy(TEMP_FILE, failed_image)
- elif os.path.exists(failed_image):
- os.remove(failed_image)
+ print_message(e.output.decode("utf-8"))
+
return not failed
-def run_test(filepath):
+def run_test(report, filepath):
testname = test_get_name(filepath)
spacer = "." * (32 - len(testname))
- print(testname, spacer, end="")
- sys.stdout.flush()
+ print_message(testname, 'SUCCESS', 'RUN')
+ time_start = time.time()
error = render_file(filepath)
+ status = "FAIL"
if not error:
- if verify_output(filepath):
- print("PASS")
- else:
+ if not verify_output(report, filepath):
error = "VERIFY"
- if error:
- print("FAIL", error)
+ time_end = time.time()
+ elapsed_ms = int((time_end - time_start) * 1000)
+ if not error:
+ print_message("{} ({} ms)" . format(testname, elapsed_ms),
+ 'SUCCESS', 'OK')
+ else:
+ if error == "NO_CYCLES":
+ print_message("Can't perform tests because Cycles failed to load!")
+ return error
+ elif error == "NO_START":
+ print_message('Can not perform tests because blender fails to start.',
+ 'Make sure INSTALL target was run.')
+ return error
+ elif error == 'VERIFY':
+ print_message("Rendered result is different from reference image")
+ else:
+ print_message("Unknown error %r" % error)
+ print_message("{} ({} ms)" . format(testname, elapsed_ms),
+ 'FAILURE', 'FAILED')
return error
+
def blend_list(path):
for dirpath, dirnames, filenames in os.walk(path):
for filename in filenames:
@@ -103,40 +377,54 @@ def blend_list(path):
filepath = os.path.join(dirpath, filename)
yield filepath
-
def run_all_tests(dirpath):
+ passed_tests = []
failed_tests = []
all_files = list(blend_list(dirpath))
all_files.sort()
+ report = Report(os.path.basename(dirpath))
+ print_message("Running {} tests from 1 test case." .
+ format(len(all_files)),
+ 'SUCCESS', "==========")
+ time_start = time.time()
for filepath in all_files:
- error = run_test(filepath)
+ error = run_test(report, filepath)
+ testname = test_get_name(filepath)
if error:
if error == "NO_CYCLES":
- print("Can't perform tests because Cycles failed to load!")
return False
elif error == "NO_START":
- print('Can not perform tests because blender fails to start.',
- 'Make sure INSTALL target was run.')
return False
- elif error == 'VERIFY':
- pass
- else:
- print("Unknown error %r" % error)
- testname = test_get_name(filepath)
failed_tests.append(testname)
+ else:
+ passed_tests.append(testname)
+ report.add_test(filepath, error)
+ time_end = time.time()
+ elapsed_ms = int((time_end - time_start) * 1000)
+ print_message("")
+ print_message("{} tests from 1 test case ran. ({} ms total)" .
+ format(len(all_files), elapsed_ms),
+ 'SUCCESS', "==========")
+ print_message("{} tests." .
+ format(len(passed_tests)),
+ 'SUCCESS', 'PASSED')
if failed_tests:
+ print_message("{} tests, listed below:" .
+ format(len(failed_tests)),
+ 'FAILURE', 'FAILED')
failed_tests.sort()
- print("\n\nFAILED tests:")
for test in failed_tests:
- print(" ", test)
- return False
- return True
+ print_message("{}" . format(test), 'FAILURE', "FAILED")
+
+ report.output()
+ return not bool(failed_tests)
def create_argparse():
parser = argparse.ArgumentParser()
parser.add_argument("-blender", nargs="+")
parser.add_argument("-testdir", nargs=1)
+ parser.add_argument("-outdir", nargs=1)
parser.add_argument("-idiff", nargs=1)
return parser
@@ -145,13 +433,21 @@ def main():
parser = create_argparse()
args = parser.parse_args()
- global BLENDER, ROOT, IDIFF
+ global COLORS
+ global BLENDER, TESTDIR, IDIFF, OUTDIR
global TEMP_FILE, TEMP_FILE_MASK, TEST_SCRIPT
global VERBOSE
+ if os.environ.get("CYCLESTEST_COLOR") is not None:
+ COLORS = COLORS_ANSI
+
BLENDER = args.blender[0]
- ROOT = args.testdir[0]
+ TESTDIR = args.testdir[0]
IDIFF = args.idiff[0]
+ OUTDIR = args.outdir[0]
+
+ if not os.path.exists(OUTDIR):
+ os.makedirs(OUTDIR)
TEMP = tempfile.mkdtemp()
TEMP_FILE_MASK = os.path.join(TEMP, "test")
@@ -161,7 +457,7 @@ def main():
VERBOSE = os.environ.get("BLENDER_VERBOSE") is not None
- ok = run_all_tests(ROOT)
+ ok = run_all_tests(TESTDIR)
# Cleanup temp files and folders
if os.path.exists(TEMP_FILE):
diff --git a/tests/python/pep8.py b/tests/python/pep8.py
index 0e6250f534b..dde4250f6aa 100644
--- a/tests/python/pep8.py
+++ b/tests/python/pep8.py
@@ -178,5 +178,6 @@ def main():
"--max-line-length=1000"
" '%s'" % f)
+
if __name__ == "__main__":
main()
diff --git a/tests/python/rna_info_dump.py b/tests/python/rna_info_dump.py
index c26d94a1246..da228e52652 100644
--- a/tests/python/rna_info_dump.py
+++ b/tests/python/rna_info_dump.py
@@ -127,5 +127,6 @@ def api_dump(use_properties=True, use_functions=True):
print("END")
+
if __name__ == "__main__":
api_dump()