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