8Render mutation results for humans without editorialising the numbers.
12- Render the enumeration-only listing used by ``--list``.
13- Render totals, the kill rate, and one description per surviving mutant.
14- Name the mutants that timed out, which no test run judged either way.
21 L3 - rendering details
26- Output is ASCII only, so a cp1252 console cannot turn a report into a crash.
27- v1 is report-only: the rendered text states no verdict and no threshold.
28- A survivor is described by its id, its source line, and its before/after form.
32- oct.mutation.engine (mutant records)
33- oct.mutation.runner (run results)
39from __future__
import annotations
41from typing
import Sequence
47def render_list(mutants: Sequence[Mutant], target: str) -> str:
48 """Render the enumeration produced by ``--list``, which runs nothing."""
49 lines = [f
"{len(mutants)} mutant(s) in {target}; nothing was run."]
51 f
" {mutant.mutant_id} line {mutant.lineno}: "
52 f
"{mutant.before} -> {mutant.after}"
55 return "\n".join(lines)
59 """Render totals, the kill rate, survivors, and any unjudged timeouts."""
61 f
"Mutation report for {report.target}",
62 f
" tests: {report.tests}",
63 f
" timeout: {report.timeout_seconds}s per mutant",
64 f
" mutants: {report.total}"
65 f
" killed {report.killed}"
66 f
" survived {report.survived}"
67 f
" timeout {report.timed_out}",
68 f
" kill rate: {_format_rate(report.kill_rate)}"
69 " (report-only: v1 applies no threshold and gates nothing)",
73 timeouts = [item
for item
in report.outcomes
if item.status == STATUS_TIMEOUT]
77 return "\n".join(lines)
81 """Render one description per surviving mutant, or say there were none."""
83 return [
"Survivors: none."]
84 lines = [f
"Survivors ({len(survivors)}) - the tests did not notice these:"]
85 for outcome
in survivors:
86 mutant = outcome.mutant
87 lines.append(f
" {mutant.mutant_id}")
88 lines.append(f
" line {mutant.lineno}: {mutant.line_text}")
89 lines.append(f
" - {mutant.before}")
90 lines.append(f
" + {mutant.after}")
95 """Render the mutants that exceeded the timeout and were never judged."""
97 f
"Timed out ({len(timeouts)}) - neither killed nor survived; "
98 "raise --timeout to judge these:"
101 f
" {outcome.mutant.mutant_id} line {outcome.mutant.lineno}: "
102 f
"{outcome.mutant.before} -> {outcome.mutant.after}"
103 for outcome
in timeouts
109 """Render the kill rate as a percentage, or ``n/a`` when nothing ran."""
112 return f
"{rate * 100:.1f}%"
list[str] _render_survivors(Sequence[MutantOutcome] survivors)
str render_list(Sequence[Mutant] mutants, str target)
str render_human(RunReport report)
str _format_rate(float|None rate)
list[str] _render_timeouts(Sequence[MutantOutcome] timeouts)