1 | # -*- coding: utf-8 -*- |
---|
2 | # |
---|
3 | # Copyright (C) 2005-2007 Christopher Lenz <cmlenz@gmx.de> |
---|
4 | # Copyright (C) 2007-2010 Edgewall Software |
---|
5 | # All rights reserved. |
---|
6 | # |
---|
7 | # This software is licensed as described in the file COPYING, which |
---|
8 | # you should have received as part of this distribution. The terms |
---|
9 | # are also available at http://bitten.edgewall.org/wiki/License. |
---|
10 | |
---|
11 | from trac.core import * |
---|
12 | from trac.web.chrome import add_script |
---|
13 | from bitten.api import IReportChartGenerator, IReportSummarizer |
---|
14 | |
---|
15 | __docformat__ = 'restructuredtext en' |
---|
16 | |
---|
17 | |
---|
18 | class TestResultsChartGenerator(Component): |
---|
19 | implements(IReportChartGenerator) |
---|
20 | |
---|
21 | # IReportChartGenerator methods |
---|
22 | |
---|
23 | def get_supported_categories(self): |
---|
24 | return ['test'] |
---|
25 | |
---|
26 | def generate_chart_data(self, req, config, category): |
---|
27 | assert category == 'test' |
---|
28 | |
---|
29 | db = self.env.get_db_cnx() |
---|
30 | cursor = db.cursor() |
---|
31 | cursor.execute(""" |
---|
32 | SELECT build.rev, build.platform, item_status.value AS status, COUNT(*) AS num |
---|
33 | FROM bitten_build AS build |
---|
34 | LEFT OUTER JOIN bitten_report AS report ON (report.build=build.id) |
---|
35 | LEFT OUTER JOIN bitten_report_item AS item_status |
---|
36 | ON (item_status.report=report.id AND item_status.name='status') |
---|
37 | WHERE build.config=%s AND report.category='test' |
---|
38 | AND build.rev_time >= %s AND build.rev_time <= %s |
---|
39 | GROUP BY build.rev_time, build.rev, build.platform, item_status.value |
---|
40 | ORDER BY build.rev_time, build.platform""", (config.name, |
---|
41 | config.min_rev_time(self.env), |
---|
42 | config.max_rev_time(self.env))) |
---|
43 | |
---|
44 | prev_rev = None |
---|
45 | prev_platform, platform_total = None, 0 |
---|
46 | tests = [] |
---|
47 | for rev, platform, status, num in cursor: |
---|
48 | if rev != prev_rev: |
---|
49 | tests.append([rev, 0, 0, 0]) |
---|
50 | prev_rev = rev |
---|
51 | platform_total = 0 |
---|
52 | if platform != prev_platform: |
---|
53 | prev_platform = platform |
---|
54 | platform_total = 0 |
---|
55 | |
---|
56 | platform_total += num |
---|
57 | tests[-1][1] = max(platform_total, tests[-1][1]) |
---|
58 | if status == 'success': |
---|
59 | pass |
---|
60 | elif status == 'ignore': |
---|
61 | tests[-1][3] = max(num, tests[-1][3]) |
---|
62 | else: |
---|
63 | tests[-1][2] = max(num, tests[-1][2]) |
---|
64 | |
---|
65 | data = {'title': 'Unit Tests', |
---|
66 | 'data': [ |
---|
67 | {'label': 'Total', 'data': [[item[0], item[1]] for item in tests], 'lines': {'fill': True}}, |
---|
68 | {'label': 'Failures', 'data': [[item[0], item[2]] for item in tests]}, |
---|
69 | {'label': 'Ignored', 'data': [[item[0], item[3]] for item in tests]}, |
---|
70 | ], |
---|
71 | 'options': { |
---|
72 | 'legend': {'position': 'sw', 'backgroundOpacity': 0.7}, |
---|
73 | 'xaxis': {'tickDecimals': 0}, |
---|
74 | 'yaxis': {'tickDecimals': 0}, |
---|
75 | }, |
---|
76 | } |
---|
77 | |
---|
78 | return 'json.txt', {"json": data} |
---|
79 | |
---|
80 | |
---|
81 | class TestResultsSummarizer(Component): |
---|
82 | implements(IReportSummarizer) |
---|
83 | |
---|
84 | # IReportSummarizer methods |
---|
85 | |
---|
86 | def get_supported_categories(self): |
---|
87 | return ['test'] |
---|
88 | |
---|
89 | def render_summary(self, req, config, build, step, category): |
---|
90 | assert category == 'test' |
---|
91 | |
---|
92 | db = self.env.get_db_cnx() |
---|
93 | cursor = db.cursor() |
---|
94 | cursor.execute(""" |
---|
95 | SELECT item_fixture.value AS fixture, item_file.value AS file, |
---|
96 | COUNT(item_success.value) AS num_success, |
---|
97 | COUNT(item_ignore.value) AS num_ignore, |
---|
98 | COUNT(item_failure.value) AS num_failure, |
---|
99 | COUNT(item_error.value) AS num_error |
---|
100 | FROM bitten_report AS report |
---|
101 | LEFT OUTER JOIN bitten_report_item AS item_fixture |
---|
102 | ON (item_fixture.report=report.id AND item_fixture.name='fixture') |
---|
103 | LEFT OUTER JOIN bitten_report_item AS item_file |
---|
104 | ON (item_file.report=report.id AND item_file.item=item_fixture.item AND |
---|
105 | item_file.name='file') |
---|
106 | LEFT OUTER JOIN bitten_report_item AS item_success |
---|
107 | ON (item_success.report=report.id AND item_success.item=item_fixture.item AND |
---|
108 | item_success.name='status' AND item_success.value='success') |
---|
109 | LEFT OUTER JOIN bitten_report_item AS item_ignore |
---|
110 | ON (item_ignore.report=report.id AND item_ignore.item=item_fixture.item AND |
---|
111 | item_ignore.name='status' AND item_ignore.value='ignore') |
---|
112 | LEFT OUTER JOIN bitten_report_item AS item_failure |
---|
113 | ON (item_failure.report=report.id AND item_failure.item=item_fixture.item AND |
---|
114 | item_failure.name='status' AND item_failure.value='failure') |
---|
115 | LEFT OUTER JOIN bitten_report_item AS item_error |
---|
116 | ON (item_error.report=report.id AND item_error.item=item_fixture.item AND |
---|
117 | item_error.name='status' AND item_error.value='error') |
---|
118 | WHERE category='test' AND build=%s AND step=%s |
---|
119 | GROUP BY file, fixture |
---|
120 | ORDER BY fixture""", (build.id, step.name)) |
---|
121 | |
---|
122 | fixtures = [] |
---|
123 | total_success, total_ignore, total_failure, total_error = 0, 0, 0, 0 |
---|
124 | for fixture, file, num_success, num_ignore, num_failure, num_error in cursor: |
---|
125 | fixtures.append({'name': fixture, |
---|
126 | 'num_success': num_success, |
---|
127 | 'num_ignore': num_ignore, |
---|
128 | 'num_error': num_error, |
---|
129 | 'num_failure': num_failure}) |
---|
130 | total_success += num_success |
---|
131 | total_ignore += num_ignore |
---|
132 | total_failure += num_failure |
---|
133 | total_error += num_error |
---|
134 | if file: |
---|
135 | fixtures[-1]['href'] = req.href.browser(config.path, file) |
---|
136 | |
---|
137 | # For each fixture, get a list of tests that don't succeed |
---|
138 | for fixture in fixtures: |
---|
139 | cursor.execute(""" |
---|
140 | SELECT item_status.value AS status, item_name.value AS name, |
---|
141 | item_traceback.value AS traceback |
---|
142 | FROM bitten_report |
---|
143 | LEFT OUTER JOIN bitten_report_item AS item_fixture |
---|
144 | ON (item_fixture.report=bitten_report.id AND |
---|
145 | item_fixture.name='fixture') |
---|
146 | LEFT OUTER JOIN bitten_report_item AS item_status |
---|
147 | ON (item_status.report=bitten_report.id AND |
---|
148 | item_status.item=item_fixture.item AND |
---|
149 | item_status.name='status') |
---|
150 | LEFT OUTER JOIN bitten_report_item AS item_name |
---|
151 | ON (item_name.report=bitten_report.id AND |
---|
152 | item_name.item=item_fixture.item AND |
---|
153 | item_name.name='name') |
---|
154 | LEFT OUTER JOIN bitten_report_item AS item_traceback |
---|
155 | ON (item_traceback.report=bitten_report.id AND |
---|
156 | item_traceback.item=item_fixture.item AND |
---|
157 | item_traceback.name='traceback') |
---|
158 | WHERE category='test' AND build=%s AND step=%s AND item_status.value<>'success' AND |
---|
159 | item_fixture.value=%s""", (build.id, step.name, fixture['name'])) |
---|
160 | |
---|
161 | failures = [] |
---|
162 | for status, name, traceback in cursor: |
---|
163 | # use the fixture name if a name isn't supplied for the |
---|
164 | # individual test |
---|
165 | if not name: |
---|
166 | name = fixture['name'] |
---|
167 | failures.append({'status': status, |
---|
168 | 'name': name, |
---|
169 | 'traceback': traceback}) |
---|
170 | if failures: |
---|
171 | fixture['failures'] = failures |
---|
172 | |
---|
173 | data = {'fixtures': fixtures, |
---|
174 | 'totals': {'success': total_success, |
---|
175 | 'ignore': total_ignore, |
---|
176 | 'failure': total_failure, |
---|
177 | 'error': total_error} |
---|
178 | } |
---|
179 | return 'bitten_summary_tests.html', data |
---|