-
Notifications
You must be signed in to change notification settings - Fork 65
Expand file tree
/
Copy pathtest_script_for_py.py
More file actions
117 lines (112 loc) · 4.04 KB
/
test_script_for_py.py
File metadata and controls
117 lines (112 loc) · 4.04 KB
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
import vcs, sys, os
def attrCompare(old_dict, new_dict):
if old_dict.keys() != new_dict.keys():
return (False, "keys mismatch")
for key in old_dict.keys():
if old_dict[key] == new_dict[key]:
continue
elif type(old_dict[key]) is tuple:
l = list(old_dict[key])
if l == new_dict[key]:
continue
else:
return (False, key + "not equal.")
return (True, "All values equal")
# graphics method list
gms = ["boxfill", "meshfill", "isofill", "vector", "isoline", "1d", "taylordiagram", "3d_scalar", "3d_dual_scalar",
"3d_vector"]
for obj in gms:
s = vcs.creategraphicsmethod(obj, 'default', 'test_%s' % obj)
s_dict = vcs.dumpToDict(s)[0]
scr = obj + "_script.py"
try:
s.script(scr)
except:
print "Python script creation broke on " + obj + ".script()"
sys.exit(1)
else:
# script was written successfully, now test for accuracy when it's run
# remove the object, or scriptrun() will just use the same thing
vcs.removeobject(s)
try:
vcs.scriptrun(scr) # test to see that scriptrun actually runs
except:
print "Scriptrun broke on " + obj
os.remove(scr)
sys.exit(1)
else:
# script has both written and run without failure, just need to check for accuracy
try:
new_s = vcs.getgraphicsmethod(obj, "test_%s" % obj)
except:
print "Scriptrun failed: test_%s does not exist" %obj
sys.exit(1)
else:
new_s_dict = vcs.dumpToDict(new_s)[0]
comp = attrCompare(s_dict, new_s_dict)
if not comp[0]:
print "Scriptrun failed: " + comp[1]
sys.exit(1)
if os.path.exists(scr):
os.remove(scr)
# text objects
tt = vcs.createtexttable('test_tt')
to = vcs.createtextorientation('test_tto')
tcs = vcs.listelements('textcombined')
if len(tcs) == 0:
tc = vcs.createtext(Tt_name="testtext", Tt_source=tt.name, To_name="testtext", To_source=to.name)
else:
tc = vcs.gettext(tcs[0])
# other secondaries
fa = vcs.createfillarea('test_fillarea')
ma = vcs.createmarker('test_marker')
li = vcs.createline('test_line')
secondaries = [tt, to, tc, fa, ma, li]
for sec in secondaries:
scr = sec.s_name + '_script.py'
old_dict = vcs.dumpToDict(sec)[0]
try:
sec.script(scr)
except:
print "Python script creation broke on " + sec.s_name + ".script()"
sys.exit(1)
else:
vcs.removeobject(sec)
try:
vcs.scriptrun(scr) # test to see that scriptrun actually runs
except:
print "Scriptrun broke on " + sec.s_name
os.remove(scr)
sys.exit(1)
else:
if sec.s_name == 'To':
getfunc = vcs.gettextorientation
elif sec.s_name == 'Tt':
getfunc = vcs.gettexttable
elif sec.s_name == 'Tc':
getfunc = (vcs.gettext, "testtext", "testtext")
elif sec.s_name == 'Tm':
getfunc = vcs.getmarker
elif sec.s_name == 'Tf':
getfunc = vcs.getfillarea
else:
getfunc = vcs.getline
# script has both written and run without failure, just need to check for accuracy
try:
if type(getfunc) is tuple:
new_sec = getfunc[0](getfunc[1], getfunc[2])
else:
new_sec = getfunc(sec.name)
except:
print "Scriptrun failed: %s does not exist" % sec.name
sys.exit(1)
else:
new_dict = vcs.dumpToDict(new_sec)[0]
comp = attrCompare(old_dict, new_dict)
if comp[0]:
print comp[1] + " for " + sec.s_name
else:
print "Scriptrun failed: " + comp[1]
sys.exit(1)
if os.path.exists(scr):
os.remove(scr)