-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisplayResults.py
105 lines (81 loc) · 1.99 KB
/
displayResults.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
# TestCase class
# contains setup lines and result line
class TestCase:
setup = []
result = 0
def __init__(self):
self.setup = []
self.result = 0
# Loads current test cases
f_testCases = open('testCases.ml', 'r')
# Read all the lines in the file
allLines = []
line = f_testCases.readline()
while line : # read each line
if line != '\n' :
line = line.rstrip() #remove \n
allLines.append(line)
#print(line)
line = f_testCases.readline()
# Parse all the lines into testCaseList
testCaseList = [];
x = TestCase()
for i in allLines :
if i == '\n': #just a line
continue
else :
#print("Check: " + i)
if i.startswith("- :") : # Case result, save to result, start new testCase
x.result = i
#print i
# start new testcase
testCaseList.append(x)
x = TestCase()
else :
#print(i)
i = i.replace("<", "<")
i = i.replace(">", ">")
x.setup.append(i) # Save line to display
# read in the test outputs
# display it in colors, along with testCases
f_output = open('testOutput.txt')
line = f_output.readline()
testResults = []
while line : # read each line
testResults.append(line)
#print(line)
line = f_output.readline()
# Write to HTML with formatting
f_out = open('testResults.html', 'w')
testGen_init = """
<html>
<head><title>Test Results</title></head>
<body>
<h2> Test Results </h2>
"""
testGen_mid = ""
f_out.write(testGen_init)
#print(len(testResults))
# Apply green for success, red for fail
for i in range(len(testResults)):
cur = ""
color = "Blue"
if "Success" in testResults[i]:
color = "Green"
elif "Failed" in testResults[i]:
color = "Red"
cur += "<pre style='color:" + color + "'>\n"
cur += "<strong>" + testResults[i].rstrip() + "</strong>"
for j in range(len(testCaseList[i].setup)):
cur += " " + testCaseList[i].setup[j] + "\n"
cur += " " + testCaseList[i].result;
cur += "\n</pre>\n";
testGen_mid += cur
testGen_mid += "\n"
f_out.write(testGen_mid)
testGen_end = """
</body>
"""
f_out.write(testGen_end)
f_testCases.close()
f_out.close()