cosmic_ray.operators package

Submodules

cosmic_ray.operators.binary_operator_replacement module

cosmic_ray.operators.boolean_replacer module

cosmic_ray.operators.break_continue module

cosmic_ray.operators.comparison_operator_replacement module

cosmic_ray.operators.exception_replacer module

cosmic_ray.operators.keyword_replacer module

cosmic_ray.operators.no_op module

Implementation of the no-op operator.

class cosmic_ray.operators.no_op.NoOp

Bases: cosmic_ray.operators.operator.Operator

An operator that makes no changes.

This is primarily for baselining and debugging. It behaves like any other operator, but it makes no changes. Obviously this means that, if your test suite passes on unmutated code, it will still pass after applying this operator. Use with care.

classmethod examples()

Examples of the mutations that this operator can make.

This is primarily for testing purposes, but it could also be used for documentation.

Each example takes the following arguments:

pre_mutation_code: code prior to applying the mutation. post_mutation_code: code after (successfully) applying the mutation. occurrence: the index of the occurrence to which the mutation is

applied (optional, default=0).
operator_args: a dictionary of arguments to be **-unpacked to the
operator (optional, default={}).

Returns: An iterable of Examples.

mutate(node, index)

Mutate a node in an operator-specific manner.

Return the new, mutated node. Return None if the node has been deleted. Return node if there is no mutation at all for some reason.

mutation_positions(node)

All positions where this operator can mutate node.

An operator might be able to mutate a node in multiple ways, and this function should produce a position description for each of these mutations. Critically, if an operator can make multiple mutations to the same position, this should produce a position for each of these mutations (i.e. multiple identical positions).

Parameters:node – The AST node being mutated.
Returns:An iterable of ((start-line, start-col), (stop-line, stop-col)) tuples describing the locations where this operator will mutate node.

cosmic_ray.operators.number_replacer module

cosmic_ray.operators.operator module

Implementation of operator base class.

class cosmic_ray.operators.operator.Argument(name: str, description: str)

Bases: object

class cosmic_ray.operators.operator.Example(pre_mutation_code: str, post_mutation_code: str, occurrence: Optional[int] = 0, operator_args: Optional[dict] = None)

Bases: object

A structure to store pre and post mutation operator code snippets, including optional specification of occurrence and operator args.

This is used for testing whether the pre-mutation code is correctly mutated to the post-mutation code at the given occurrence (if specified) and for the given operator args (if specified).

occurrence = 0
operator_args = None
class cosmic_ray.operators.operator.Operator

Bases: abc.ABC

The mutation operator base class.

classmethod arguments() → Sequence[cosmic_ray.operators.operator.Argument]

Sequence of Arguments that the operator accepts.

Returns: A Sequence of Argument instances

classmethod examples()

Examples of the mutations that this operator can make.

This is primarily for testing purposes, but it could also be used for documentation.

Each example takes the following arguments:

pre_mutation_code: code prior to applying the mutation. post_mutation_code: code after (successfully) applying the mutation. occurrence: the index of the occurrence to which the mutation is

applied (optional, default=0).
operator_args: a dictionary of arguments to be **-unpacked to the
operator (optional, default={}).

Returns: An iterable of Examples.

mutate(node, index)

Mutate a node in an operator-specific manner.

Return the new, mutated node. Return None if the node has been deleted. Return node if there is no mutation at all for some reason.

mutation_positions(node)

All positions where this operator can mutate node.

An operator might be able to mutate a node in multiple ways, and this function should produce a position description for each of these mutations. Critically, if an operator can make multiple mutations to the same position, this should produce a position for each of these mutations (i.e. multiple identical positions).

Parameters:node – The AST node being mutated.
Returns:An iterable of ((start-line, start-col), (stop-line, stop-col)) tuples describing the locations where this operator will mutate node.

cosmic_ray.operators.provider module

cosmic_ray.operators.remove_decorator module

cosmic_ray.operators.unary_operator_replacement module

cosmic_ray.operators.util module

Utilities for implementing operators.

cosmic_ray.operators.util.extend_name(suffix)

A factory for class decorators that modify the class name by appending some text to it.

Example:

@extend_name('_Foo')
class Class:
    pass

assert Class.__name__ == 'Class_Foo'

cosmic_ray.operators.zero_iteration_for_loop module

Module contents