diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/python/CMakeLists.txt | 2 | ||||
-rw-r--r-- | tests/python/collada/CMakeLists.txt | 65 | ||||
-rw-r--r-- | tests/python/collada/mesh/test_mesh_simple.py | 144 |
3 files changed, 211 insertions, 0 deletions
diff --git a/tests/python/CMakeLists.txt b/tests/python/CMakeLists.txt index e03d8c065e7..6419c3f36e2 100644 --- a/tests/python/CMakeLists.txt +++ b/tests/python/CMakeLists.txt @@ -616,3 +616,5 @@ if(WITH_ALEMBIC) --with-legacy-depsgraph=${WITH_LEGACY_DEPSGRAPH} ) endif() + +add_subdirectory(collada) diff --git a/tests/python/collada/CMakeLists.txt b/tests/python/collada/CMakeLists.txt new file mode 100644 index 00000000000..b42a91329f9 --- /dev/null +++ b/tests/python/collada/CMakeLists.txt @@ -0,0 +1,65 @@ +# ***** 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. +# +# Contributor(s): Jacques Beaurain. +# +# ***** END GPL LICENSE BLOCK ***** + +# --env-system-scripts allows to run without the install target. + +# Use '--write-blend=/tmp/test.blend' to view output + +# Some tests are interesting but take too long to run +# and don't give deterministic results +set(USE_EXPERIMENTAL_TESTS FALSE) + +set(TEST_SRC_DIR ${CMAKE_SOURCE_DIR}/../lib/tests) +set(TEST_OUT_DIR ${CMAKE_BINARY_DIR}/tests) + +# ugh, any better way to do this on testing only? +execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${TEST_OUT_DIR}) + +#~ if(NOT IS_DIRECTORY ${TEST_SRC_DIR}) +#~ message(FATAL_ERROR "CMake test directory not found!") +#~ endif() + +# all calls to blender use this +if(APPLE) + if(${CMAKE_GENERATOR} MATCHES "Xcode") + set(TEST_BLENDER_EXE_PARAMS --background -noaudio --factory-startup) + else() + set(TEST_BLENDER_EXE_PARAMS --background -noaudio --factory-startup --env-system-scripts ${CMAKE_SOURCE_DIR}/release/scripts) + endif() +else() + 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} ${TEST_BLENDER_EXE_PARAMS} ) + +# ------------------------------------------------------------------------------ +# GENERAL PYTHON CORRECTNESS TESTS +macro (COLLADA_TEST module test_name) + add_test( + NAME collada_${test_name} + COMMAND "$<TARGET_FILE:blender>" ${TEST_BLENDER_EXE_PARAMS} ${TEST_SRC_DIR}/collada/${module}/${test_name}.blend + --python ${CMAKE_CURRENT_LIST_DIR}/${module}/test_${test_name}.py -- + --testdir ${TEST_SRC_DIR}/collada/${module} + ) +endmacro() + +COLLADA_TEST(mesh mesh_simple) diff --git a/tests/python/collada/mesh/test_mesh_simple.py b/tests/python/collada/mesh/test_mesh_simple.py new file mode 100644 index 00000000000..4ef98fdc6b4 --- /dev/null +++ b/tests/python/collada/mesh/test_mesh_simple.py @@ -0,0 +1,144 @@ +#!/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 ##### +# +# Call as follows: +# python collada_mesh_simple.py --blender PATH_TO_BLENDER_EXE --testdir PATH_TO_SVN/lib/tests/collada/mesh +# +import sys +import bpy +import argparse +import functools +import shutil +import tempfile +import unittest +import difflib +import pathlib +from pathlib import Path + +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-collada-test') + #print("Using tempdir %s" % dirname) + 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 AbstractColladaTest(unittest.TestCase): + + @classmethod + def setUpClass(cls): + cls.testdir = pathlib.Path(args.testdir) + + def checkdae(self, reference, export): + """ + collada verifier checks if exported dae file is the same as reference dae + """ + + ref = open(reference) + exp = open(export) + diff=difflib.unified_diff(ref.readlines(), exp.readlines(), lineterm='', n=0) + ref.close() + exp.close() + + diff_count = 0; + for line in diff: + error = True + for prefix in ('---', '+++', '@@'): + # Ignore diff metadata + if line.startswith(prefix): + error=False + break + else: + # Ignore time stamps + for ignore in ('<created>', '<modified>', '<authoring_tool>'): + if line[1:].strip().startswith(ignore): + error=False + break + if error: + diff_count +=1 + print ("%s"%line.strip()) + + if diff_count > 0: + print("Generated file differs from reference") + print("reference: %s" % reference) + print("result : %s" % export) + + return diff_count == 0 + +class MeshExportTest(AbstractColladaTest): + @with_tempdir + def test_export_single_mesh(self, tempdir: pathlib.Path): + test = "mesh_simple_001" + reference_dae = self.testdir / Path("%s.dae" % test) + outfile = tempdir / Path("%s_out.dae" % test) + + bpy.ops.wm.collada_export(filepath="%s" % str(outfile), + check_existing=True, + filemode=8, + display_type="DEFAULT", + sort_method="FILE_SORT_ALPHA", + apply_modifiers=False, + export_mesh_type=0, + export_mesh_type_selection="view", + selected=False, + include_children=False, + include_armatures=False, + include_shapekeys=True, + deform_bones_only=False, + sampling_rate=0, + active_uv_only=False, + use_texture_copies=True, + triangulate=False, + use_object_instantiation=True, + use_blender_profile=True, + sort_by_name=False, + export_transformation_type=0, + export_transformation_type_selection="matrix", + export_texture_type=0, + export_texture_type_selection="mat", + open_sim=False, + limit_precision=False, + keep_bind_info=False) + + # Now check the resulting Collada file. + self.assertTrue(self.checkdae(reference_dae, outfile)) + +if __name__ == '__main__': + sys.argv = [__file__] + (sys.argv[sys.argv.index("--") + 1:] if "--" in sys.argv else []) + parser = argparse.ArgumentParser() + parser.add_argument('--testdir', required=True) + args, remaining = parser.parse_known_args() + unittest.main(argv=sys.argv[0:1]+remaining)
\ No newline at end of file |