1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
|
# ##### 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>
# semi-useful script, runs all operators in a number of different
# contexts, cheap way to find misc small bugs but is in no way a complete test.
#
# only error checked for here is a segfault.
import bpy
import sys
op_blacklist = (
"script.reload",
"export*.*",
"import*.*",
"*.save_*",
"*.read_*",
"*.open_*",
"*.link_append",
"render.render",
"*.*_export",
"*.*_import",
"wm.blenderplayer_start",
"wm.url_open",
"wm.doc_view",
"wm.path_open",
"help.operator_cheat_sheet",
"wm.keyconfig_test", # just annoying - but harmless
"wm.memory_statistics", # another annoying one
"console.*", # just annoying - but harmless
)
def filter_op_list(operators):
from fnmatch import fnmatchcase
def is_op_ok(op):
for op_match in op_blacklist:
if fnmatchcase(op, op_match):
print(" skipping: %s (%s)" % (op, op_match))
return False
return True
operators[:] = [op for op in operators if is_op_ok(op[0])]
def run_ops(operators, setup_func=None, reset=True):
print("\ncontext:", setup_func.__name__)
# first invoke
for op_id, op in operators:
if op.poll():
print(" operator:", op_id)
sys.stdout.flush() # in case of crash
# disable will get blender in a bad state and crash easy!
if reset:
bpy.ops.wm.read_factory_settings()
setup_func()
for mode in {'EXEC_DEFAULT', 'INVOKE_DEFAULT'}:
try:
op(mode)
except:
#import traceback
#traceback.print_exc()
pass
if not operators:
# run test
if reset:
bpy.ops.wm.read_factory_settings()
setup_func()
# contexts
def ctx_clear_scene(): # copied from batch_import.py
unique_obs = set()
for scene in bpy.data.scenes:
for obj in scene.objects[:]:
scene.objects.unlink(obj)
unique_obs.add(obj)
# remove obdata, for now only worry about the startup scene
for bpy_data_iter in (bpy.data.objects, bpy.data.meshes, bpy.data.lamps, bpy.data.cameras):
for id_data in bpy_data_iter:
bpy_data_iter.remove(id_data)
def ctx_editmode_mesh():
bpy.ops.object.mode_set(mode='EDIT')
def ctx_editmode_mesh_extra():
bpy.ops.object.vertex_group_add()
bpy.ops.object.shape_key_add(from_mix=False)
bpy.ops.object.shape_key_add(from_mix=True)
bpy.ops.mesh.uv_texture_add()
bpy.ops.mesh.vertex_color_add()
bpy.ops.object.material_slot_add()
# editmode last!
bpy.ops.object.mode_set(mode='EDIT')
def ctx_editmode_mesh_empty():
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.select_all(action='SELECT')
bpy.ops.mesh.delete()
def ctx_editmode_curves():
bpy.ops.curve.primitive_nurbs_circle_add()
bpy.ops.object.mode_set(mode='EDIT')
def ctx_editmode_curves_empty():
bpy.ops.curve.primitive_nurbs_circle_add()
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.curve.delete(type='ALL')
def ctx_editmode_surface():
bpy.ops.surface.primitive_nurbs_surface_torus_add()
bpy.ops.object.mode_set(mode='EDIT')
def ctx_editmode_mball():
bpy.ops.object.metaball_add()
bpy.ops.object.mode_set(mode='EDIT')
def ctx_editmode_text():
bpy.ops.object.text_add()
bpy.ops.object.mode_set(mode='EDIT')
def ctx_editmode_armature():
bpy.ops.object.armature_add()
bpy.ops.object.mode_set(mode='EDIT')
def ctx_editmode_armature_empty():
bpy.ops.object.armature_add()
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.armature.select_all(action='SELECT')
bpy.ops.armature.delete()
def ctx_editmode_lattice():
bpy.ops.object.add(type='LATTICE')
bpy.ops.object.mode_set(mode='EDIT')
# bpy.ops.object.vertex_group_add()
def ctx_object_empty():
bpy.ops.object.add(type='EMPTY')
def ctx_object_pose():
bpy.ops.object.armature_add()
bpy.ops.object.mode_set(mode='POSE')
bpy.ops.pose.select_all(action='SELECT')
def ctx_object_paint_weight():
bpy.ops.object.mode_set(mode='WEIGHT_PAINT')
def ctx_object_paint_vertex():
bpy.ops.object.mode_set(mode='VERTEX_PAINT')
def ctx_object_paint_sculpt():
bpy.ops.object.mode_set(mode='SCULPT')
def ctx_object_paint_texture():
bpy.ops.object.mode_set(mode='TEXTURE_PAINT')
def bpy_check_type_duplicates():
# non essential sanity check
bl_types = dir(bpy.types)
bl_types_unique = set(bl_types)
if len(bl_types) != len(bl_types_unique):
print("Error, found duplicates in 'bpy.types'")
for t in sorted(bl_types_unique):
tot = bl_types.count(t)
if tot > 1:
print(" '%s', %d" % (t, tot))
import sys
sys.exit(1)
def main():
bpy_check_type_duplicates()
# bpy.ops.wm.read_factory_settings()
import bpy
operators = []
for mod_name in dir(bpy.ops):
mod = getattr(bpy.ops, mod_name)
for submod_name in dir(mod):
op = getattr(mod, submod_name)
operators.append(("%s.%s" % (mod_name, submod_name), op))
operators.sort(key=lambda op: op[0])
filter_op_list(operators)
# for testing, mix the list up.
#operators.reverse()
#import random
#random.shuffle(operators)
# 2 passes, first just run setup_func to make sure they are ok
for operators_test in ((), operators):
# Run the operator tests in different contexts
run_ops(operators_test, setup_func=lambda: None)
run_ops(operators_test, setup_func=ctx_clear_scene)
# object modes
run_ops(operators_test, setup_func=ctx_object_empty)
run_ops(operators_test, setup_func=ctx_object_pose)
run_ops(operators_test, setup_func=ctx_object_paint_weight)
run_ops(operators_test, setup_func=ctx_object_paint_vertex)
run_ops(operators_test, setup_func=ctx_object_paint_sculpt)
run_ops(operators_test, setup_func=ctx_object_paint_texture)
# mesh
run_ops(operators_test, setup_func=ctx_editmode_mesh)
run_ops(operators_test, setup_func=ctx_editmode_mesh_extra)
run_ops(operators_test, setup_func=ctx_editmode_mesh_empty)
# armature
run_ops(operators_test, setup_func=ctx_editmode_armature)
run_ops(operators_test, setup_func=ctx_editmode_armature_empty)
# curves
run_ops(operators_test, setup_func=ctx_editmode_curves)
run_ops(operators_test, setup_func=ctx_editmode_curves_empty)
run_ops(operators_test, setup_func=ctx_editmode_surface)
# other
run_ops(operators_test, setup_func=ctx_editmode_mball)
run_ops(operators_test, setup_func=ctx_editmode_text)
run_ops(operators_test, setup_func=ctx_editmode_lattice)
if not operators_test:
print("All setup functions run fine!")
print("Finished %r" % __file__)
if __name__ == "__main__":
main()
|