Skip to content

Commit

Permalink
linting and type check updates
Browse files Browse the repository at this point in the history
  • Loading branch information
EvanKepner committed May 16, 2020
1 parent 182a404 commit 02f1f22
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 54 deletions.
4 changes: 2 additions & 2 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Contributing
============

Up top, thanks for considering a contribution! ``mutatest`` is in active development and
new features that align to the vision are welcome.
Up top, thanks for considering a contribution!
New features that align to the vision are welcome.
You can either open an issue to discuss the idea first, or if you have working code,
submit a pull-request.

Expand Down
8 changes: 4 additions & 4 deletions mutatest/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ class instance, and any valid measured file can be used in the filter.
covered_lines = self.coverage_data.lines(measured_file) or list()

if invert:
return {l for l in loc_idxs if l.lineno not in covered_lines}
return {l for l in loc_idxs if l.lineno in covered_lines}
return {loc for loc in loc_idxs if loc.lineno not in covered_lines}
return {loc for loc in loc_idxs if loc.lineno in covered_lines}


class CategoryCodeFilter(Filter):
Expand Down Expand Up @@ -282,6 +282,6 @@ def filter(self, loc_idxs: Set[LocIndex], invert: bool = False) -> Set[LocIndex]
return loc_idxs

if invert:
return {l for l in loc_idxs if l.op_type not in self.valid_mutations}
return {loc for loc in loc_idxs if loc.op_type not in self.valid_mutations}

return {l for l in loc_idxs if l.op_type in self.valid_mutations}
return {loc for loc in loc_idxs if loc.op_type in self.valid_mutations}
2 changes: 1 addition & 1 deletion mutatest/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ def run_mutation_trials(src_loc: Path, test_cmds: List[str], config: Config) ->
LOGGER.info("Setting random.seed to: %s", config.random_seed)
random.seed(a=config.random_seed)
sample_space = get_sample(ggrp, config.ignore_coverage)
LOGGER.info(f"Total sample space size: %s", len(sample_space))
LOGGER.info("Total sample space size: %s", len(sample_space))
mutation_sample = get_mutation_sample_locations(sample_space, config.n_locations)

# Run trials through mutations
Expand Down
4 changes: 2 additions & 2 deletions mutatest/tests/test_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
from pathlib import Path
from py_compile import PycInvalidationMode # type: ignore

import hypothesis.strategies as st
import hypothesis.strategies as st # type: ignore
import pytest

from hypothesis import example, given
from hypothesis import example, given # type: ignore

from mutatest.cache import (
check_cache_invalidation_mode,
Expand Down
4 changes: 2 additions & 2 deletions mutatest/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
from textwrap import dedent
from typing import List, NamedTuple

import hypothesis.strategies as st
import hypothesis.strategies as st # type: ignore
import pytest

from freezegun import freeze_time
from hypothesis import given
from hypothesis import given # type: ignore

import mutatest.cli

Expand Down
4 changes: 2 additions & 2 deletions mutatest/tests/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
from pathlib import Path
from subprocess import CompletedProcess

import hypothesis.strategies as st
import hypothesis.strategies as st # type: ignore
import pytest

from hypothesis import assume, given
from hypothesis import assume, given # type: ignore

from mutatest import run
from mutatest.api import Genome, GenomeGroup, GenomeGroupTarget
Expand Down
81 changes: 40 additions & 41 deletions mutatest/tests/test_transformers.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ def test_MutateAST_visit_augassign(augassign_file, augassign_expected_locs):

assert len(mast.locs) == 4

for l in mast.locs:
for loc in mast.locs:
# spot check on mutation from Add tp Div
if l.lineno == 1 and l.col_offset == 4:
assert l.op_type == test_mutation
if loc.lineno == 1 and loc.col_offset == 4:
assert loc.op_type == test_mutation

# spot check on not-mutated location still being Mult
if l.lineno == 5 and l.col_offset == 4:
assert l.op_type == "AugAssign_Mult"
if loc.lineno == 5 and loc.col_offset == 4:
assert loc.op_type == "AugAssign_Mult"


def test_MutateAST_visit_binop_37(binop_file):
Expand Down Expand Up @@ -104,14 +104,14 @@ def test_MutateAST_visit_binop_37(binop_file):
assert len(mast.locs) == 4

# locs is an unordered set, cycle through to thd target and check the mutation
for l in mast.locs:
for loc in mast.locs:
if (
l.lineno == 6
and l.col_offset == 11
and l.end_lineno == end_lineno
and l.end_col_offset == end_col_offset
loc.lineno == 6
and loc.col_offset == 11
and loc.end_lineno == end_lineno
and loc.end_col_offset == end_col_offset
):
assert l.op_type == test_mutation
assert loc.op_type == test_mutation


def test_MutateAST_visit_boolop(boolop_file, boolop_expected_loc):
Expand All @@ -134,9 +134,9 @@ def test_MutateAST_visit_boolop(boolop_file, boolop_expected_loc):

# there will only be one loc, but this still works
# basedon the col and line offset in the fixture for compare_expected_loc
for l in mast.locs:
if l.lineno == 2 and l.col_offset == 11:
assert l.op_type == test_mutation
for loc in mast.locs:
if loc.lineno == 2 and loc.col_offset == 11:
assert loc.op_type == test_mutation


@pytest.mark.parametrize( # based on the fixture definitions for compare_file and expected_locs
Expand All @@ -162,11 +162,11 @@ def test_MutateAST_visit_compare(idx, mut_op, lineno, compare_file, compare_expe

# check that the lineno marked for mutation is changed, otherwise original ops should
# still be present without modification
for l in mast.locs:
if l.lineno == lineno and l.col_offset == 11:
assert l.op_type == mut_op
for loc in mast.locs:
if loc.lineno == lineno and loc.col_offset == 11:
assert loc.op_type == mut_op
else:
assert l.op_type in {ast.Eq, ast.Is, ast.In} # based on compare_file fixture
assert loc.op_type in {ast.Eq, ast.Is, ast.In} # based on compare_file fixture


def test_MutateAST_visit_if(if_file, if_expected_locs):
Expand All @@ -184,18 +184,17 @@ def test_MutateAST_visit_if(if_file, if_expected_locs):
mast.visit(mutated_tree)

# named constants will also be picked up, filter just to if_ operations
if_locs = [l for l in mast.locs if l.ast_class == "If"]
if_locs = [loc for loc in mast.locs if loc.ast_class == "If"]
assert len(if_locs) == 4

for l in if_locs:
for loc in if_locs:
# spot check on mutation from True to False
if l.lineno == 2 and l.col_offset == 4:
print(l)
assert l.op_type == test_mutation
if loc.lineno == 2 and loc.col_offset == 4:
assert loc.op_type == test_mutation

# spot check on not-mutated location still being None
if l.lineno == 13 and l.col_offset == 4:
assert l.op_type == "If_False"
if loc.lineno == 13 and loc.col_offset == 4:
assert loc.op_type == "If_False"


INDEX_SETS = [
Expand Down Expand Up @@ -241,14 +240,14 @@ def test_MutateAST_visit_index_neg(

assert len(mast.locs) == 4

for l in mast.locs:
for loc in mast.locs:
# spot check on mutation from Index_NumNeg to Index_NumPos
if l.lineno == lineno and l.col_offset == col_offset:
assert l.op_type == test_mutation
if loc.lineno == lineno and loc.col_offset == col_offset:
assert loc.op_type == test_mutation

# spot check on not-mutated location still being None
if l.lineno == 4 and l.col_offset == 23:
assert l.op_type == "Index_NumPos"
if loc.lineno == 4 and loc.col_offset == 23:
assert loc.op_type == "Index_NumPos"


def test_MutateAST_visit_nameconst(nameconst_file, nameconst_expected_locs):
Expand All @@ -265,17 +264,17 @@ def test_MutateAST_visit_nameconst(nameconst_file, nameconst_expected_locs):
mast.visit(mutated_tree)

# if statement is included with this file that will be picked up
nc_locs = [l for l in mast.locs if l.ast_class == "NameConstant"]
nc_locs = [loc for loc in mast.locs if loc.ast_class == "NameConstant"]
assert len(nc_locs) == 4

for l in nc_locs:
for loc in nc_locs:
# spot check on mutation from True to False
if l.lineno == 1 and l.col_offset == 14:
assert l.op_type == test_mutation
if loc.lineno == 1 and loc.col_offset == 14:
assert loc.op_type == test_mutation

# spot check on not-mutated location still being None
if l.lineno == 7 and l.col_offset == 22:
assert l.op_type is None
if loc.lineno == 7 and loc.col_offset == 22:
assert loc.op_type is None


def test_MutateAST_visit_subscript(slice_file, slice_expected_locs):
Expand All @@ -292,11 +291,11 @@ def test_MutateAST_visit_subscript(slice_file, slice_expected_locs):
mast.visit(mutated_tree)
assert len(mast.locs) == len(slice_expected_locs)

for l in mast.locs:
for loc in mast.locs:

if l.lineno == 5 and l.col_offset == 15:
assert l.op_type == test_mutation
if loc.lineno == 5 and loc.col_offset == 15:
assert loc.op_type == test_mutation

# test one unmodified location
if l.lineno == 4 and l.col_offset == 14:
assert l.op_type == "Slice_UnboundUpper"
if loc.lineno == 4 and loc.col_offset == 14:
assert loc.op_type == "Slice_UnboundUpper"

0 comments on commit 02f1f22

Please sign in to comment.