This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 35
/
reporter.py
116 lines (86 loc) · 3.51 KB
/
reporter.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
class Reporter():
reporters = {}
def start_report(self):
return None
def start_targets(self):
return None
def write_target(self, target):
return None
def start_actives(self):
return None
def write_active(self, test):
return None
def start_passives(self):
return None
def write_passive(self, target):
return None
def end_passives(self):
return None
def end_actives(self):
return None
def end_targets(self):
return None
def end_report(self):
return "This reporter is unimplemented!"
class DetailReporter(Reporter):
# TODO Implement detailed reporter
def end_report(self):
return "This reporter should emit an XML report that includes all of the the details for each test, including captured data"
Reporter.reporters['detail'] = DetailReporter()
class AntXmlReporter(Reporter):
def __init__(self):
self.report = ""
self.errtypes = { 'Error' : "error", 'Fail' : "failure", 'Skip' : "skipped"}
def start_report(self):
self.report = '<?xml version="1.0" encoding="utf-8"?>\n'
return None
def start_targets(self):
self.report += "<testsuites>\n"
return None
def write_target(self, target):
self.states = {}
self.states["Skip"] = 0
self.states["Error"] = 0
self.states["Pass"] = 0
self.states["Fail"] = 0
self.checks = 0
self.current_target = target
self.lines = ""
return None
def start_actives(self):
return None
def write_active(self, test, result):
self.states[result["state"]] += 1
self.checks += 1
module, check = ("%s" % test ).split('.')
self.lines += '\t\t<testcase classname="%s" name="%s" time="%s"' % (module, check, result["duration"])
if result["state"] == "Pass":
self.lines += " />\n"
else:
self.lines += '>\n\t\t\t<{errtype}>{message}</{errtype}>\n\t\t</testcase>\n'.format(errtype=self.errtypes[result["state"]], message=result["message"])
return None
def start_passives(self):
return None
def write_passive(self, test, result):
self.states[result["state"]] += 1
self.checks += 1
module, check = ("%s" % test ).split('.')
self.lines += '\t\t<testcase classname="%s" name="%s" time="%s"' % (module, check, result["duration"])
if result["state"] == "Pass":
self.lines += " />\n"
else:
self.lines += '>\n\t\t\t<{errtype}>{message}</{errtype}>\n\t\t</testcase>\n'.format(errtype=self.errtypes[result["state"]], message=result["message"])
return None
def end_passives(self):
return None
def end_actives(self):
self.report+= '\t<testsuite name="{target}" errors="{errors}" failures="{failures}" skips="{skips}" tests="{checks}" time="{duration}">\n{lines}\t</testsuite>\n'.format(
target = self.current_target, errors=self.states["Error"], failures = self.states["Fail"],
skips = self.states["Skip"], checks = self.checks, duration=100, lines=self.lines)
return None
def end_targets(self):
self.report += "</testsuites>\n"
return None
def end_report(self):
return self.report
Reporter.reporters['xml'] = AntXmlReporter()