1 # Copyright (C) 2010, Thomas Leonard
2 # Visit http://0install.net for details.
4 from zeroinstall
.injector
import iface_cache
6 def format_combo(combo
):
8 for iface
, version
in combo
.iteritems():
9 this_combo
.append("%s v%s" % (iface
.get_name(), version
))
10 return ', '.join(this_combo
)
12 def print_summary(results
):
15 for label
in ["passed", "skipped", "failed"]:
16 results_for_status
= results
.by_status
[label
]
17 if not results_for_status
:
20 print label
.capitalize()
21 for combo
in results_for_status
:
22 if isinstance(combo
, Exception):
23 print " - " + unicode(combo
)
25 print " - " + format_combo(combo
)
27 def format_html(results
):
30 from xml
.dom
import minidom
31 impl
= minidom
.getDOMImplementation()
32 doctype
= impl
.createDocumentType("html",
33 "-//W3C//DTD XHTML 1.0 Strict//EN",
34 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd")
35 XMLNS_XHTML
= "http://www.w3.org/1999/xhtml"
36 doc
= impl
.createDocument(XMLNS_XHTML
, "html", doctype
)
37 root
= doc
.documentElement
39 head
= doc
.createElement('head')
40 root
.appendChild(head
)
41 title
= doc
.createElement('title')
42 title
.appendChild(doc
.createTextNode('0test results for ' + spec
.test_iface
))
43 head
.appendChild(title
)
44 style
= doc
.createElement('style')
45 head
.appendChild(style
)
46 style
.setAttribute('type', "text/css")
47 style
.appendChild(doc
.createTextNode("""
49 border: 1px solid black;
54 table.testresults th {
59 table.testresults td.passed {
63 table.testresults td.passed {
67 table.testresults td.skipped {
72 table.testresults td.failed {
77 body
= doc
.createElement('body')
78 root
.appendChild(body
)
80 for outer_combo
in spec
.get_combos(spec
.test_ifaces
[:-2]):
81 outer_key
= frozenset(outer_combo
.items())
82 outers
= [(iface_cache
.iface_cache
.get_feed(uri
).get_name() + " " + version
) for (uri
, version
) in outer_combo
.iteritems()]
84 heading
= doc
.createElement('h1')
85 heading
.appendChild(doc
.createTextNode(', '.join(outers
) or 'Results'))
86 body
.appendChild(heading
)
88 table
= doc
.createElement('table')
89 table
.setAttribute('class', 'testresults')
90 body
.appendChild(table
)
92 col_iface_uri
= spec
.test_ifaces
[-1]
93 row_iface_uri
= spec
.test_ifaces
[-2]
95 col_iface
= iface_cache
.iface_cache
.get_interface(col_iface_uri
)
96 row_iface
= iface_cache
.iface_cache
.get_interface(row_iface_uri
)
98 test_columns
= spec
.test_matrix
[spec
.test_ifaces
[-1]]
100 row
= doc
.createElement('tr')
101 table
.appendChild(row
)
102 th
= doc
.createElement('th')
104 th
= doc
.createElement('th')
105 th
.setAttribute("colspan", str(len(test_columns
)))
107 th
.appendChild(doc
.createTextNode(col_iface
.get_name()))
109 row
= doc
.createElement('tr')
110 table
.appendChild(row
)
111 th
= doc
.createElement('th')
113 th
.appendChild(doc
.createTextNode(row_iface
.get_name()))
114 for col_iface_version
in spec
.test_matrix
[col_iface_uri
]:
115 th
= doc
.createElement('th')
117 th
.appendChild(doc
.createTextNode(col_iface_version
))
119 for row_iface_version
in spec
.test_matrix
[row_iface_uri
]:
120 table
.appendChild(doc
.createTextNode('\n'))
121 row
= doc
.createElement('tr')
122 table
.appendChild(row
)
123 th
= doc
.createElement('th')
125 th
.appendChild(doc
.createTextNode(row_iface_version
))
126 for col_iface_version
in test_columns
:
127 td
= doc
.createElement('td')
129 key
= frozenset(outer_key |
set([(row_iface_uri
, row_iface_version
), (col_iface_uri
, col_iface_version
)]))
131 result
, selections
= results
.by_combo
[key
]
132 td
.setAttribute('class', result
)
135 combo_ifaces
= set(uri
for (uri
, version
) in key
)
136 for iface
, version
in selections
.iteritems():
137 if iface
.uri
not in combo_ifaces
:
138 other_ifaces
.append((iface
.get_name(), version
))
140 td
.appendChild(doc
.createTextNode('\n'.join('%s %s' % (uri
, version
) for uri
, version
in other_ifaces
)))
142 td
.appendChild(doc
.createTextNode(result
))
143 table
.appendChild(doc
.createTextNode('\n'))