ansible-test - Fix PS coverage `--all` generation.

pull/77254/head
Matt Clay 3 years ago
parent 6f445ca6e5
commit 0c514bcf54

@ -0,0 +1,2 @@
bugfixes:
- ansible-test - Fix traceback when using the ``--all`` option with PowerShell code coverage.

@ -60,6 +60,8 @@ from . import (
PathChecker,
)
TValue = t.TypeVar('TValue')
def command_coverage_combine(args): # type: (CoverageCombineConfig) -> None
"""Patch paths in coverage files and merge into a single file."""
@ -113,9 +115,12 @@ def _command_coverage_combine_python(args, host_state): # type: (CoverageCombin
coverage_files = get_python_coverage_files()
def _default_stub_value(source_paths: list[str]) -> dict[str, set[tuple[int, int]]]:
return {path: set() for path in source_paths}
counter = 0
sources = _get_coverage_targets(args, walk_compile_targets)
groups = _build_stub_groups(args, sources, lambda s: dict((name, set()) for name in s))
groups = _build_stub_groups(args, sources, _default_stub_value)
collection_search_re, collection_sub_re = get_collection_path_regexes()
@ -185,7 +190,7 @@ def _command_coverage_combine_powershell(args): # type: (CoverageCombineConfig)
"""Combine PowerShell coverage files and return a list of the output files."""
coverage_files = get_powershell_coverage_files()
def _default_stub_value(source_paths):
def _default_stub_value(source_paths: list[str]) -> dict[str, dict[int, int]]:
cmd = ['pwsh', os.path.join(ANSIBLE_TEST_TOOLS_ROOT, 'coverage_stub.ps1')]
cmd.extend(source_paths)
@ -234,12 +239,9 @@ def _command_coverage_combine_powershell(args): # type: (CoverageCombineConfig)
coverage_data = dict((filename, data) for filename, data in groups[group].items() if path_checker.check_path(filename))
if args.all:
# Add 0 line entries for files not in coverage_data
for source, source_line_count in sources:
if source in coverage_data:
continue
coverage_data[source] = _default_stub_value(source_line_count)
missing_sources = [source for source, _source_line_count in sources if source not in coverage_data]
stubs = _default_stub_value(missing_sources)
coverage_data.update(stubs)
if not args.explain:
if args.export:
@ -278,17 +280,19 @@ def _get_coverage_targets(args, walk_func): # type: (CoverageCombineConfig, t.C
return sources
def _build_stub_groups(args, sources, default_stub_value):
def _build_stub_groups(
args: CoverageCombineConfig,
sources: list[tuple[str, int]],
default_stub_value: t.Callable[[list[str]], dict[str, TValue]],
) -> dict[str, dict[str, TValue]]:
"""
:type args: CoverageCombineConfig
:type sources: List[tuple[str, int]]
:type default_stub_value: Func[List[str]]
:rtype: dict
Split the given list of sources with line counts into groups, maintaining a maximum line count for each group.
Each group consists of a dictionary of sources and default coverage stubs generated by the provided default_stub_value function.
"""
groups = {}
if args.stub:
stub_group = []
stub_group: list[str] = []
stub_groups = [stub_group]
stub_line_limit = 500000
stub_line_count = 0

Loading…
Cancel
Save