parameters
[imago.git] / test / html_results.py
1 #!/usr/bin/env python
2
3 import sys
4 import pickle
5
6 print "<html>"
7 print "<head>"
8 print "<style>"
9 print "table {border-collapse: collapse; table-layout: fixed;}"
10 print "td {border-style: solid; border-width: 1px; border-color: grey;}"
11 print "</style>"
12 print "</head>"
13
14 print "<body>"
15
16 print "<h1>Imago test</h1>"
17
18 print "<pre>"
19
20 res = pickle.load(open(sys.argv[1], 'r'))
21
22 total = len(res)
23
24 failed = [(name,error) for (name, time, output, error, r_code) in res
25           if r_code > 0]
26 print "failed tests:", str(len(failed)) + '/' + str(total)
27
28 for (name, error) in failed:
29     print "    ", name
30
31 print ""
32
33 n = 0
34 t = 0
35 correct = 0
36
37 for (name, time, output, error, r_code) in res:
38     if r_code > 0:
39         continue
40     n += 1
41     t += time
42     ref = open(name.split('.')[0] + '.txt').read()
43     if output == ref:
44         correct += 1
45     else:
46         #TODO find and record the error
47         pass
48
49 print "average runtime:", (t/n)
50 print "correct:", str(correct) + '/' + str(n)
51
52 print "</pre>"
53
54 for (name, time, output, error, r_code) in res:
55     print "<div>"
56     print "<h2>" + name + "</h2>"
57     print "<image src=\"" + name + "\" width=\"600\" style=\"float: right;\" />"
58     print "<table>"
59     output = output.split('\n')
60     correct = open(name[:-4]+".txt").readlines()
61     output = map(lambda s: s.split(), output)
62     correct = map(lambda s: s.split(), correct)
63     for i in range(len(output)):
64         print "<tr>"
65         for j in range(len(output[i])):
66             if output[i][j] == correct[i][j]:
67                 print "<td><div style=\"width: 15px\" >{}</td>".format(output[i][j])
68             else:
69                 print "<td><div style=\"background-color: red; \
70                       width: 15px\">{}</td>".format(output[i][j])
71         print "</tr>"
72     print "</table>"
73     print "<div style=\"clear: both;\"></div>"
74     print "</div>"
75
76 print "</body>"
77 print "</html>"