Changeset View
Changeset View
Standalone View
Standalone View
tests/python/boolean_operator.py
- This file was added.
| # ##### 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 bpy | |||||
| import os | |||||
| import pathlib | |||||
| import sys | |||||
| import importlib | |||||
| blend_dir = pathlib.Path(bpy.data.filepath) | |||||
| test_dir = blend_dir.parent.parent.parent.parent/"blender"/"tests"/"python"/"modules" | |||||
| if str(test_dir) not in sys.path: | |||||
| sys.path.append(str(test_dir)) | |||||
| import mesh_test | |||||
| importlib.reload(mesh_test) | |||||
| from mesh_test import MeshTest, OperatorSpec | |||||
| def main(): | |||||
| tests = [ | |||||
| ['FACE', {0, 1, 2, 3, 4, 5}, 'Cubecube', 'Cubecube_result_1', 'intersect_boolean', {'operation': 'UNION'}], | |||||
| ['FACE', {0, 1, 2, 3, 4, 5}, 'Cubecube', 'Cubecube_result_2', 'intersect_boolean', {'operation': 'INTERSECT'}], | |||||
| ['FACE', {0, 1, 2, 3, 4, 5}, 'Cubecube', 'Cubecube_result_3', 'intersect_boolean', {'operation': 'DIFFERENCE'}], | |||||
| ['FACE', {0, 1, 2, 3, 4, 5}, 'Cubecube', 'Cubecube_result_4', 'intersect', {'separate_mode': 'CUT'}], | |||||
| ['FACE', {0, 1, 2, 3, 4, 5}, 'Cubecube', 'Cubecube_result_5', 'intersect', {'separate_mode': 'ALL'}], | |||||
| ['FACE', {0, 1, 2, 3, 4, 5}, 'Cubecube', 'Cubecube_result_6', 'intersect', {'separate_mode': 'NONE'}], | |||||
| ['FACE', {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, 'Cubecube', 'Cubecube_result_7', 'intersect', | |||||
| {'mode': 'SELECT', 'separate_mode': 'NONE'}], | |||||
| ['FACE', {6, 7, 8, 9, 10}, 'Cubecone', 'Cubecone_result_1', 'intersect_boolean', {'operation': 'UNION'}], | |||||
| ['FACE', {0, 1, 2, 3, 4, 5}, 'Cubecones', 'Cubecones_result_1', 'intersect_boolean', {'operation': 'UNION'}], | |||||
| ] | |||||
| for case in tests: | |||||
| select_mode = case[0] | |||||
| selection = case[1] | |||||
| test_object_name = case[2] | |||||
| expected_object_name = case[3] | |||||
| operator_name = case[4] | |||||
| operator_parameters = case[5] | |||||
| operator_spec = OperatorSpec(operator_name, operator_parameters, select_mode, selection) | |||||
| test = MeshTest(test_object_name, expected_object_name) | |||||
| test.add_operator(operator_spec) | |||||
| success = test.run_test() | |||||
| if test.is_test_updated(): | |||||
| # run the test again if the blend file has been updated | |||||
| success = test.run_test() | |||||
| if not success: | |||||
| raise Exception("Test failed.") | |||||
| if __name__ == "__main__": | |||||
| try: | |||||
| main() | |||||
| except: | |||||
| import traceback | |||||
| traceback.print_exc() | |||||
| sys.exit(1) | |||||