### Install Cosmic Ray from source Source: https://github.com/sixty-north/cosmic-ray/blob/master/docs/source/tutorials/intro/index.md Install Cosmic Ray from its source code. This can be done directly or in editable mode. ```bash pip install . ``` ```bash pip install -e . ``` -------------------------------- ### ReplaceBinaryOperator_BitOr_BitXor.examples() Source: https://github.com/sixty-north/cosmic-ray/blob/master/docs/source/reference/api/cosmic_ray.md Provides examples for the ReplaceBinaryOperator_BitOr_BitXor. ```APIDOC ## ReplaceBinaryOperator_BitOr_BitXor.examples() ### Description Provides examples for the ReplaceBinaryOperator_BitOr_BitXor. ### Method N/A (This is a method call, not an HTTP endpoint) ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ### Response Example N/A ``` -------------------------------- ### ReplaceBinaryOperator_BitOr_Add.examples() Source: https://github.com/sixty-north/cosmic-ray/blob/master/docs/source/reference/api/cosmic_ray.md Provides examples for the ReplaceBinaryOperator_BitOr_Add. ```APIDOC ## ReplaceBinaryOperator_BitOr_Add.examples() ### Description Provides examples for the ReplaceBinaryOperator_BitOr_Add. ### Method N/A (This is a method call, not an HTTP endpoint) ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ### Response Example N/A ``` -------------------------------- ### ReplaceBinaryOperator_BitOr_LShift.examples() Source: https://github.com/sixty-north/cosmic-ray/blob/master/docs/source/reference/api/cosmic_ray.md Provides examples for the ReplaceBinaryOperator_BitOr_LShift. ```APIDOC ## ReplaceBinaryOperator_BitOr_LShift.examples() ### Description Provides examples for the ReplaceBinaryOperator_BitOr_LShift. ### Method N/A (This is a method call, not an HTTP endpoint) ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ### Response Example N/A ``` -------------------------------- ### ReplaceBinaryOperator_BitOr_FloorDiv.examples() Source: https://github.com/sixty-north/cosmic-ray/blob/master/docs/source/reference/api/cosmic_ray.md Provides examples for the ReplaceBinaryOperator_BitOr_FloorDiv. ```APIDOC ## ReplaceBinaryOperator_BitOr_FloorDiv.examples() ### Description Provides examples for the ReplaceBinaryOperator_BitOr_FloorDiv. ### Method N/A (This is a method call, not an HTTP endpoint) ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ### Response Example N/A ``` -------------------------------- ### Install a Progress Reporter Source: https://github.com/sixty-north/cosmic-ray/blob/master/docs/source/reference/api/cosmic_ray.md Use this function to install a callable that will report progress. For most use cases, prefer the `progress_reporter` context manager or `reports_progress` decorator factory. ```python cosmic_ray.progress.install_progress_reporter(reporter) ``` -------------------------------- ### ReplaceBinaryOperator_BitAnd_Sub.examples() Source: https://github.com/sixty-north/cosmic-ray/blob/master/docs/source/reference/api/cosmic_ray.md Provides examples for the ReplaceBinaryOperator_BitAnd_Sub. ```APIDOC ## ReplaceBinaryOperator_BitAnd_Sub.examples() ### Description Provides examples for the ReplaceBinaryOperator_BitAnd_Sub. ### Method N/A (This is a method call, not an HTTP endpoint) ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ### Response Example N/A ``` -------------------------------- ### ReplaceBinaryOperator_BitAnd_Add.examples() Source: https://github.com/sixty-north/cosmic-ray/blob/master/docs/source/reference/api/cosmic_ray.md Provides examples for the BitwiseAnd-to-Add binary operator replacement mutation. ```APIDOC ## ReplaceBinaryOperator_BitAnd_Add.examples() ### Description Provides examples for the BitwiseAnd-to-Add binary operator replacement mutation. ### Method This is a method call within a Python class. The specific HTTP method or RPC type is not detailed in the source. ### Endpoint N/A (Python method) ### Parameters Parameters are not explicitly detailed in the source for this method. ### Request Example N/A (Python method) ### Response Response details are not explicitly detailed in the source for this method. ``` -------------------------------- ### ReplaceBinaryOperator_BitAnd_BitXor.examples() Source: https://github.com/sixty-north/cosmic-ray/blob/master/docs/source/reference/api/cosmic_ray.md Provides examples for the BitwiseAnd-to-BitwiseXor binary operator replacement mutation. ```APIDOC ## ReplaceBinaryOperator_BitAnd_BitXor.examples() ### Description Provides examples for the BitwiseAnd-to-BitwiseXor binary operator replacement mutation. ### Method This is a method call within a Python class. The specific HTTP method or RPC type is not detailed in the source. ### Endpoint N/A (Python method) ### Parameters Parameters are not explicitly detailed in the source for this method. ### Request Example N/A (Python method) ### Response Response details are not explicitly detailed in the source for this method. ``` -------------------------------- ### ReplaceBinaryOperator_BitOr_BitAnd.examples() Source: https://github.com/sixty-north/cosmic-ray/blob/master/docs/source/reference/api/cosmic_ray.md Provides examples for the ReplaceBinaryOperator_BitOr_BitAnd. ```APIDOC ## ReplaceBinaryOperator_BitOr_BitAnd.examples() ### Description Provides examples for the ReplaceBinaryOperator_BitOr_BitAnd. ### Method N/A (This is a method call, not an HTTP endpoint) ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ### Response Example N/A ``` -------------------------------- ### ReplaceBinaryOperator_BitOr_Div.examples() Source: https://github.com/sixty-north/cosmic-ray/blob/master/docs/source/reference/api/cosmic_ray.md Provides examples for the ReplaceBinaryOperator_BitOr_Div. ```APIDOC ## ReplaceBinaryOperator_BitOr_Div.examples() ### Description Provides examples for the ReplaceBinaryOperator_BitOr_Div. ### Method N/A (This is a method call, not an HTTP endpoint) ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ### Response Example N/A ``` -------------------------------- ### Install Cosmic Ray with pip Source: https://github.com/sixty-north/cosmic-ray/blob/master/docs/source/tutorials/intro/index.md Install Cosmic Ray using pip. It's generally recommended to do this within a virtual environment. ```bash pip install cosmic-ray ``` -------------------------------- ### ReplaceBinaryOperator_Add_Sub.examples() Source: https://github.com/sixty-north/cosmic-ray/blob/master/docs/source/reference/api/cosmic_ray.md Provides examples for the Add-to-Subtract binary operator replacement mutation. ```APIDOC ## ReplaceBinaryOperator_Add_Sub.examples() ### Description Provides examples for the Add-to-Subtract binary operator replacement mutation. ### Method This is a method call within a Python class. The specific HTTP method or RPC type is not detailed in the source. ### Endpoint N/A (Python method) ### Parameters Parameters are not explicitly detailed in the source for this method. ### Request Example N/A (Python method) ### Response Response details are not explicitly detailed in the source for this method. ``` -------------------------------- ### Install Test Dependencies Source: https://github.com/sixty-north/cosmic-ray/blob/master/docs/source/reference/tests.md Installs the necessary dependencies for testing Cosmic Ray, including development and test-specific packages. ```bash pip install -e .[dev,test] ``` -------------------------------- ### ReplaceBinaryOperator_BitAnd_BitOr.examples() Source: https://github.com/sixty-north/cosmic-ray/blob/master/docs/source/reference/api/cosmic_ray.md Provides examples for the BitwiseAnd-to-BitwiseOr binary operator replacement mutation. ```APIDOC ## ReplaceBinaryOperator_BitAnd_BitOr.examples() ### Description Provides examples for the BitwiseAnd-to-BitwiseOr binary operator replacement mutation. ### Method This is a method call within a Python class. The specific HTTP method or RPC type is not detailed in the source. ### Endpoint N/A (Python method) ### Parameters Parameters are not explicitly detailed in the source for this method. ### Request Example N/A (Python method) ### Response Response details are not explicitly detailed in the source for this method. ``` -------------------------------- ### Cosmic Ray Worker Output Example Source: https://github.com/sixty-north/cosmic-ray/blob/master/docs/source/tutorials/distributed/index.md Example output from a Cosmic Ray worker process, showing mutation application and test execution. ```text [05/16/21 11:31:10] INFO INFO:cosmic_ray.mutating:Applying mutation: path=mod.py, mutating.py:111 op=, occurrence=1 INFO INFO:cosmic_ray.testing:Running test (timeout=10.0): python -m unittest test_mod.py testing.py:36 INFO INFO:aiohttp.access:::1 [16/May/2021:09:31:10 +0000] "POST / HTTP/1.1" 200 899 "-" web_log.py:206 "Python/3.7 aiohttp/3.7.4.post0" INFO INFO:cosmic_ray.mutating:Applying mutation: path=mod.py, mutating.py:111 op=, occurrence=0 INFO INFO:cosmic_ray.testing:Running test (timeout=10.0): python -m unittest test_mod.py testing.py:36 [05/16/21 11:31:11] INFO INFO:aiohttp.access:::1 [16/May/2021:09:31:10 +0000] "POST / HTTP/1.1" 200 899 "-" web_log.py:206 "Python/3.7 aiohttp/3.7.4.post0" ``` -------------------------------- ### ReplaceBinaryOperator_Add_Mul.examples() Source: https://github.com/sixty-north/cosmic-ray/blob/master/docs/source/reference/api/cosmic_ray.md Provides examples for the Add-to-Multiply binary operator replacement mutation. ```APIDOC ## ReplaceBinaryOperator_Add_Mul.examples() ### Description Provides examples for the Add-to-Multiply binary operator replacement mutation. ### Method This is a method call within a Python class. The specific HTTP method or RPC type is not detailed in the source. ### Endpoint N/A (Python method) ### Parameters Parameters are not explicitly detailed in the source for this method. ### Request Example N/A (Python method) ### Response Response details are not explicitly detailed in the source for this method. ``` -------------------------------- ### ReplaceBinaryOperator_Add_RShift.examples() Source: https://github.com/sixty-north/cosmic-ray/blob/master/docs/source/reference/api/cosmic_ray.md Provides examples for the Add-to-RightShift binary operator replacement mutation. ```APIDOC ## ReplaceBinaryOperator_Add_RShift.examples() ### Description Provides examples for the Add-to-RightShift binary operator replacement mutation. ### Method This is a method call within a Python class. The specific HTTP method or RPC type is not detailed in the source. ### Endpoint N/A (Python method) ### Parameters Parameters are not explicitly detailed in the source for this method. ### Request Example N/A (Python method) ### Response Response details are not explicitly detailed in the source for this method. ``` -------------------------------- ### ReplaceBinaryOperator_Add_Pow.examples() Source: https://github.com/sixty-north/cosmic-ray/blob/master/docs/source/reference/api/cosmic_ray.md Provides examples for the Add-to-Power binary operator replacement mutation. ```APIDOC ## ReplaceBinaryOperator_Add_Pow.examples() ### Description Provides examples for the Add-to-Power binary operator replacement mutation. ### Method This is a method call within a Python class. The specific HTTP method or RPC type is not detailed in the source. ### Endpoint N/A (Python method) ### Parameters Parameters are not explicitly detailed in the source for this method. ### Request Example N/A (Python method) ### Response Response details are not explicitly detailed in the source for this method. ``` -------------------------------- ### Start an HTTP Worker Source: https://github.com/sixty-north/cosmic-ray/blob/master/docs/source/tutorials/distributed/index.md Command to start a Cosmic Ray HTTP worker. Ensure the worker runs in the same directory as your project's tests. ```bash cd $ROOT cosmic-ray --verbosity INFO http-worker --port 9876 ``` -------------------------------- ### HttpDistributor Configuration Source: https://github.com/sixty-north/cosmic-ray/blob/master/docs/source/reference/api/cosmic_ray.distribution.md Configuration example for enabling and setting up the HTTP distributor in Cosmic Ray. ```APIDOC ## Enabling the distributor To use the http distributor, set `cosmic-ray.distributor.name = "http"` in your Cosmic Ray configuration, and configure the list of worker URLs in `cosmic-ray.distributor.http.worker-urls`: ```toml [cosmic-ray.distributor] name = "http" [cosmic-ray.distributor.http] worker-urls = ['http://localhost:9876', 'http://localhost:9877'] ``` ``` -------------------------------- ### ReplaceBinaryOperator_Mul_LShift.examples Source: https://github.com/sixty-north/cosmic-ray/blob/master/docs/source/reference/api/cosmic_ray.operators.md Provides examples of mutations that can be made by the ReplaceBinaryOperator_Mul_LShift operator. ```APIDOC ## ReplaceBinaryOperator_Mul_LShift.examples() ### Description 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. ``` -------------------------------- ### ReplaceBinaryOperator_Mul_FloorDiv.examples Source: https://github.com/sixty-north/cosmic-ray/blob/master/docs/source/reference/api/cosmic_ray.operators.md Provides examples of mutations that can be made by the ReplaceBinaryOperator_Mul_FloorDiv operator. ```APIDOC ## ReplaceBinaryOperator_Mul_FloorDiv.examples() ### Description 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. ``` -------------------------------- ### Start HTTP Workers with cr-http-workers Source: https://github.com/sixty-north/cosmic-ray/blob/master/docs/source/tutorials/distributed/index.md Start multiple HTTP workers using cr-http-workers. This command reads the configuration file for worker endpoints and clones the specified git repository for each worker. ```bash cr-http-workers config.toml . ``` -------------------------------- ### LocalDistributor Configuration Source: https://github.com/sixty-north/cosmic-ray/blob/master/docs/source/reference/api/cosmic_ray.distribution.md Configuration example for enabling the local distributor in Cosmic Ray. ```APIDOC ## Enabling the distributor To use the local distributor, set `cosmic-ray.distributor.name = "local"` in your Cosmic Ray configuration: ```toml [cosmic-ray.distributor] name = "local" ``` ``` -------------------------------- ### ReplaceBinaryOperator_Mul_Mod.examples Source: https://github.com/sixty-north/cosmic-ray/blob/master/docs/source/reference/api/cosmic_ray.operators.md Provides examples of mutations that can be made by the ReplaceBinaryOperator_Mul_Mod operator. ```APIDOC ## ReplaceBinaryOperator_Mul_Mod.examples() ### Description 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. ``` -------------------------------- ### Navigate to Example Project Directory Source: https://github.com/sixty-north/cosmic-ray/blob/master/docs/source/reference/tests.md Changes the current directory to the 'test_project' for running 'adam' tests. ```bash cd tests/example_project ``` -------------------------------- ### ReplaceUnaryOperator_Invert_Not Source: https://github.com/sixty-north/cosmic-ray/blob/master/docs/source/reference/api/cosmic_ray.operators.md This operator inverts the logical NOT operator. It provides methods to get mutation positions and examples of its usage. ```APIDOC ## ReplaceUnaryOperator_Invert_Not ### Description This class represents an operator that mutates by inverting a logical NOT operator. It inherits from the base `Operator` class and provides methods for generating mutation positions and examples. ### Methods #### `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`. #### `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. ``` -------------------------------- ### ReplaceBinaryOperator_BitAnd_FloorDiv.examples Source: https://github.com/sixty-north/cosmic-ray/blob/master/docs/source/reference/api/cosmic_ray.operators.md Provides examples of mutations that this operator can make, primarily for testing and documentation. ```APIDOC ## examples() ### Description 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. ``` -------------------------------- ### Minimal setup.py for an operator package Source: https://github.com/sixty-north/cosmic-ray/blob/master/docs/source/how-tos/operators.md Provides the basic structure for a Python package using setuptools, necessary for defining entry points for Cosmic Ray plugins. ```python from setuptools import setup setup( name='example', version='0.1.0', ) ``` -------------------------------- ### ReplaceUnaryOperator_Invert_UAdd Source: https://github.com/sixty-north/cosmic-ray/blob/master/docs/source/reference/api/cosmic_ray.operators.md This operator inverts the unary plus operator. It provides methods to get mutation positions and examples of its usage. ```APIDOC ## ReplaceUnaryOperator_Invert_UAdd ### Description This class represents an operator that mutates by inverting a unary plus operator. It inherits from the base `Operator` class and provides methods for generating mutation positions and examples. ### Methods #### `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`. #### `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. ``` -------------------------------- ### Generate Skeleton Configuration (`cosmic-ray new-config`) Source: https://context7.com/sixty-north/cosmic-ray/llms.txt Interactively creates a starter TOML configuration file. Review and edit the generated file before use. ```bash # Interactive wizard — answer the prompts: cosmic-ray new-config config.toml # [?] Top-level module path: src/mypackage # [?] Test execution timeout (seconds): 30 # [?] Test command: python -m pytest tests/ -x -q # -- MENU: Distributor -- # (0) http # (1) local # [?] Enter menu selection: 1 # Result: config.toml is written with the answers above. cat config.toml # [cosmic-ray] # module-path = "src/mypackage" # timeout = 30.0 # excluded-modules = [] # test-command = "python -m pytest tests/ -x -q" # # [cosmic-ray.distributor] # name = "local" ``` -------------------------------- ### ReplaceBinaryOperator_RShift_BitOr Source: https://github.com/sixty-north/cosmic-ray/blob/master/docs/source/reference/api/cosmic_ray.operators.md This operator replaces binary operators with bitwise OR. It provides methods to get mutation positions and examples of its usage. ```APIDOC ## ReplaceBinaryOperator_RShift_BitOr ### Description This class represents an operator that replaces binary operators with bitwise OR. It inherits from the base `Operator` class. ### Methods #### `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`. ``` -------------------------------- ### Sample Project Module Source: https://github.com/sixty-north/cosmic-ray/blob/master/docs/source/tutorials/distributed/index.md This is a simple Python module used for demonstrating mutation testing. ```python def func(): return 1234 ``` -------------------------------- ### ReplaceBinaryOperator_RShift_BitAnd Source: https://github.com/sixty-north/cosmic-ray/blob/master/docs/source/reference/api/cosmic_ray.operators.md This operator replaces binary operators with bitwise AND. It provides methods to get mutation positions and examples of its usage. ```APIDOC ## ReplaceBinaryOperator_RShift_BitAnd ### Description This class represents an operator that replaces binary operators with bitwise AND. It inherits from the base `Operator` class. ### Methods #### `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`. ``` -------------------------------- ### ReplaceBinaryOperator_Sub_BitAnd Source: https://github.com/sixty-north/cosmic-ray/blob/master/docs/source/reference/api/cosmic_ray.operators.md This operator replaces binary operators. It provides methods to get mutation positions, generate examples, and perform mutations. ```APIDOC ## ReplaceBinaryOperator_Sub_BitAnd ### Description This class represents an operator that replaces binary operators. It inherits from the base `Operator` class and provides specific implementations for mutation. ### Methods #### 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`. #### 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. ``` -------------------------------- ### ReplaceBinaryOperator_Sub_Add Source: https://github.com/sixty-north/cosmic-ray/blob/master/docs/source/reference/api/cosmic_ray.operators.md This operator replaces binary operators. It provides methods to get mutation positions, generate examples, and perform mutations. ```APIDOC ## ReplaceBinaryOperator_Sub_Add ### Description This class represents an operator that replaces binary operators. It inherits from the base `Operator` class and provides specific implementations for mutation. ### Methods #### 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`. #### 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. ``` -------------------------------- ### ReplaceBinaryOperator_RShift_Sub Source: https://github.com/sixty-north/cosmic-ray/blob/master/docs/source/reference/api/cosmic_ray.operators.md This operator replaces binary operators. It provides methods to get mutation positions, generate examples, and perform mutations. ```APIDOC ## ReplaceBinaryOperator_RShift_Sub ### Description This class represents an operator that replaces binary operators. It inherits from the base `Operator` class and provides specific implementations for mutation. ### Methods #### 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`. #### 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. ``` -------------------------------- ### ReplaceBinaryOperator_RShift_BitXor Source: https://github.com/sixty-north/cosmic-ray/blob/master/docs/source/reference/api/cosmic_ray.operators.md This operator replaces binary operators with bitwise XOR. It provides methods to get mutation positions and examples of its usage. ```APIDOC ## ReplaceBinaryOperator_RShift_BitXor ### Description This class represents an operator that replaces binary operators with bitwise XOR. It inherits from the base `Operator` class. ### Methods #### `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`. ``` -------------------------------- ### ReplaceBinaryOperator_Mod_Sub Source: https://github.com/sixty-north/cosmic-ray/blob/master/docs/source/reference/api/cosmic_ray.operators.md This operator replaces binary operators like modulo with subtraction. It provides methods to get mutation positions and examples of its usage. ```APIDOC ## ReplaceBinaryOperator_Mod_Sub ### Description This class represents an operator that replaces binary operators with subtraction. It inherits from the base Operator class. ### Methods #### examples() Examples of the mutations that this operator can make. This is primarily for testing purposes, but it could also be used for documentation. #### 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`. ``` -------------------------------- ### ReplaceBinaryOperator_BitXor_Mod Source: https://github.com/sixty-north/cosmic-ray/blob/master/docs/source/reference/api/cosmic_ray.operators.md This operator replaces binary XOR operations with modulo operations. It provides methods to get mutation positions and examples of its usage. ```APIDOC ## ReplaceBinaryOperator_BitXor_Mod ### Description This class represents an operator that replaces binary XOR operations with modulo operations. It inherits from the base `Operator` class. ### Methods #### `classmethod examples()` Provides examples of mutations this operator can make, useful for testing and documentation. It takes `pre_mutation_code`, `post_mutation_code`, `occurrence`, and `operator_args` as arguments and returns an iterable of Examples. #### `mutate(node, index)` Mutates a node in an operator-specific manner. Returns the new, mutated node, `None` if the node is deleted, or the original `node` if no mutation occurs. #### `mutation_positions(node)` Returns all positions where this operator can mutate the given `node`. It yields tuples of `((start-line, start-col), (stop-line, stop-col))` for each possible mutation. ``` -------------------------------- ### ReplaceUnaryOperator_Delete_Not Operator Source: https://github.com/sixty-north/cosmic-ray/blob/master/docs/source/reference/api/cosmic_ray.md Replaces the unary `not` operator with a deletion. Provides methods to get examples, mutate code, and find mutation positions. ```APIDOC ## ReplaceUnaryOperator_Delete_Not ### Description Replaces the unary `not` operator with a deletion. ### Methods - `examples()`: Returns a list of examples for this operator. - `mutate(module_path, name, ast)`: Mutates the given AST. - `mutation_positions(module_path, name, ast)`: Returns a list of possible mutation positions. ``` -------------------------------- ### Registering the operator provider via setup.py Source: https://github.com/sixty-north/cosmic-ray/blob/master/docs/source/how-tos/operators.md Configures the `setup.py` file to register the custom operator provider with Cosmic Ray using setuptools' `entry_points` mechanism. ```python setup( . . . entry_points={ 'cosmic_ray.operator_providers': [ 'example = example.provider:Provider' ] }) ``` -------------------------------- ### ReplaceBinaryOperator_Mul_Sub Source: https://github.com/sixty-north/cosmic-ray/blob/master/docs/source/reference/api/cosmic_ray.operators.md This class represents an operator that replaces multiplication (*) with subtraction (-) in binary operations. It provides methods to get mutation positions and examples of its usage. ```APIDOC ## ReplaceBinaryOperator_Mul_Sub ### Description This operator replaces multiplication (*) with subtraction (-) in binary operations. ### Methods #### mutation_positions(node) All positions where this operator can mutate `node`. * **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`. #### examples() Examples of the mutations that this operator can make. 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. ``` -------------------------------- ### ReplaceBinaryOperator_Mul_Pow Source: https://github.com/sixty-north/cosmic-ray/blob/master/docs/source/reference/api/cosmic_ray.operators.md This class represents an operator that replaces multiplication (*) with exponentiation (**) in binary operations. It provides methods to get mutation positions and examples of its usage. ```APIDOC ## ReplaceBinaryOperator_Mul_Pow ### Description This operator replaces multiplication (*) with exponentiation (**) in binary operations. ### Methods #### mutation_positions(node) All positions where this operator can mutate `node`. * **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`. #### examples() Examples of the mutations that this operator can make. 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. ``` -------------------------------- ### ReplaceBinaryOperator_FloorDiv_Pow Source: https://github.com/sixty-north/cosmic-ray/blob/master/docs/source/reference/api/cosmic_ray.operators.md This class represents an operator that replaces floor division with power operations. It provides methods to get mutation positions and examples of its usage. ```APIDOC ## ReplaceBinaryOperator_FloorDiv_Pow ### Description This operator replaces floor division operations with power operations. ### Methods #### mutation_positions(node) All positions where this operator can mutate `node`. * **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`. #### examples() Examples of the mutations that this operator can make. Returns: An iterable of Examples. ``` -------------------------------- ### Badge Configuration Example Source: https://github.com/sixty-north/cosmic-ray/blob/master/docs/source/reference/badge.md Configure the badge's label, format, and color thresholds. Thresholds define the percentage ranges for different badge colors. ```ini [cosmic-ray.badge] label = "mutation" format = "%.2f %%" [cosmic-ray.badge.thresholds] 50 = 'red' 70 = 'orange' 100 = 'yellow' 101 = 'green' ``` -------------------------------- ### ReplaceBinaryOperator_BitAnd_Mul Source: https://github.com/sixty-north/cosmic-ray/blob/master/docs/source/reference/api/cosmic_ray.operators.md This operator replaces bitwise AND operators with multiplication. It provides methods to get mutation examples, perform mutations, and identify mutation positions. ```APIDOC ## class cosmic_ray.operators.binary_operator_replacement.ReplaceBinaryOperator_BitAnd_Mul ### Description This operator replaces bitwise AND operators with multiplication. ### Methods #### examples() *classmethod* Examples of the mutations that this operator can make. This is primarily for testing purposes, but it could also be used for documentation. #### 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`. ``` -------------------------------- ### ReplaceBinaryOperator_Add_RShift Source: https://github.com/sixty-north/cosmic-ray/blob/master/docs/source/reference/api/cosmic_ray.operators.md This operator replaces binary operators like addition with right shift. It provides methods to get mutation positions and examples of its usage. ```APIDOC ## ReplaceBinaryOperator_Add_RShift ### Description This class represents an operator that replaces binary addition operations with a right shift operation. ### Methods #### mutation_positions(node) All positions where this operator can mutate `node`. * **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`. #### examples() Examples of the mutations that this operator can make. * **Returns:** An iterable of Examples. #### mutate(node, index) Mutate a node in an operator-specific manner. * **Parameters:** **node** – The AST node to mutate. **index** – The index of the mutation occurrence. * **Returns:** The new, mutated node. Returns `None` if the node has been deleted. Returns `node` if there is no mutation. ``` -------------------------------- ### ReplaceUnaryOperator_Delete_USub Operator Source: https://github.com/sixty-north/cosmic-ray/blob/master/docs/source/reference/api/cosmic_ray.md Replaces the unary subtraction operator (`-`) with a deletion. Provides methods to get examples, mutate code, and find mutation positions. ```APIDOC ## ReplaceUnaryOperator_Delete_USub ### Description Replaces the unary subtraction operator (`-`) with a deletion. ### Methods - `examples()`: Returns a list of examples for this operator. - `mutate(module_path, name, ast)`: Mutates the given AST. - `mutation_positions(module_path, name, ast)`: Returns a list of possible mutation positions. ``` -------------------------------- ### Sample Project Test Suite Source: https://github.com/sixty-north/cosmic-ray/blob/master/docs/source/tutorials/distributed/index.md This is a basic unittest suite for the sample module, used to verify mutation testing results. ```python import unittest import mod class Tests(unittest.TestCase): def test_func(self): self.assertEqual(mod.func(), 1234) ``` -------------------------------- ### cosmic_ray.commands.init.init Source: https://github.com/sixty-north/cosmic-ray/blob/master/docs/source/reference/api/cosmic_ray.commands.md Clears and initializes a work-db with new work items, replacing any existing data. ```APIDOC ## init ### Description Clear and initialize a work-db with work items. Any existing data in the work-db will be cleared and replaced with entirely new work orders. In particular, this means that any results in the db are removed. ### Parameters * **module_paths** – iterable of pathlib.Paths of modules to mutate. * **work_db** – A WorkDB instance into which the work orders will be saved. * **operator_cfgs** – A dict mapping operator names to parameterization dicts. ### Raises **TypeError** – Arguments provided for an operator are invalid. ### Signature init(module_paths, work_db: WorkDB, operator_cfgs) ``` -------------------------------- ### ReplaceUnaryOperator_Delete_Invert Operator Source: https://github.com/sixty-north/cosmic-ray/blob/master/docs/source/reference/api/cosmic_ray.md Replaces the unary inversion operator (`-`) with a deletion. Provides methods to get examples, mutate code, and find mutation positions. ```APIDOC ## ReplaceUnaryOperator_Delete_Invert ### Description Replaces the unary inversion operator (`-`) with a deletion. ### Methods - `examples()`: Returns a list of examples for this operator. - `mutate(module_path, name, ast)`: Mutates the given AST. - `mutation_positions(module_path, name, ast)`: Returns a list of possible mutation positions. ``` -------------------------------- ### NumberReplacer Operator Source: https://github.com/sixty-north/cosmic-ray/blob/master/docs/source/reference/api/cosmic_ray.md The NumberReplacer operator mutates numerical literals. It provides methods to get examples, mutate code, and find mutation positions. ```APIDOC ## NumberReplacer ### Description Mutates numerical literals. ### Methods - `examples()`: Returns a list of examples for this operator. - `mutate(module_path, name, ast)`: Mutates the given AST. - `mutation_positions(module_path, name, ast)`: Returns a list of possible mutation positions. ``` -------------------------------- ### ReplaceBinaryOperator_Sub_FloorDiv Source: https://github.com/sixty-north/cosmic-ray/blob/master/docs/source/reference/api/cosmic_ray.operators.md This operator replaces subtraction operations with floor division. It provides methods to get mutation examples, mutate nodes, and identify mutation positions. ```APIDOC ## ReplaceBinaryOperator_Sub_FloorDiv ### Description This class represents an operator that replaces subtraction operations with floor division. ### Methods #### examples() *classmethod* Examples of the mutations that this operator can make. This is primarily for testing purposes, but it could also be used for documentation. #### 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`. ``` -------------------------------- ### Apply cr-filter-pragma after init Source: https://github.com/sixty-north/cosmic-ray/blob/master/docs/source/how-tos/filters.md This example shows how to first initialize a session with all possible mutations and then apply the `cr-filter-pragma` to skip mutations on lines with a pragma comment. ```bash cosmic-ray init cr.conf session.sqlite cr-filter-pragma session.sqlite ``` -------------------------------- ### ReplaceBinaryOperator_Pow_Sub Source: https://github.com/sixty-north/cosmic-ray/blob/master/docs/source/reference/api/cosmic_ray.operators.md This operator replaces the power (**) operator with a subtraction (-) operator. It provides methods to get mutation examples, perform mutations, and identify mutation positions. ```APIDOC ## class cosmic_ray.operators.binary_operator_replacement.ReplaceBinaryOperator_Pow_Sub ### Description This operator replaces the power (**) operator with a subtraction (-) operator. #### *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. * **Parameters:** **node** – The AST node being mutated. **index** – The index of the mutation to apply. * **Returns:** The mutated node, `None` if deleted, or the original node if no mutation occurred. #### 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`. ``` -------------------------------- ### ReplaceBinaryOperator_Mul_RShift Source: https://github.com/sixty-north/cosmic-ray/blob/master/docs/source/reference/api/cosmic_ray.operators.md This class represents an operator that replaces multiplication (*) with right shift (>>) in binary operations. It provides methods to get mutation positions and examples of its usage. ```APIDOC ## ReplaceBinaryOperator_Mul_RShift ### Description This operator replaces multiplication (*) with right shift (>>) in binary operations. ### Methods #### mutation_positions(node) All positions where this operator can mutate `node`. * **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`. #### examples() Examples of the mutations that this operator can make. 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. ```