Skip to content

Commit

Permalink
3.1.0 maintenance
Browse files Browse the repository at this point in the history
  • Loading branch information
EvanKepner committed Feb 20, 2022
1 parent d1a2aa1 commit 41fa40e
Show file tree
Hide file tree
Showing 11 changed files with 88 additions and 88 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# custom
.vscode/
.idea/
htmlcov/
pip-wheel-metadata/
Expand Down
10 changes: 3 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
exclude: ^notebooks/
repos:
- repo: https://github.com/psf/black
rev: stable
rev: 22.1.0
hooks:
- id: black
#files: ^mutatest/
files: ^mutatest/
types: [file, python]
language_version: python3.7

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.4.0
rev: v4.1.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: debug-statements
- id: flake8
files: ^mutatest/
language_version: python3.7
7 changes: 6 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ Changelog
Stable Releases
---------------

3.1.0
~~~~~

- Maintenance patches and API changes to skip/only category selection.

3.0.2
~~~~~

Expand Down Expand Up @@ -156,7 +161,7 @@ Alpha Releases
0.9.1
~~~~~

- Added ``--whitelist`` and ``--blacklist`` with category codes for mutation families.
- Added ``--only`` and ``--skip`` with category codes for mutation families.
- Provides CLI selection of mutation types to be used during the trials.


Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
``mutatest``: Python mutation testing
==========================================

| |py-versions| |license| |ci-azure| |ci-travis| |docs| |coverage| |black|
| |py-versions| |license| |ci-azure| |docs| |coverage| |black|
| |pypi-version| |pypi-status| |pypi-format| |pypi-downloads|
| |conda-version| |conda-recipe| |conda-platform| |conda-downloads|
Expand Down
22 changes: 11 additions & 11 deletions docs/commandline.rst
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ Selecting categories of mutations

``mutatest`` categorizes families of mutations with two-letter category codes (available in
the help output and in the mutants section below). You can use these category codes in the
``--whitelist`` and ``--blacklist`` arguments to opt-in or opt-out of types of mutations
``--only`` and ``--skip`` arguments to opt-in or opt-out of types of mutations
for your trials. This impacts the pool of potential locations to draw from for the sample, but the
number of mutations specified in ``--nlocations`` still determines the final sample size.
You will see the categories used in the output during the trial. Categories are space delimited
Expand All @@ -207,7 +207,7 @@ as an input list on the CLI.
.. code-block::
# selects only the categories "aa" (AugAssign), "bn" (BinOp), and "ix" (Index) mutations
$ mutatest --whitelist aa bn ix
$ mutatest --only aa bn ix
... prior output...
Expand All @@ -220,13 +220,13 @@ as an input list on the CLI.
... continued output...
# using shorthand
$ mutatest -w aa bn ix
$ mutatest -y aa bn ix
# using the blacklist instead, selects all categories except "aa", "bn", and "ix"
$ mutatest --blacklist aa bn ix
# using the skip list instead, selects all categories except "aa", "bn", and "ix"
$ mutatest --skip aa bn ix
# with shorthand
$ mutatest -b aa bn ix
$ mutatest -k aa bn ix
Setting the output location
Expand Down Expand Up @@ -366,8 +366,8 @@ Run ``mutatest --help`` to see command line arguments and supported operations:
optional arguments:
-h, --help show this help message and exit
-b [STR [STR ...]], --blacklist [STR [STR ...]]
Blacklisted mutation categories for trials. (default: empty list)
-k [STR [STR ...]], --skip [STR [STR ...]]
Mutation categories to skip for trials. (default: empty list)
-e PATH, --exclude PATH
Path to .py file to exclude, multiple -e entries supported. (default: None)
-m {f,s,d,sd}, --mode {f,s,d,sd}
Expand All @@ -380,8 +380,8 @@ Run ``mutatest --help`` to see command line arguments and supported operations:
-s PATH, --src PATH Source code (file or directory) for mutation testing. (default: auto-detection attempt).
-t STR_CMDS, --testcmds STR_CMDS
Test command string to execute. (default: 'pytest')
-w [STR [STR ...]], --whitelist [STR [STR ...]]
Whitelisted mutation categories for trials. (default: empty list)
-y [STR [STR ...]], --only [STR [STR ...]]
Only mutation categories to use for trials. (default: empty list)
-x INT, --exception INT
Count of survivors to raise Mutation Exception for system exit.
--debug Turn on DEBUG level logging output.
Expand Down Expand Up @@ -423,7 +423,7 @@ The contents of an example ``mutatest.ini`` or entry in ``setup.cfg``:
[mutatest]
blacklist = nc su ix
skip = nc su ix
exclude =
mutatest/__init__.py
mutatest/_devtools.py
Expand Down
8 changes: 4 additions & 4 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ Run ``mutatest --help`` to see command line arguments and supported operations:
optional arguments:
-h, --help show this help message and exit
-b [STR [STR ...]], --blacklist [STR [STR ...]]
Blacklisted mutation categories for trials. (default: empty list)
-k [STR [STR ...]], --skip [STR [STR ...]]
Mutation categories to skip for trials. (default: empty list)
-e PATH, --exclude PATH
Path to .py file to exclude, multiple -e entries supported. (default: None)
-m {f,s,d,sd}, --mode {f,s,d,sd}
Expand All @@ -107,8 +107,8 @@ Run ``mutatest --help`` to see command line arguments and supported operations:
-s PATH, --src PATH Source code (file or directory) for mutation testing. (default: auto-detection attempt).
-t STR_CMDS, --testcmds STR_CMDS
Test command string to execute. (default: 'pytest')
-w [STR [STR ...]], --whitelist [STR [STR ...]]
Whitelisted mutation categories for trials. (default: empty list)
-y [STR [STR ...]], --only [STR [STR ...]]
Only mutation categories to use for trials. (default: empty list)
-x INT, --exception INT
Count of survivors to raise Mutation Exception for system exit.
--debug Turn on DEBUG level logging output.
Expand Down
2 changes: 1 addition & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
coverage==4.5.4
ipython==7.8.0
ipython==7.16.3
Sphinx==2.2.0
typing-extensions
2 changes: 1 addition & 1 deletion mutatest/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Mutation initialization.
"""
__version__ = "3.0.2"
__version__ = "3.1.0"

__title__ = "mutatest"
__description__ = "Python mutation testing: test your tests!"
Expand Down
54 changes: 26 additions & 28 deletions mutatest/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@


class SettingsFile(NamedTuple):
"""Container for settings file in ini or cfg parsing format.
"""
"""Container for settings file in ini or cfg parsing format."""

path: Path
sections: List[str] # hierarchy of keys to search
Expand All @@ -48,8 +47,7 @@ class SettingsFile(NamedTuple):


class RunMode(NamedTuple):
"""Running mode choices. This translate the ``-m`` argument into valid ``Config`` options.
"""
"""Running mode choices. This translate the ``-m`` argument into valid ``Config`` options."""

mode: str

Expand Down Expand Up @@ -113,7 +111,7 @@ def __call__(self, parser, namespace, values, option_string=None): # type: igno


class ValidCategoryAction(argparse.Action):
"""Custom action to ensure only valid categories are used for white/black listing."""
"""Custom action to ensure only valid categories are used for only/skip listing."""

def __call__(self, parser, namespace, values, option_string=None): # type: ignore
if len(values) > 0:
Expand Down Expand Up @@ -163,14 +161,14 @@ def cli_parser() -> argparse.ArgumentParser:
epilog=cli_epilog(),
)
parser.add_argument(
"-b",
"--blacklist",
"-k",
"--skip",
type=str,
action=ValidCategoryAction,
nargs="*",
default=[],
metavar="STR",
help="Blacklisted mutation categories for trials. (default: empty list)",
help="Mutation categories to skip for trials. (default: empty list)",
)
parser.add_argument(
"-e",
Expand Down Expand Up @@ -238,14 +236,14 @@ def cli_parser() -> argparse.ArgumentParser:
help="Test command string to execute. (default: 'pytest')",
)
parser.add_argument(
"-w",
"--whitelist",
"-y",
"--only",
type=str,
action=ValidCategoryAction,
nargs="*",
default=[],
metavar="STR",
help="Whitelisted mutation categories for trials. (default: empty list)",
help="Only use these mutation categories for trials. (default: empty list)",
)
parser.add_argument(
"-x",
Expand Down Expand Up @@ -284,12 +282,12 @@ def cli_epilog() -> str:
Additional command argument information:
========================================
Black/White List:
-----------------
- Use -b and -w to set black/white lists of mutation categories. If -w categories are set then
all mutation categories except those specified are skipped during trials. If -b categories
Skip/Only Category Lists:
-------------------------
- Use -k and -y to set skip/only lists of mutation categories. If -y categories are set then
all mutation categories except those specified are skipped during trials. If -k categories
are set then all mutations categories except those specified are considered. If you set both
-w and -b then the whitelisted categories are selected first, and then the blacklisted
-k and -y then the only categories are selected first, and then the skipped
categories are removed from the candidate set.
Exclude:
Expand Down Expand Up @@ -355,7 +353,7 @@ def cli_epilog() -> str:
header = "Supported mutation sets"
description = (
"These are the current operations that are mutated as compatible sets. "
"Use the category code for whitelist/blacklist selections."
"Use the category code for only/skip selections."
)
mutation_epilog = [header, "=" * len(header), description, "\n"]
for mutop in transformers.get_compatible_operation_sets():
Expand Down Expand Up @@ -406,7 +404,7 @@ def get_parser_actions(parser: argparse.ArgumentParser) -> ParserActionMap:
# action-types:
{argparse._HelpAction: ['help'],
mutatest.cli.ValidCategoryAction: ['blacklist', 'whitelist'],
mutatest.cli.ValidCategoryAction: ['skip', 'only'],
argparse._AppendAction: ['exclude'],
argparse._StoreAction: ['mode', 'output', 'src', 'testcmds'],
mutatest.cli.PositiveIntegerAction: ['nlocations', 'rseed', 'exception'],
Expand All @@ -415,16 +413,16 @@ def get_parser_actions(parser: argparse.ArgumentParser) -> ParserActionMap:
# actions:
{'-h': '--help',
'-b': '--blacklist',
'-k': '--skip',
'-e': '--exclude',
'-m': '--mode',
'-n': '--nlocations',
'-o': '--output',
'-r': '--rseed',
'-s': '--src',
'-t': '--testcmds',
'-w': '--whitelist',
'-x': '--exception',
'-y': '--only',
'--debug': '--debug',
'--parallel': '--parallel',
'--nocov': '--nocov'}
Expand Down Expand Up @@ -641,19 +639,19 @@ def get_src_location(src_loc: Optional[Path] = None) -> Path:
)


def selected_categories(whitelist: List[str], blacklist: List[str]) -> List[str]:
"""Create the selected categories from the whitelist/blacklist set to use in filtering.
def selected_categories(only: List[str], skip: List[str]) -> List[str]:
"""Create the selected categories from the skip/only set to use in filtering.
Args:
whitelist: list of categories
blacklist: list of categories
only: list of categories
skip: list of categories
Returns:
Selection set of mutation categories
"""
all_mutations = {m.category for m in transformers.get_compatible_operation_sets()}
w_set = set(whitelist)
b_set = set(blacklist)
w_set = set(only)
b_set = set(skip)

if w_set:
return list(w_set - b_set)
Expand Down Expand Up @@ -757,8 +755,8 @@ def main(args: argparse.Namespace) -> None:
# Run the mutation trials based on the input argument
# set categories if present
filter_codes: List[str] = list()
if len(args.whitelist) > 0 or len(args.blacklist) > 0:
filter_codes = selected_categories(whitelist=args.whitelist, blacklist=args.blacklist)
if len(args.only) > 0 or len(args.skip) > 0:
filter_codes = selected_categories(only=args.only, skip=args.skip)

# Build the running configuration for the mutation trials
run_mode = RunMode(args.mode)
Expand Down
8 changes: 4 additions & 4 deletions mutatest/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,15 @@ def write_cov_file(line_data: Dict[str, List[int]], fname: str) -> None:
class MockArgs(NamedTuple):
"""Container for mocks of the cli arguments."""

blacklist: Optional[List[str]]
skip: Optional[List[str]]
exclude: Optional[List[str]]
mode: Optional[str]
nlocations: Optional[int]
output: Optional[Path]
rseed: Optional[int]
src: Optional[Path]
testcmds: Optional[List[str]]
whitelist: Optional[List[str]]
only: Optional[List[str]]
exception: Optional[int]
debug: Optional[bool]
nocov: Optional[bool]
Expand All @@ -138,15 +138,15 @@ def mock_args(tmp_path_factory, binop_file):
folder = tmp_path_factory.mktemp("output")

return MockArgs(
blacklist=[],
skip=[],
exclude=["__init__.py"],
mode="s",
nlocations=10,
output=folder / "mock_mutation_report.rst",
rseed=314,
src=binop_file,
testcmds=["pytest"],
whitelist=[],
only=[],
exception=None,
debug=False,
nocov=True,
Expand Down
Loading

0 comments on commit 41fa40e

Please sign in to comment.