summaryrefslogtreecommitdiff
path: root/tests/cakebaby.py
blob: a58b6bc5fd46de3b8789e1fcc80b1b913325d339 (plain)
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
#!/usr/bin/python
import string,platform,sys,re,os

wiki_basepath = 'OpenSCAD'
platform = 'ubuntu linux i686'.replace(' ','_') + '_abcd'
logfilename = 'LastTest.log.tmp'
builddir = 'build'
logpath = os.path.join(builddir,'Testing','Temporary',logfilename)
NO_END = False
if logfilename.endswith('.tmp'): NO_END = True

def readlog():
	try:
		print 'reading',logpath
		f = open(logpath)
	except:
		print 'couldnt open ',logpath
		return None

	data = f.read()
	return data

class Test:
	def __init__(self,fullname,time,passed,output,type,outputfile,expectedfile):
		self.fullname,self.time,self.passed,self.output = \
			fullname, time, passed, output
		self.type = type
		self.outputfile = outputfile
		self.expectedfile = expectedfile

	def __str__(self):
		x = 'fullname: ' + self.fullname
		x+= '\noutputfile: ' + self.outputfile
		x+= '\nexpectedfile: ' + self.expectedfile
		x+= '\ntesttime: ' + self.time
		x+= '\ntesttype: ' + self.type
		x+= '\npassfail: ' + self.passfail
		x+= '\noutput: \n' + self.output
		x+= '\n'
		return x

def gettest_strings(data):
	chunks = data.split('----------------------------------------------------------')
	print 'read',len(chunks), 'chunks'
	if NO_END:
		enddate = 'n/a (cancelled)'
		chunks.pop()
	else:
		enddate = chunks.pop().replace('End testing: ','').strip()
	chunks.reverse()
	startdate = chunks.pop().replace('Start testing: ','').strip()
	chunks.reverse()
	tests=[]
	chunksize = 3
	for i in range(0,len(chunks),chunksize):
		testchunks = chunks[i:i+chunksize]
		test = string.join(testchunks,'-----')
		tests += [test]
		#print '----------<<<<<<<<<<<<<<<<'
		#print test
		#print '----------<<<<<<<<<<<<<<<<'
		test = ''
	return startdate, tests, enddate, platform

def parsetest(teststring):
	s = teststring
	def regex(pat,str):
		x=re.search(pat,str,re.DOTALL|re.MULTILINE)
		if x: 
			if len(x.groups())>0: 
				return x.group(1).strip()
		return ''
	testfullname = regex("Test:(.*?)\n",s)
	testtime = regex("Test time =(.*?)\n",s).replace(' sec','')
	passfail = regex("Test time.*?Test (Passed)",s)
	command = regex("Command:(.*?)\n",s)
	tmp = command.split(' "')
	testtype = ''
	try:
		testtype = tmp[3].strip('"')
	except:
		print 'failed to parse log', teststring
	goodimg = regex("expected image:(.*?)\n",s)
	actualimg = regex("actual image:(.*?)\n",s)
	if passfail=='Passed': passed = True
	else: passed = False
	output = regex("Output:(.*?)<end of output>",s).replace('-----','')
	test = Test(testfullname, testtime, passed, output, testtype, actualimg, goodimg )
	return test

def parse(data):
	startdate, test_strs, enddate, platform = gettest_strings(data)
	print 'found', len(test_strs),'test results'
	tests = []
	for i in range(len(test_strs)):
		test = parsetest(test_strs[i])
		tests += [test]
	return startdate, tests, enddate, platform

def towiki(startdate, tests, enddate, platform):
	def convert_path(fulltestname,platform,path):
		# convert system path name (image file) to wiki path name
		testprogram = fulltestname[0:fulltestname.find('_')]
		testprogram = testprogram.replace('test','')
		filename = os.path.basename(path)
		filename = filename.replace('-actual','')
		filename = filename.replace('-tests','')
		filename = filename.replace('-expected','')
		try:
			platform = platform[0].upper() + platform[1:]
		except:
			platform = 'error'
		newpath = testprogram + '_' + filename
		# must use _ not / b/c of wikinet.org weird name mangling
		newpath = wiki_basepath + '_' + platform + '_' + newpath
		return newpath
		
	x='''
<h3>OpenSCAD test run</h3>

platform: PLATFORM

runtime: STARTDATE to ENDDATE

Failed tests

{|TABLESTYLE
! Testname !! expected output !! actual output
|-
| FTESTNAME || [[File:EXPECTEDIMG|thumb|250px]] || [[File:ACTUALIMG|thumb|250px]]
|}

Passed tests

{|TABLESTYLE 
! Testname 
|-
| PTESTNAME
|}

'''

	repeat1='''
|-
| FTESTNAME || [[File:EXPECTEDIMG|thumb|250px]] || [[File:ACTUALIMG|thumb|250px]]
'''

	repeat2='''
|-
| PTESTNAME
'''

	x = x.replace('TABLESTYLE','border=1 cellspacing=0 cellpadding=1 align="center"')
	x = x.replace('STARTDATE',startdate)
	x = x.replace('ENDDATE',enddate)
	x = x.replace('PLATFORM',platform)

	for t in tests:
		if t.passed:
			tmp = str(repeat2)
			tmp = tmp.replace('PTESTNAME',t.fullname)
			x = x.replace(repeat2,tmp + repeat2)
		else:
			tmp = str(repeat1)
			tmp = tmp.replace('FTESTNAME',t.fullname)
			wiki_imgpath1 = convert_path(t.fullname,'expected',t.expectedfile)
			tmp = tmp.replace('EXPECTEDIMG',wiki_imgpath1)
			wiki_imgpath2 = convert_path(t.fullname,platform,t.outputfile)
			tmp = tmp.replace('ACTUALIMG',wiki_imgpath2)
			x = x.replace(repeat1,tmp + repeat1)

	x = x.replace(repeat1,'')
	x = x.replace(repeat2,'')
	return x

def testsort(tests):
	passed = []
	failed = []
	for t in tests:
		if t.passed: passed+=[t]
		else: failed +=[t]
	return failed+passed

def save(data,filename):
	try:
		f=open(filename,'w')
	except:
		print 'couldnt open ',filename, 'for writing'
		return None
	print 'writing',len(data),'bytes to',filename
	f.write(data)
	f.close()

def main():
	data = readlog()
	startdate, tests, enddate, platform = parse(data)
	tests = testsort(tests)
	out = towiki(startdate, tests, enddate, platform)
	save(out, platform+'.wiki')

main()

contact: Jan Huwald // Impressum