Run mutate-changes on a script its tests import by file name, and name a crash inside mutmut in one line
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
mutmut names a mutant `<module>.<key>__mutmut_<number>`. The key is x_<function> for a function at a module's top, and xǁ<class>ǁ<method> for a method of a class there; mutmut mutates no other code. Its mutants/ copy of a file holds the original of each function mutmut mutates, as `<key>__mutmut_orig`, and each mutant as a changed copy of that original."""
|
||||
import ast
|
||||
import functools
|
||||
import re
|
||||
from typing import NamedTuple
|
||||
from collections.abc import Sequence
|
||||
|
||||
@@ -40,6 +41,20 @@ def named(name: str, paths: list[str]) -> tuple[str, str, int] | None:
|
||||
return (found[0], key, int(number)) if found and number.isdigit() else None
|
||||
|
||||
|
||||
TRACEBACK = "Traceback (most recent call last):"
|
||||
FRAME = re.compile(r'^\s*File ".*?[/\\](mutmut[/\\].*?|[^/\\]*?)", line (\d+)', re.MULTILINE)
|
||||
|
||||
|
||||
def crash_in_mutmut(output: str) -> str | None:
|
||||
"""The error and place of the last traceback in output, where it ends in a frame inside mutmut's own code, else None."""
|
||||
block = output.rpartition(TRACEBACK)[2] if TRACEBACK in output else ""
|
||||
frames = FRAME.findall(block)
|
||||
lines = block.strip().splitlines()
|
||||
if not frames or not lines or not frames[-1][0].startswith("mutmut"):
|
||||
return None
|
||||
return f"{lines[-1]}, in {frames[-1][0].replace(chr(92), '/')} line {frames[-1][1]}"
|
||||
|
||||
|
||||
def statuses(results: str) -> dict[str, str]:
|
||||
"""Each mutant's status by name, from the ` <name>: <status>` lines `mutmut results --all true` prints."""
|
||||
return {name: status for name, _, status in (line.strip().partition(": ") for line in results.splitlines()) if "__mutmut_" in name and status}
|
||||
|
||||
Reference in New Issue
Block a user