-
Notifications
You must be signed in to change notification settings - Fork 3
/
aviconv.py
149 lines (123 loc) · 3 KB
/
aviconv.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
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
from xml.dom import minidom
# import HTML
import math
import jinja2
import re
import smtplib
import sys
from email.mime.text import MIMEText
import os
def amain(fn):
# print os.getcwd()
templateLoader = jinja2.FileSystemLoader( searchpath=os.getcwd() )
templateEnv = jinja2.Environment( loader=templateLoader )
TEMPLATE_FILE = "avinja.jinja"
template = templateEnv.get_template( TEMPLATE_FILE )
f1 = open(fn, 'r')
f2 = open('temp.xml', 'w')
for line in f1:
f2.write(line.replace('&#', ''))
f1.close()
f2.close()
all_list = []
slist = []
xmldoc = minidom.parse('temp.xml')
itemlist = xmldoc.getElementsByTagName('UnitTestResult')
testrun = xmldoc.getElementsByTagName('TestRun')
tid = testrun[0].attributes['id'].value
ru = testrun[0].attributes['runUser'].value
time = xmldoc.getElementsByTagName('Times')
st = time[0].attributes['start'].value
et = time[0].attributes['finish'].value
ey = xmldoc.getElementsByTagName('Counters')
trs = ey[0].attributes['total'].value
tps = ey[0].attributes['passed'].value
tfs = ey[0].attributes['failed'].value
absa = ey[0].attributes['aborted'].value
for s in itemlist:
temp = []
temp.append(s.attributes['testName'].value)
temp.append(s.attributes['outcome'].value)
all_list.append(temp)
junk = ['Junk','Junk']
all_list.append(junk)
# print all_list
cp = 0
tcount = 0
flist = []
i = ""
for l in all_list:
# for l in i:
# print l[0]
if i == "":
flist = []
temp = l[0]
# print "First time"
# print "l1 is:"
# print l[1]
if l[1] == 'Passed':
cp +=1
tcount+=1
else:
tcount+=1
i = "Avinash"
else:
if temp == l[0]:
if l[1] == 'Passed':
cp+=1
tcount+=1
else:
tcount+=1
else:
flist.append(temp)
# if cp == 0:
# if l[1] == 'Passed':
# cp+=1
# if i == "Avinash":
# pass
# else:
# tcount+=1
if tcount == 0:
tcount = 1
passper = math.ceil((float(cp)/tcount)*100)
flist.append(passper)
if passper == 0:
flist.append("ALERT")
elif passper >0 and passper < 50 :
flist.append("INVESTIGATE")
elif passper >49 and passper < 80 :
flist.append("COULD BE BETTER")
elif passper >80 or passper == 80:
flist.append("AWESOME")
else:
pass
flist.append(cp)
flist.append(tcount)
slist.append(flist)
cp = 0
tcount = 0
flist = []
temp = l[0]
if l[1] == 'Passed':
cp+=1
tcount+=1
# print slist
templateVars = { "title" : "Awesome Report",
"description" : "This report is generated by Murgi convertor",
"slist" : slist,
"id":tid,
"ru":ru,
"st":st,
"et":et,
"trs":trs,
"tps":tps,
"tfs":tfs,
"abs":absa
}
outputText = template.render( templateVars )
f = open('report1.html','w')
f.write(outputText)
f.close()
if __name__ == "__main__":
fileName = sys.argv[1]
amain(fileName)