/
__init__.py
271 lines (261 loc) · 11.1 KB
/
__init__.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
# -*- coding:utf-8 -*-
# ************************** Copyrights and license ***************************
#
# This file is part of gcovr 7.2+main, a parsing and reporting tool for gcov.
# https://gcovr.com/en/stable
#
# _____________________________________________________________________________
#
# Copyright (c) 2013-2024 the gcovr authors
# Copyright (c) 2013 Sandia Corporation.
# Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
# the U.S. Government retains certain rights in this software.
#
# This software is distributed under the 3-clause BSD License.
# For more information, see the README.rst file.
#
# ****************************************************************************
import logging
from typing import List
from ...options import (
GcovrConfigOption,
OutputOrDefault,
check_input_file,
check_percentage,
)
from ...formats.base import BaseHandler
from ...coverage import CovData
LOGGER = logging.getLogger("gcovr")
class HtmlHandler(BaseHandler):
def get_options() -> List[GcovrConfigOption]:
from .write import CssRenderer
return [
# Global options needed for report
"exclude_calls",
"show_decision",
# Local options
GcovrConfigOption(
"html",
["--html"],
group="output_options",
metavar="OUTPUT",
help="Generate a HTML report. OUTPUT is optional and defaults to --output.",
nargs="?",
type=OutputOrDefault,
default=None,
const=OutputOrDefault(None),
),
GcovrConfigOption(
"html_details",
["--html-details"],
group="output_options",
metavar="OUTPUT",
help=(
"Add annotated source code reports to the HTML report. "
"Implies --html, can not be used together with --html-nested. "
"OUTPUT is optional and defaults to --output."
),
nargs="?",
type=OutputOrDefault,
default=None,
const=OutputOrDefault(None),
),
GcovrConfigOption(
"html_nested",
["--html-nested"],
group="output_options",
metavar="OUTPUT",
help=(
"Add annotated source code reports to the HTML report. "
"A page is created for each directory that summarize subdirectories "
"with aggregated statistics. "
"Implies --html, can not be used together with --html-details. "
"OUTPUT is optional and defaults to --output."
),
nargs="?",
type=OutputOrDefault,
default=None,
const=OutputOrDefault(None),
),
GcovrConfigOption(
"html_template_dir",
["--html-template-dir"],
group="output_options",
metavar="OUTPUT",
help=(
"Override the default Jinja2 template directory for the HTML report. "
),
),
GcovrConfigOption(
"html_syntax_highlighting",
["--html-syntax-highlighting", "--html-details-syntax-highlighting"],
group="output_options",
help="Use syntax highlighting in HTML source page. Enabled by default.",
action="store_const",
default=True,
const=True,
const_negate=False, # autogenerates --no-NAME with action const=False
),
GcovrConfigOption(
"html_theme",
["--html-theme"],
group="output_options",
type=str,
choices=CssRenderer.get_themes(),
metavar="THEME",
help=(
"Override the default color theme for the HTML report. "
"Default is {default!s}."
),
default=CssRenderer.get_default_theme(),
),
GcovrConfigOption(
"html_css",
["--html-css"],
group="output_options",
type=check_input_file,
metavar="CSS",
help="Override the default style sheet for the HTML report.",
default=None,
),
GcovrConfigOption(
"html_title",
["--html-title"],
group="output_options",
metavar="TITLE",
help="Use TITLE as title for the HTML report. Default is '{default!s}'.",
default="GCC Code Coverage Report",
),
GcovrConfigOption(
"html_medium_threshold",
["--html-medium-threshold"],
group="output_options",
type=check_percentage,
metavar="MEDIUM",
help=(
"If the coverage is below MEDIUM, the value is marked "
"as low coverage in the HTML report. "
"MEDIUM has to be lower than or equal to value of --html-high-threshold "
"and greater than 0. "
"If MEDIUM is equal to value of --html-high-threshold the report has "
"only high and low coverage. Default is {default!s}."
),
default=75.0,
),
GcovrConfigOption(
"html_high_threshold",
["--html-high-threshold"],
group="output_options",
type=check_percentage,
metavar="HIGH",
help=(
"If the coverage is below HIGH, the value is marked "
"as medium coverage in the HTML report. "
"HIGH has to be greater than or equal to value of --html-medium-threshold. "
"If HIGH is equal to value of --html-medium-threshold the report has "
"only high and low coverage. Default is {default!s}."
),
default=90.0,
),
GcovrConfigOption(
"html_medium_threshold_branch",
["--html-medium-threshold-branch"],
group="output_options",
metavar="MEDIUM_BRANCH",
type=check_percentage,
help="If the coverage is below MEDIUM_BRANCH, the value is marked "
"as low coverage in the HTML report. "
"MEDIUM_BRANCH has to be lower than or equal to value of --html-high-threshold-branch "
"and greater than 0. "
"If MEDIUM_BRANCH is equal to value of --html-medium-threshold-branch the report has "
"only high and low coverage. Default is taken from --html-medium-threshold.",
default=None,
),
GcovrConfigOption(
"html_high_threshold_branch",
["--html-high-threshold-branch"],
group="output_options",
type=check_percentage,
metavar="HIGH_BRANCH",
help="If the coverage is below HIGH_BRANCH, the value is marked "
"as medium coverage in the HTML report. "
"HIGH_BRANCH has to be greater than or equal to value of --html-medium-threshold-branch. "
"If HIGH_BRANCH is equal to value of --html-medium-threshold-branch the report has "
"only high and low coverage. Default is taken from --html-high-threshold.",
default=None,
),
GcovrConfigOption(
"html_medium_threshold_line",
["--html-medium-threshold-line"],
group="output_options",
metavar="MEDIUM_LINE",
type=check_percentage,
help="If the coverage is below MEDIUM_LINE, the value is marked "
"as low coverage in the HTML report. "
"MEDIUM_LINE has to be lower than or equal to value of --html-high-threshold-line "
"and greater than 0. "
"If MEDIUM_LINE is equal to value of --html-medium-threshold-line the report has "
"only high and low coverage. Default is taken from --html-medium-threshold.",
default=None,
),
GcovrConfigOption(
"html_high_threshold_line",
["--html-high-threshold-line"],
group="output_options",
type=check_percentage,
metavar="HIGH_LINE",
help="If the coverage is below HIGH_LINE, the value is marked "
"as medium coverage in the HTML report. "
"HIGH_LINE has to be greater than or equal to value of --html-medium-threshold-line. "
"If HIGH_LINE is equal to value of --html-medium-threshold-line the report has "
"only high and low coverage. Default is taken from --html-high-threshold.",
default=None,
),
GcovrConfigOption(
"html_tab_size",
["--html-tab-size"],
group="output_options",
help="Used spaces for a tab in a source file. Default is {default!s}",
type=int,
default=4,
),
GcovrConfigOption(
"html_relative_anchors",
["--html-absolute-paths"],
group="output_options",
help=(
"Use absolute paths to link the --html-details reports. "
"Defaults to relative links."
),
action="store_false",
),
GcovrConfigOption(
"html_encoding",
["--html-encoding"],
group="output_options",
help=(
"Override the declared HTML report encoding. "
"Defaults to {default!s}. "
"See also --source-encoding."
),
default="UTF-8",
),
GcovrConfigOption(
"html_self_contained",
["--html-self-contained"],
group="output_options",
help=(
"Control whether the HTML report bundles resources like CSS styles. "
"Self-contained reports can be sent via email, "
"but conflict with the Content Security Policy of some web servers. "
"Defaults to self-contained reports unless --html-details is used."
),
action="store_const",
default=None,
const=True,
const_negate=False,
),
]
def write_report(self, covdata: CovData, output_file: str) -> None:
from .write import write_report
write_report(covdata, output_file, self.options)