Changeset View
Standalone View
tests/python/transform_operators.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> | |||||
| # To run all tests, use | |||||
| # BLENDER_VERBOSE=1 blender path/to/transform_regression.blend --python path/to/transform_operators.py -- --run-all-tests | |||||
| # To run one test, use | |||||
| # BLENDER_VERBOSE=1 blender path/to/transform_regression.blend --python path/to/transform_operators.py -- --run-test <index> | |||||
| # where <index> is the index of the test specified in the list tests. | |||||
| import bpy | |||||
| import os | |||||
| import sys | |||||
sybren: I've never seen this before, and I feel it's also a bit clunky. Most test frameworks use the… | |||||
Done Inline ActionsThis index is for internal use. The test name is "transform". This is the same as seen in modifier.py which has an API similar. mano-wii: This index is for internal use. The test name is `"transform"`.
This is the same as seen in… | |||||
Done Inline ActionsIf there is the need to manually add comments to a list to indicate the index of each item, that's an indication of a bad design. There is also a comment that explains how to use that index to run a single test, so it's not for internal use either. modifiers.py identifies tests by name, and not by index, so I don't really see your point. sybren: If there is the need to manually add comments to a list to indicate the index of each item… | |||||
Done Inline ActionsI may be seeing things, but I'm sure it used to be index. mano-wii: I may be seeing things, but I'm sure it used to be index.
I don't even know what the names of… | |||||
| from mathutils import Matrix | |||||
| sys.path.append(os.path.dirname(os.path.realpath(__file__))) | |||||
| from modules.mesh_test import TransformOperatorTest | |||||
| override_context = None | |||||
| def get_area(): | |||||
| for area in bpy.context.screen.areas: | |||||
| if area.type == 'VIEW_3D': | |||||
| return area | |||||
| raise | |||||
| def get_region_window(area): | |||||
| for region in area.regions: | |||||
| if region.type == 'WINDOW': | |||||
| return region | |||||
| raise | |||||
Done Inline ActionsWhat are "edit mode a" and "b"? What is being tested here? The way the test code is written, it's hard to see the difference between the "a" and "b" functions. sybren: What are "edit mode a" and "b"? What is being tested here? The way the test code is written… | |||||
| def get_rv3d(area): | |||||
| for space in area.spaces: | |||||
| if space.type == 'VIEW_3D': | |||||
| return space.region_3d | |||||
| raise | |||||
| def transform_default_settings_set(context): | |||||
| rv3d = get_rv3d(override_context['area']) | |||||
| if rv3d.view_perspective != 'CAMERA': | |||||
| bpy.ops.view3d.view_camera(override_context) | |||||
| scene = context.scene | |||||
| tool_settings = scene.tool_settings | |||||
| scene.transform_orientation_slots[0].type = 'GLOBAL' | |||||
| tool_settings.transform_pivot_point = 'MEDIAN_POINT' | |||||
| tool_settings.snap_elements = {'INCREMENT'} | |||||
| tool_settings.use_snap = False | |||||
| tool_settings.use_snap_grid_absolute = False | |||||
| tool_settings.use_snap_translate = True | |||||
| tool_settings.use_snap_rotate = False | |||||
| tool_settings.use_snap_scale = False | |||||
| tool_settings.use_proportional_edit_objects = False | |||||
| tool_settings.proportional_edit_falloff = 'SMOOTH' | |||||
| def transform_test_translate(context, index=None): | |||||
| tests_global = [ | |||||
| # 0 | |||||
| ['MyObject', 'MyObject_trans_global_object_expected', 'OBJECT', 'translate', (override_context,), {'value': (0,0,1), 'constraint_axis': (True,True,True)}], | |||||
sergeyUnsubmitted Done Inline ActionsI am sure you can make this more readable about what is the input, what is the expected expression. sergey: I am sure you can make this more readable about what is the input, what is the expected… | |||||
| # 1 | |||||
| ['MyObject', 'MyObject_trans_global_edit_expected', 'EDIT', 'translate', (override_context,), {'value': (0,0,1), 'constraint_axis': (True,True,True)}], | |||||
| # 2 | |||||
| ['MyObject', 'MyObject_trans_global_edit_expected', 'EDIT', 'translate', (override_context,), {'value': (0,0,1), 'orient_type': 'GLOBAL', 'constraint_axis': (True,True,True)}], | |||||
| ] | |||||
| tests_local = [ | |||||
| # 0 (3) | |||||
| ['MyObject_transformed', 'MyObject_trans_local_object_expected', 'OBJECT', 'translate', (override_context,), {'value': (0,0,1), 'constraint_axis': (True,True,True)}], | |||||
| # 1 (4) | |||||
| ['MyObject_transformed', 'MyObject_trans_local_edit_expected', 'EDIT', 'translate', (override_context,), {'value': (0,0,1), 'constraint_axis': (True,True,True)}], | |||||
| # 2 (5) | |||||
| ['MyObject_transformed', 'MyObject_trans_local_edit_expected', 'EDIT', 'translate', (override_context,), {'value': (0,0,1), 'orient_type': 'LOCAL', 'constraint_axis': (True,True,True)}], | |||||
| # 3 (6) | |||||
| ['MyObject_transformed', 'MyObject_rot_local_object_expected', 'OBJECT', 'rotate', (override_context,), {'value': 1.5708, 'constraint_axis': (False,False,True)}], | |||||
| # 4 (7) | |||||
| ['MyObject_transformed', 'MyObject_rot_local_object_expected', 'OBJECT', 'rotate', (override_context,), {'value': 1.5708, 'orient_type':'LOCAL', 'constraint_axis': (False,False,True)}], | |||||
| ] | |||||
| tests_view = [ | |||||
| # 0 (8) | |||||
| # ['MyObject', 'MyObject_rot_view_object_expected_0', 'OBJECT', 'rotate', (override_context,), {'value': 1.5708}], | |||||
| # 1 (9) | |||||
| ['MyObject', 'MyObject_rot_view_object_expected_1', 'OBJECT', 'rotate', (override_context,), {'value': 1.5708, 'orient_type': 'NORMAL', 'orient_matrix_type': 'NORMAL', \ | |||||
| 'orient_matrix': ((0.9079387784004211,-0.17976072430610657,0.3785933554172516), (0.4191024899482727,0.3894294500350952,-0.8201814889907837), (-9.983776863009552e-07,-0.9033441543579102,-0.428916335105896))}], | |||||
| ] | |||||
| tests_normal = [ | |||||
| # 0 (10) | |||||
| ['MyObject_transformed', 'MyObject_rot_normal_edit_individual_orig_expected', 'EDIT', 'rotate', (override_context,), {'value': 0.785398, 'constraint_axis': (False,False,True)}], | |||||
| # 1 (11) | |||||
| ['MyObject_transformed', 'MyObject_rot_normal_edit_individual_orig_expected', 'EDIT', 'rotate', (override_context,), {'value': 0.785398, 'orient_type': 'NORMAL', 'constraint_axis': (False,False,True)}], | |||||
| # 2 (12) | |||||
| ['MyObject_transformed', 'MyObject_rot_normal_edit_individual_orig_expected', 'EDIT', 'rotate', (override_context,), {'value': 0.785398, 'constraint_axis': (False,False,True), 'orient_type': 'NORMAL', \ | |||||
| 'orient_matrix_type': 'NORMAL', 'orient_matrix': ((1,0,0), (0,1,0), (0,0,1))}], | |||||
| ] | |||||
| transform_default_settings_set(context) | |||||
| scene = context.scene | |||||
| if index is not None: | |||||
| if index < len(tests_global): | |||||
| operator_test = TransformOperatorTest(tests_global) | |||||
| #scene.transform_orientation_slots[0].type = 'GLOBAL' | |||||
| operator_test.run_test(index) | |||||
| return | |||||
| index -= len(tests_global) | |||||
| if index < len(tests_local): | |||||
| operator_test = TransformOperatorTest(tests_local) | |||||
| scene.transform_orientation_slots[0].type = 'LOCAL' | |||||
| operator_test.run_test(index) | |||||
| return | |||||
| index -= len(tests_local) | |||||
| if index < len(tests_view): | |||||
| operator_test = TransformOperatorTest(tests_view) | |||||
| scene.transform_orientation_slots[0].type = 'VIEW' | |||||
| operator_test.run_test(index) | |||||
| return | |||||
| index -= len(tests_view) | |||||
| if index < len(tests_normal): | |||||
| operator_test = TransformOperatorTest(tests_normal) | |||||
| scene.transform_orientation_slots[0].type = 'NORMAL' | |||||
| scene.tool_settings.transform_pivot_point = 'INDIVIDUAL_ORIGINS' | |||||
| operator_test.run_test(index) | |||||
| return | |||||
| else: | |||||
| operator_test_global = TransformOperatorTest(tests_global) | |||||
| operator_test_local = TransformOperatorTest(tests_local) | |||||
| operator_test_view = TransformOperatorTest(tests_view) | |||||
| # operator_test_normal = TransformOperatorTest(tests_normal) | |||||
| #scene.transform_orientation_slots[0].type = 'GLOBAL' | |||||
| operator_test_global.run_all_tests() | |||||
| scene.transform_orientation_slots[0].type = 'LOCAL' | |||||
| operator_test_local.run_all_tests() | |||||
| scene.transform_orientation_slots[0].type = 'VIEW' | |||||
| operator_test_view.run_all_tests() | |||||
| # scene.transform_orientation_slots[0].type = 'NORMAL' | |||||
| # scene.tool_settings.transform_pivot_point = 'INDIVIDUAL_ORIGINS' | |||||
| # operator_test_normal.run_all_tests() | |||||
| def main(): | |||||
| global override_context | |||||
| context = bpy.context | |||||
| area = get_area() | |||||
| region = get_region_window(area) | |||||
| override_context = {'area':area, 'region':region} | |||||
| index = None | |||||
| command = list(sys.argv) | |||||
| for i, cmd in enumerate(command): | |||||
| if cmd == "--run-all-tests": | |||||
| break | |||||
| elif cmd == "--run-test": | |||||
| index = int(command[i + 1]) | |||||
| break | |||||
| transform_test_translate(context, index=index) | |||||
| if __name__ == "__main__": | |||||
| try: | |||||
| main() | |||||
| except: | |||||
| import traceback | |||||
| traceback.print_exc() | |||||
| sys.exit(1) | |||||
Done Inline ActionsWhy isn't this using argparse instead? sybren: Why isn't this using `argparse` instead? | |||||
Done Inline ActionsWhat does this do? sybren: What does this do? | |||||
Done Inline ActionsRemoved because it was not meant to be set here. mano-wii: Removed because it was not meant to be set here.
This environment variable is used in some… | |||||
I've never seen this before, and I feel it's also a bit clunky. Most test frameworks use the name of the test, and not its index.