1 # ##### BEGIN GPL LICENSE BLOCK #####
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software Foundation,
15 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 # ##### END GPL LICENSE BLOCK #####
21 # semi-useful script, runs all operators in a number of different
22 # contexts, cheap way to find misc small bugs but is in no way a complete test.
24 # only error checked for here is a segfault.
43 "help.operator_cheat_sheet",
47 def filter_op_list(operators):
48 from fnmatch import fnmatchcase
51 for op_match in op_blacklist:
52 if fnmatchcase(op, op_match):
53 print(" skipping: %s (%s)" % (op, op_match))
57 operators[:] = [op for op in operators if is_op_ok(op[0])]
60 def run_ops(operators, setup_func=None):
61 print("\ncontext:", setup_func.__name__)
63 for op_id, op in operators:
65 print(" operator:", op_id)
66 sys.stdout.flush() # incase of crash
68 # disable will get blender in a bad state and crash easy!
69 bpy.ops.wm.read_factory_settings()
73 for mode in ('EXEC_DEFAULT', 'INVOKE_DEFAULT'):
78 #traceback.print_exc()
83 def ctx_clear_scene(): # copied from batch_import.py
85 for scene in bpy.data.scenes:
86 for obj in scene.objects[:]:
87 scene.objects.unlink(obj)
90 # remove obdata, for now only worry about the startup scene
91 for bpy_data_iter in (bpy.data.objects, bpy.data.meshes, bpy.data.lamps, bpy.data.cameras):
92 for id_data in bpy_data_iter:
93 bpy_data_iter.remove(id_data)
96 def ctx_editmode_mesh():
97 bpy.ops.object.mode_set(mode='EDIT')
98 bpy.ops.object.vertex_group_add()
101 def ctx_editmode_curves():
102 bpy.ops.curve.primitive_nurbs_circle_add()
103 bpy.ops.object.mode_set(mode='EDIT')
106 def ctx_editmode_surface():
107 bpy.ops.surface.primitive_nurbs_surface_torus_add()
108 bpy.ops.object.mode_set(mode='EDIT')
111 def ctx_editmode_mball():
112 bpy.ops.object.metaball_add()
113 bpy.ops.object.mode_set(mode='EDIT')
116 def ctx_editmode_text():
117 bpy.ops.object.text_add()
118 bpy.ops.object.mode_set(mode='EDIT')
121 def ctx_editmode_armature():
122 bpy.ops.object.armature_add()
123 bpy.ops.object.mode_set(mode='EDIT')
126 def ctx_editmode_lattice():
127 bpy.ops.object.add(type='LATTICE')
128 bpy.ops.object.mode_set(mode='EDIT')
129 # bpy.ops.object.vertex_group_add()
132 def ctx_object_empty():
133 bpy.ops.object.add(type='EMPTY')
136 def ctx_weightpaint():
137 bpy.ops.object.mode_set(mode='WEIGHT_PAINT')
141 # bpy.ops.wm.read_factory_settings()
144 for mod_name in dir(bpy.ops):
145 mod = getattr(bpy.ops, mod_name)
146 for submod_name in dir(mod):
147 op = getattr(mod, submod_name)
148 operators.append(("%s.%s" % (mod_name, submod_name), op))
150 operators.sort(key=lambda op: op[0])
152 filter_op_list(operators)
154 # for testing, mix the list up.
158 #random.shuffle(operators)
160 # Run the operator tests in different contexts
161 run_ops(operators, setup_func=lambda: None)
162 run_ops(operators, setup_func=ctx_editmode_surface)
163 run_ops(operators, setup_func=ctx_object_empty)
164 run_ops(operators, setup_func=ctx_editmode_armature)
165 run_ops(operators, setup_func=ctx_editmode_mesh)
166 run_ops(operators, setup_func=ctx_clear_scene)
167 run_ops(operators, setup_func=ctx_editmode_curves)
168 run_ops(operators, setup_func=ctx_editmode_mball)
169 run_ops(operators, setup_func=ctx_editmode_text)
170 run_ops(operators, setup_func=ctx_weightpaint)
171 run_ops(operators, setup_func=ctx_editmode_lattice)
175 if __name__ == "__main__":