mutation.generate_mutants

mutation.generate_mutants(source)

All mutants of a module, in source order.

Parameters

Name Type Description Default
source str The module’s source code. required

Returns

Name Type Description
list[Mutant] list[Mutant]: One mutant per mutable node and operator. Mutations that leave the unparsed module unchanged are dropped.

Raises

Name Type Description
SyntaxError If source does not parse.

Examples

from spotregen.mutation import generate_mutants

source = "def check(x):\n    if x < 0 and x != -1:\n        raise ValueError(x)\n"
for m in generate_mutants(source):
    print(m.id, m.line, m.operator, m.original, "->", m.mutated)
M001 2 condition if x < 0 and x != -1 -> if not (x < 0 and x != -1)
M002 2 boolean x < 0 and x != -1 -> x < 0 or x != -1
M003 2 compare x < 0 -> x <= 0
M004 2 constant 0 -> 1
M005 2 compare x != -1 -> x == -1
M006 2 constant 1 -> 2
M007 3 raise raise ValueError(x) -> pass