Debian Codegraph @

test/lib/ansible_test/_internal/commands/coverage/html.py

raw
1 """Generate HTML code coverage reports."""
2
3 from __future__ import annotations
4
5 import os
6
7 from ...io import (
8 make_dirs,
9 )
10
11 from ...util import (
12 display,
13 )
14
15 from ...util_common import (
16 ResultType,
17 )
18
19 from ...provisioning import (
20 prepare_profiles,
21 )
22
23 from .combine import (
24 combine_coverage_files,
25 CoverageCombineConfig,
26 )
27
28 from . import (
29 run_coverage,
30 )
31
32
33 def command_coverage_html(args: CoverageHtmlConfig) -> None:
34 """Generate an HTML coverage report."""
35 host_state = prepare_profiles(args) # coverage html
36 output_files = combine_coverage_files(args, host_state)
37
38 for output_file in output_files:
39 if output_file.endswith('-powershell'):
40 # coverage.py does not support non-Python files so we just skip the local html report.
41 display.info("Skipping output file %s in html generation" % output_file, verbosity=3)
42 continue
43
44 dir_name = os.path.join(ResultType.REPORTS.path, os.path.basename(output_file))
45 make_dirs(dir_name)
46 run_coverage(args, host_state, output_file, 'html', ['-i', '-d', dir_name])
47
48 display.info('HTML report generated: file:///%s' % os.path.join(dir_name, 'index.html'))
49
50
51 class CoverageHtmlConfig(CoverageCombineConfig):
52 """Configuration for the coverage html command."""