-
-
Notifications
You must be signed in to change notification settings - Fork 1k
/
generator.py
executable file
·89 lines (75 loc) · 2.08 KB
/
generator.py
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
#!/usr/bin/env python
import os
import sys
import pickle
example_dir = '../../../examples/undocumented/python_modular'
test_dir = '../../../tests/integration/tests'
blacklist = ("__init__.py",
"classifier_libsvm_minimal_modular.py",
"classifier_multiclassocas_modular.py",
"modelselection_grid_search_kernel.py",
"serialization_string_kernels_modular.py",
"kernel_fisher_modular.py",
"kernel_top_modular.py",
"distribution_hmm_modular.py",
"kernel_director_linear_modular.py",
"features_director_dot_modular.py",
"evaluation_director_contingencytableevaluation_modular.py",
"distance_director_euclidean_modular.py"
)
def get_fname(mod_name, i):
return os.path.join(test_dir, mod_name + str(i) + '.txt')
def setup_tests(tests=[]):
os.chdir(example_dir)
if not len(tests):
tests = os.listdir(".")
tests.sort()
else:
tests = [ os.path.basename(t) for t in tests ]
sys.path.insert(0, '.')
return tests
def check_for_function(fname):
for l in file(fname).readlines():
if l.startswith("def "):
return True
return False
def get_test_mod(t):
if t.endswith(".py") and not t.startswith('.') and t not in blacklist:
mod_name = t[:-3]
if not check_for_function(t):
raise Exception("ERROR (no function)")
return __import__(mod_name), mod_name
def run_test(mod, mod_name, i):
fname = get_fname(mod_name, i)
par=mod.parameter_list[i]
a = getattr(mod, mod_name)(*par)
return a
def generator(tests):
for t in tests:
try:
mod, mod_name = get_test_mod(t)
except TypeError:
continue
except Exception, e:
print t, e
continue
fname = ""
print "%-60s" % mod_name,
#print "%+60s" % "...",
try:
for i in xrange(len(mod.parameter_list)):
fname = get_fname(mod_name, i)
a = run_test(mod, mod_name, i)
pickle.dump(a,file(fname, "w"))
print "OK"
except Exception, e:
print "ERROR generating '%s' using '%s'" % (fname,t)
print e
continue
if __name__=='__main__':
from optparse import OptionParser
op=OptionParser()
op.set_usage("[<file1> <file2> ...]")
(opts, args)=op.parse_args()
tests = setup_tests(args)
generator(tests)