-
Notifications
You must be signed in to change notification settings - Fork 0
/
render.py
301 lines (262 loc) · 11.9 KB
/
render.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
"""
BE CAREFUL!!!
SHIT CODE BELOW. Needs to be rewritten with Jinja2
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░▓████████▓░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░▒█████████▓▒░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░▓██▓▓▓▓▓▓███░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░▓██▓▓▓▓▓▓▓██▓░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░▓█▓▓▓▓▓▓▓▓█▓░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░▓█▓▓▓▓▓▓▓▓█▓▒░░░░░░░░░░░░
░░░░░░░░░░░░░░░▓██▓▓▓▓▓▓▓▓▓▓▓░░░░░░░░░░░░
░░░░░░░░░░░▒▓▓█████▓▓▓▓▓▓▓▓██▓░░░░░░░░░░░
░░░░░░░░░▓█████████▓▓▓▓▓▓▓▓███▓▒░░░░░░░░░
░░░░░░░░▓███▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓████▓░░░░░░░░
░░░░░░▒████▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓███▓░░░░░░░
░░░░░░▓██▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓██▓░░░░░░
░░░░░░▓██▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓██▓░░░░░░
░░░░░░███▓▓▓█████▓▓▓▓▓▓▓█████▓▓▓██▓░░░░░░
░░░░░░████▓█▓░░▒▓▓▓▓█▓██▓░░▒▓█▓███▓░░░░░░
░░░░░▒█████▓░░░░▒▓█████▓░░░░▒▓█████▒░░░░░
░░░░▓████▓▒░░▒█░░░▓███▒░░▒▓░░░▓█████▓░░░░
░░▒▓███▓▓▓░░░██▒░░▒▓█▓░░░▓█▓░░░▓▓▓███▓▒░░
░▓████▓▓▓▓▓░░░░░░░▓▓▓▓▒░░░░░░░▓▓▓▓▓████░░
░███▓▓▓▓▓▓▓▓▒░░░▓▓▓▓▓▓▓▓▒░░░▓▓▓▓▓▓▓▓▓██▓░
░███▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓██▓░
░███▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓██▓░
░███▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓██▓░
░███▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓██▓░
░█████▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓███▒░
░▒█████▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓███▓█░░
░░░▓████▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓████▒░░░
░░░░▒▓█████████████████████████████▓▒░░░░
░░░░░▒▓███████████████████████████▓░░░░░░
"""
import utils
import os
from datetime import datetime
"""THIS IS VERY PRIMITIVE IMPLEMENTATION. Needs to be rewritten using jinja or smth like that"""
class Render(object):
def __init__(self, storage, root_dir, excluded):
self._storage = storage
self._root_dir = root_dir
self._excluded = excluded
def render(self):
return ''.join([
self._render_header(),
self._render_summary(),
self._render_statistics(),
self._render_directories_tree(),
self._render_semi_a(),
self._render_test_cases(),
self._render_semi_b()
])
def _render_header(self):
return '''<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Test Cases Report - ''' + self._root_dir + '''</title>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.3.3/semantic.min.css">
<style>
h2 {
margin-top:1.5em !important;
}
.dont-break-out {
/* These are technically the same, but use both */
overflow-wrap: break-word;
word-wrap: break-word;
-ms-word-break: break-all;
/* This is the dangerous one in WebKit, as it breaks things wherever */
word-break: break-all;
/* Instead use this non-standard one: */
word-break: break-word;
/* Adds a hyphen where the word breaks, if supported (No Blink) */
-ms-hyphens: auto;
-moz-hyphens: auto;
-webkit-hyphens: auto;
hyphens: auto;
min-width:110px !important;
}
</style>
</head>
<body>
<div class="ui container" style="padding-top:20px">
<h1 class="ui dividing header">Test Cases Report</h1>
<div class="ui vertical segment">
<h2 class="ui header">Summary</h2>
<p>The report contains statistics about test cases written using Google Test framework</p>
<table class="ui striped very basic celled collapsing table">
<tbody>
'''
def _render_summary(self):
return '''
<tr>
<td>Project Root Dir</td>
<td><code>{}</code></td>
</tr>
<tr>
<td>Excluded Paths</td>
<td><small><code>{}</code></small></td>
</tr>
<tr>
<td>Report Generation Date</td>
<td>{}</td>
</tr>
<tr>
<td>Target File Extensions</td>
<td><code>.cpp .cxx .cc .c .hpp .h</code></td>
</tr>
<tr>
<td>Target Cases Types</td>
<td><code>TEST, TEST_F, TEST_P, TYPED_TEST_CASE</code></td>
</tr>
</tbody>
</table>
<div class="ui small statistics">
'''.format(self._root_dir, '<br>'.join(self._excluded), datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
def _render_statistics(self):
return '''
<div class="statistic">
<div class="value">
{}
</div>
<div class="label">
files with tests
</div>
</div>
<div class="statistic">
<div class="value">
{}
</div>
<div class="label">
test cases
</div>
</div>
<div class="orange statistic">
<div class="value">
{}
</div>
<div class="label">
lacks in description
</div>
</div>
<div class="statistic">
<div class="value">
{}
</div>
<div class="label">
disabled cases
</div>
</div>
</div>
</div>
<div class="ui vertical segment" id="tree">
<h2 class="ui header">Directories Tree</h2>
<div class="ui list">
'''.format(
self._storage.count_files_with_tests(),
self._storage.count_test_cases(),
self._storage.count_test_cases_without_description(),
self._storage.count_disabled_test_cases()
)
def _render_directories_tree(self):
files = self._storage.get_sources()
tree = utils.directories_tree(files)
def render_node(node, prefix):
result = []
dir = len(node['children'])
icon = 'folder outline' if dir else 'file'
result.append('<div class="item">')
result.append('<i class="{} icon"></i>'.format(icon))
result.append('<div class="content">')
new_prefix = '' if os.sep in node['name'] else prefix + node['name']
if dir:
result.append('<div class="header">{}</div>'.format(node['name']))
else:
result.append('<div class="header"><a href="#{}">{}</a></div>'.format(
new_prefix, node['name']
))
if dir:
result.append('<div class="list">')
for child in node['children']:
result.append(render_node(child, new_prefix))
result.append('</div>')
result.append('</div></div>')
return ''.join(result)
return render_node(tree, '')
def _render_semi_a(self):
return '''
</div>
</div>
<h2 class="ui header">Test Cases</h2>
'''
def _render_test_cases(self):
sources = self._storage.get_sources()
prefix = utils.common_path_prefix(sources)
def render_test_case(path, prefix):
result = []
result.append('''<div class="ui top attached block header" id="{}">
<div style="display:inline-block">{}</div>
<div style="float: right;">
<a href="#tree"><i class="small angle up icon"></i>back to tree</a>
</div>
</div>'''.format(path[len(prefix):].replace(os.sep, ''),
path[len(prefix):]))
result.append('''<div class="ui bottom attached segment"><table class="ui selectable very basic celled attached table">
<thead>
<tr>
<th>Line #</th>
<th class="collapsing">Fixture (
<div class="ui mini empty circular purple label"></div>
) / Test Name
</th>
<th>Test Case Name</th>
<th>Caption</th>
<th>Given</th>
<th>When</th>
<th>Then</th>
</tr>
</thead>
<tbody>''')
for row in self._storage.get_test_cases(path):
line = row[0]
fixture_name = row[1]
test_name = row[2]
has_fixture = int(row[3])
caption = row[4] if row[4] else ''
given = row[5] if row[5] else ''
when = row[6] if row[6] else ''
then = row[7] if row[7] else ''
disabled = '<div class="ui grey horizontal label">DISABLED</div>' if test_name.startswith(
'DISABLED_') else ''
test = test_name[len('DISABLED_'):] if disabled else test_name
warning = (not caption and not given and not when and not then)
result.append('''<tr class="{}"><td>{}</td><td>{}{}</td><td class="dont-break-out">{}{}</td>'''.format(
'warning' if warning else '',
line,
fixture_name,
' <div class="ui mini empty circular purple label"></div>' if has_fixture else '',
disabled,
test
))
result.append('''<td>{}</td><td>{}</td><td>{}</td><td>{}</td></tr>'''.format(
caption, given, when, then
))
result.append('''
</tbody>
</table>
</div>
''')
return ''.join(result)
res = []
for source in sources:
res.append(render_test_case(source, prefix))
return ''.join(res)
def _render_semi_b(self):
return '''
<div class="ui basic segment"> </div>
</div>
</body>
</html>
'''