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.
40 "wm.blenderplayer_start",
44 "help.operator_cheat_sheet",
45 "wm.keyconfig_test", # just annoying - but harmless
46 "wm.memory_statistics", # another annoying one
47 "console.*", # just annoying - but harmless
51 def filter_op_list(operators):
52 from fnmatch import fnmatchcase
55 for op_match in op_blacklist:
56 if fnmatchcase(op, op_match):
57 print(" skipping: %s (%s)" % (op, op_match))
61 operators[:] = [op for op in operators if is_op_ok(op[0])]
64 def run_ops(operators, setup_func=None, reset=True):
65 print("\ncontext:", setup_func.__name__)
67 for op_id, op in operators:
69 print(" operator:", op_id)
70 sys.stdout.flush() # in case of crash
72 # disable will get blender in a bad state and crash easy!
74 bpy.ops.wm.read_factory_settings()
78 for mode in {'EXEC_DEFAULT', 'INVOKE_DEFAULT'}:
83 #traceback.print_exc()
89 bpy.ops.wm.read_factory_settings()
93 def ctx_clear_scene(): # copied from batch_import.py
95 for scene in bpy.data.scenes:
96 for obj in scene.objects[:]:
97 scene.objects.unlink(obj)
100 # remove obdata, for now only worry about the startup scene
101 for bpy_data_iter in (bpy.data.objects, bpy.data.meshes, bpy.data.lamps, bpy.data.cameras):
102 for id_data in bpy_data_iter:
103 bpy_data_iter.remove(id_data)
106 def ctx_editmode_mesh():
107 bpy.ops.object.mode_set(mode='EDIT')
110 def ctx_editmode_mesh_extra():
111 bpy.ops.object.vertex_group_add()
112 bpy.ops.object.shape_key_add(from_mix=False)
113 bpy.ops.object.shape_key_add(from_mix=True)
114 bpy.ops.mesh.uv_texture_add()
115 bpy.ops.mesh.vertex_color_add()
116 bpy.ops.object.material_slot_add()
118 bpy.ops.object.mode_set(mode='EDIT')
121 def ctx_editmode_mesh_empty():
122 bpy.ops.object.mode_set(mode='EDIT')
123 bpy.ops.mesh.select_all(action='SELECT')
124 bpy.ops.mesh.delete()
127 def ctx_editmode_curves():
128 bpy.ops.curve.primitive_nurbs_circle_add()
129 bpy.ops.object.mode_set(mode='EDIT')
132 def ctx_editmode_curves_empty():
133 bpy.ops.curve.primitive_nurbs_circle_add()
134 bpy.ops.object.mode_set(mode='EDIT')
135 bpy.ops.curve.delete(type='ALL')
138 def ctx_editmode_surface():
139 bpy.ops.surface.primitive_nurbs_surface_torus_add()
140 bpy.ops.object.mode_set(mode='EDIT')
143 def ctx_editmode_mball():
144 bpy.ops.object.metaball_add()
145 bpy.ops.object.mode_set(mode='EDIT')
148 def ctx_editmode_text():
149 bpy.ops.object.text_add()
150 bpy.ops.object.mode_set(mode='EDIT')
153 def ctx_editmode_armature():
154 bpy.ops.object.armature_add()
155 bpy.ops.object.mode_set(mode='EDIT')
158 def ctx_editmode_armature_empty():
159 bpy.ops.object.armature_add()
160 bpy.ops.object.mode_set(mode='EDIT')
161 bpy.ops.armature.select_all(action='SELECT')
162 bpy.ops.armature.delete()
165 def ctx_editmode_lattice():
166 bpy.ops.object.add(type='LATTICE')
167 bpy.ops.object.mode_set(mode='EDIT')
168 # bpy.ops.object.vertex_group_add()
171 def ctx_object_empty():
172 bpy.ops.object.add(type='EMPTY')
175 def ctx_object_pose():
176 bpy.ops.object.armature_add()
177 bpy.ops.object.mode_set(mode='POSE')
178 bpy.ops.pose.select_all(action='SELECT')
181 def ctx_object_paint_weight():
182 bpy.ops.object.mode_set(mode='WEIGHT_PAINT')
185 def ctx_object_paint_vertex():
186 bpy.ops.object.mode_set(mode='VERTEX_PAINT')
189 def ctx_object_paint_sculpt():
190 bpy.ops.object.mode_set(mode='SCULPT')
193 def ctx_object_paint_texture():
194 bpy.ops.object.mode_set(mode='TEXTURE_PAINT')
197 def bpy_check_type_duplicates():
198 # non essential sanity check
199 bl_types = dir(bpy.types)
200 bl_types_unique = set(bl_types)
202 if len(bl_types) != len(bl_types_unique):
203 print("Error, found duplicates in 'bpy.types'")
204 for t in sorted(bl_types_unique):
205 tot = bl_types.count(t)
207 print(" '%s', %d" % (t, tot))
214 bpy_check_type_duplicates()
216 # bpy.ops.wm.read_factory_settings()
219 for mod_name in dir(bpy.ops):
220 mod = getattr(bpy.ops, mod_name)
221 for submod_name in dir(mod):
222 op = getattr(mod, submod_name)
223 operators.append(("%s.%s" % (mod_name, submod_name), op))
225 operators.sort(key=lambda op: op[0])
227 filter_op_list(operators)
229 # for testing, mix the list up.
233 #random.shuffle(operators)
235 # 2 passes, first just run setup_func to make sure they are ok
236 for operators_test in ((), operators):
237 # Run the operator tests in different contexts
238 run_ops(operators_test, setup_func=lambda: None)
239 run_ops(operators_test, setup_func=ctx_clear_scene)
241 run_ops(operators_test, setup_func=ctx_object_empty)
242 run_ops(operators_test, setup_func=ctx_object_pose)
243 run_ops(operators_test, setup_func=ctx_object_paint_weight)
244 run_ops(operators_test, setup_func=ctx_object_paint_vertex)
245 run_ops(operators_test, setup_func=ctx_object_paint_sculpt)
246 run_ops(operators_test, setup_func=ctx_object_paint_texture)
248 run_ops(operators_test, setup_func=ctx_editmode_mesh)
249 run_ops(operators_test, setup_func=ctx_editmode_mesh_extra)
250 run_ops(operators_test, setup_func=ctx_editmode_mesh_empty)
252 run_ops(operators_test, setup_func=ctx_editmode_armature)
253 run_ops(operators_test, setup_func=ctx_editmode_armature_empty)
255 run_ops(operators_test, setup_func=ctx_editmode_curves)
256 run_ops(operators_test, setup_func=ctx_editmode_curves_empty)
257 run_ops(operators_test, setup_func=ctx_editmode_surface)
259 run_ops(operators_test, setup_func=ctx_editmode_mball)
260 run_ops(operators_test, setup_func=ctx_editmode_text)
261 run_ops(operators_test, setup_func=ctx_editmode_lattice)
263 if not operators_test:
264 print("All setup functions run fine!")
266 print("Finished %r" % __file__)
268 if __name__ == "__main__":