mutation.mutation_score(
spec,
name,
*,
python=None,
max_mutants=None,
timeout=120.0,
progress=None,
)
Run the unit’s evaluations against every mutant of its module.
Parameters
| spec |
RegenSpec |
The loaded spec. |
required |
| name |
str | Unit |
The unit, as a dotted module name, its unique suffix or a spotregen.Unit. |
required |
| python |
Path | None |
Interpreter for pytest. Defaults to <root>/.venv/bin/python if it exists, else the running interpreter. |
None |
| max_mutants |
int | None |
Run only the first max_mutants mutants (in source order). Defaults to all. |
None |
| timeout |
float |
Seconds one evaluation run may take; a slower mutant counts as killed. Defaults to 120. |
120.0 |
| progress |
Callable[[MutantResult], None] | None |
Called with each result as soon as it is known. |
None |
Raises
|
KeyError |
If name matches no unit or more than one. |
|
ConfigurationError |
If the unit declares no evaluation file, or the evaluations do not all pass on the unchanged module. |
Examples
import sys
from pathlib import Path
from tempfile import TemporaryDirectory
from spotregen import load_spec, make_sample_repo
from spotregen.mutation import mutation_score
with TemporaryDirectory() as tmp:
spec = load_spec(make_sample_repo(Path(tmp) / "demo"))
report = mutation_score(spec, "core.calc", python=Path(sys.executable))
for r in report.results:
print(r.mutant.id, r.mutant.original, "->", r.mutant.mutated, r.detail)
print(f"{report.killed}/{report.planted}")
M001 return a + b -> return None 1 failed
M002 a + b -> a - b 1 failed
M003 return 1 -> return None survived
M004 1 -> 2 survived
2/4