Skip to content

Commit

Permalink
🧪 mutator plugin tests
Browse files Browse the repository at this point in the history
  • Loading branch information
WiredNerd committed May 9, 2024
1 parent 299a45d commit 64b6fe6
Show file tree
Hide file tree
Showing 34 changed files with 1,932 additions and 629 deletions.
2 changes: 2 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"python.testing.pytestArgs": [
"-vv",
"-s",
// "--sort-mode=ordered",
"tests"
],
"python.analysis.extraPaths": [
Expand Down Expand Up @@ -45,4 +46,5 @@
],
"scss.format.preserveNewLines": false,
"scss.format.newlineBetweenSelectors": false,
"terminal.integrated.cwd": "C:\\DEVPY"
}
13 changes: 12 additions & 1 deletion notes.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@
"Decorator: instead of replacing func, replace only the decorator part"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import ast\n",
"\n",
"print(ast.dump(ast.parse(\"a = f'abc{a}def'\"),indent=4))"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -52,7 +63,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.0"
"version": "3.12.3"
}
},
"nbformat": 4,
Expand Down
13 changes: 7 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ where = ["src"]
[tool.pytest.ini_options]
pythonpath = ["src", "tests"]
testpaths = ["tests"]
addopts = "-vv --cov-reset --cov-report=html:cov-html --cov-report=term"
addopts = "-vv --cov-reset --cov-report=html:cov-html --cov-report=term --cov-context=test"
sort_mode = "random"
sort_bucket = "session"
filterwarnings = [
Expand All @@ -77,6 +77,7 @@ command_line = "pytest -x --assert=plain -o pythonpath='{PYTHONPATH}' --sort-mod

[tool.coverage.run]
branch = true
include = ["src/**"]

[tool.coverage.report]
skip_empty = true
Expand All @@ -98,9 +99,9 @@ mypy_path = "src,tests"

[tool.ruff]
target-version = "py39"
show-source = true
select = ["ALL"]
ignore = [
output-format = "full"
lint.select = ["ALL"]
lint.ignore = [
"COM812", # missing-trailing-comma
"D203", # 1 blank line required before class docstring
"D213", # multi-line-summary-second-line
Expand Down Expand Up @@ -133,12 +134,12 @@ exclude = [
"dist",
"venv",
]
task-tags = ["nomut", "TODO", "FIXME", "XXX"]
lint.task-tags = ["nomut", "TODO", "FIXME", "XXX"]

[tool.ruff.lint.isort]
known-first-party = ["poodle"]

[tool.ruff.per-file-ignores]
[tool.ruff.lint.per-file-ignores]
"src/*/__init__.py" = [
"F401", # imported but unused
"F403", # import * used
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ pysass
pytest
pytest-sort>=1.3.0
pytest-cov
coverage[toml]

mock-decorator
2 changes: 1 addition & 1 deletion src/poodle/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
Mutant,
MutantTrial,
MutantTrialResult,
RunResult,
TestingResults,
TestingSummary,
RunResult,
)
from poodle.common.echo_wrapper import EchoWrapper
from poodle.common.exceptions import (
Expand Down
1 change: 1 addition & 0 deletions src/poodle/common/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations


class PoodleTestingFailedError(Exception):
"""Poodle testing failed."""

Expand Down
2 changes: 1 addition & 1 deletion src/poodle/common/hook_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import pluggy

from .config import PoodleConfigData
from .data import FileMutation, Mutant, TestingResults, RunResult
from .data import FileMutation, Mutant, RunResult, TestingResults
from .echo_wrapper import EchoWrapper
from .option_collector import PoodleOptionCollector

Expand Down
16 changes: 8 additions & 8 deletions src/poodle/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ def main_process(config_data: PoodleConfigData, secho: EchoWrapper) -> None:


poodle_header_str = r"""
|\/|\/|\/|\/|\/|\/|\/|\/|\/|\/|\/|\/|\/|\/|\/|\/|
____ ____ ''',
/ __ \____ ____ ____/ / /__ o_)O \)____)"
/ /_/ / __ \/ __ \/ __ / / _ \ \_ )
/ ____/ /_/ / /_/ / /_/ / / __/ '',,,,,,
/_/ \____/\____/\__,_/_/\___/ || ||
Mutation Tester Version {version:<15} "--'"--'
|/\|/\|/\|/\|/\|/\|/\|/\|/\|/\|/\|/\|/\|/\|/\|/\|
|\/|\/|\/|\/|\/|\/|\/|\/|\/|\/|\/|\/|\/|\/|\/|\/|\/|\/|\/|\/|\/|
____ ____ ''', ''',
/ __ \____ ____ ____/ / /__ o_)O \)____)" o_)O \)____)"
/ /_/ / __ \/ __ \/ __ / / _ \ \_ ) \_ )
/ ____/ /_/ / /_/ / /_/ / / __/ '',,,,,, '',,,,,,
/_/ \____/\____/\__,_/_/\___/ || || || ||
Mutation Tester Version {version:<15} "--'"--' "--'"--'
|/\|/\|/\|/\|/\|/\|/\|/\|/\|/\|/\|/\|/\|/\|/\|/\|/\|/\|/\|/\|/\|
"""

Expand Down
3 changes: 2 additions & 1 deletion src/poodle/mutators/mutator_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ def create_mutations(self, parsed_ast: ast.Module, config: PoodleConfigData) ->

def visit_Compare(self, node: ast.Compare) -> None:
"""Identify replacement Operations and create Mutants."""

for idx, op in enumerate(node.ops):
if type(op) not in self.type_map:
continue
for new_op in self.type_map[type(op)]:
mut = deepcopy(node)
mut.ops[idx] = new_op()
Expand Down
2 changes: 1 addition & 1 deletion src/poodle/mutators/mutator_lambda.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def visit_Lambda(self, node: ast.Lambda) -> None:
"""Replace body of Lambda with None or empty string."""
if isinstance(node.body, ast.Constant) and node.body.value is None:
mut = deepcopy(node)
mut.body = ast.Constant("")
mut.body = ast.Constant(" ")
self.mutants.append(self.create_file_mutation(mut, ast.unparse(mut)))
else:
mut = deepcopy(node)
Expand Down
8 changes: 4 additions & 4 deletions src/poodle/mutators/mutator_operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import pluggy

from poodle import FileMutation, MutatorBase, PoodleConfigData, EchoWrapper
from poodle import EchoWrapper, FileMutation, MutatorBase, PoodleConfigData

hookimpl = pluggy.HookimplMarker("poodle")

Expand Down Expand Up @@ -66,7 +66,7 @@ class OperationMutator(ast.NodeVisitor, MutatorBase):
ast.RShift: [ast.LShift],
ast.BitOr: [ast.BitAnd],
ast.BitXor: [ast.BitOr, ast.BitAnd],
ast.BitAnd: [ast.BitOr],
ast.BitAnd: [ast.BitOr, ast.BitXor],
},
"max": {
ast.Add: [ast.Sub, ast.Mult, ast.Div, ast.FloorDiv, ast.Mod, ast.Pow],
Expand All @@ -84,10 +84,10 @@ class OperationMutator(ast.NodeVisitor, MutatorBase):
},
}

@hookimpl()
@hookimpl(specname="configure")
def configure(self, config: PoodleConfigData, secho: EchoWrapper) -> None:
mutator_opts = config.merge_dict_from_config("mutator_opts", {})
level = mutator_opts.get("operator_level", "std")
level = str(mutator_opts.get("operator_level", "std")).lower()

if level not in self.type_map_levels:
secho(f"WARN: Invalid value operator_opts.operator_level={level}. Using Default value 'std'", fg="yellow")
Expand Down
4 changes: 2 additions & 2 deletions src/poodle/mutators/mutator_subscript.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def create_mutations(self, parsed_ast: ast.Module, config: PoodleConfigData) ->
"""Visit all nodes and return created mutants."""
if not self.is_enabled(config):
return []

self.mutants = []
self.visit(parsed_ast)
return self.mutants
Expand All @@ -37,5 +37,5 @@ def visit_Subscript(self, node: ast.Subscript) -> None:
"""Replace Call to retrieve from Dict or Array with None."""
if self.is_annotation(node):
return

self.mutants.append(self.create_file_mutation(node, "None"))
2 changes: 1 addition & 1 deletion src/poodle/reporters/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

from . import reporter_html, reporter_json, reporter_sysout

reporter_plugins = [reporter_html, reporter_json, reporter_sysout]
reporter_plugins = [reporter_html, reporter_json, reporter_sysout]
2 changes: 1 addition & 1 deletion tests/common/test_config_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ def test_get_option_from_config_no_cmd(self):
config.poodle_config = mock.MagicMock()
config.poodle_config.test_option = "pc_data"
config.config_file_data = {"test_option": "file_data"}
assert config.get_option_from_config("test_option","option") == ("pc_data", "poodle_config.py")
assert config.get_option_from_config("test_option", "option") == ("pc_data", "poodle_config.py")

def test_get_option_from_config_pc(self):
config = config_base.PoodleConfigBase()
Expand Down
5 changes: 3 additions & 2 deletions tests/common/test_config_util.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
from __future__ import annotations

import importlib
import sys
from pathlib import Path
from unittest import mock

import pytest

from poodle.common import config_util
import sys
import importlib

m_name = config_util.__name__


@pytest.fixture(autouse=True)
def _reset() -> None:
importlib.reload(config_util)
Expand Down
Empty file removed tests/data_types/__init__.py
Empty file.
Loading

0 comments on commit 64b6fe6

Please sign in to comment.