Skip to main content

mutation.Mutant

mutation.Mutant(id, line, end_line, operator, original, mutated, diff, source)

One planted change of a module.

Attributes

Name Type Description
id str M001, M002, … in source order.
line int Line of the changed node in the original module.
end_line int Last line of the changed node.
operator str compare, boolean, negation, condition, constant, operator, statement, raise or return.
original str The changed expression or statement before the change.
mutated str The same after the change.
diff str Unified diff, two lines of context, between the unparsed original and the mutated module (headers --- original and +++ <id>). It tells two mutants on one line apart, which the cut original and mutated may not.
source str The whole mutated module.

Examples

from babregen.mutation import generate_mutants

mutant = generate_mutants("def f(x):\n    return x < 1\n")[0]
print(mutant.id, mutant.line, mutant.operator, mutant.original, "->", mutant.mutated)
M001 2 return return x < 1 -> return None