Exemplo n.º 1
0
def binop_expected_locs():
    """Expected target locations for the binop_file fixture."""
    return {
        LocIndex(ast_class="BinOp", lineno=6, col_offset=11, op_type=ast.Add),
        LocIndex(ast_class="BinOp", lineno=6, col_offset=18, op_type=ast.Sub),
        LocIndex(ast_class="BinOp", lineno=10, col_offset=11, op_type=ast.Add),
        LocIndex(ast_class="BinOp", lineno=15, col_offset=11, op_type=ast.Div),
    }
Exemplo n.º 2
0
def if_expected_locs():
    """Exepected locations in the if_statement."""
    return [
        LocIndex(ast_class="If",
                 lineno=2,
                 col_offset=4,
                 op_type="If_Statement"),
        LocIndex(ast_class="If",
                 lineno=4,
                 col_offset=9,
                 op_type="If_Statement"),
        LocIndex(ast_class="If", lineno=10, col_offset=4, op_type="If_True"),
        LocIndex(ast_class="If", lineno=13, col_offset=4, op_type="If_False"),
    ]
Exemplo n.º 3
0
def test_filter_wl_bl_categories(monkeypatch):
    """Filtering based on op return expectations."""

    def mock_get_comp_ops(*args, **kwargs):
        return [MockOp("aa", {"a1", "a2"}), MockOp("bb", {"b1", "b2"}), MockOp("cc", {"c1", "c2"})]

    monkeypatch.setattr(mutatest.controller, "get_compatible_operation_sets", mock_get_comp_ops)

    sample = [
        ("a1", LocIndex(ast_class="a", lineno=1, col_offset=2, op_type="a1")),
        ("a2", LocIndex(ast_class="a", lineno=1, col_offset=2, op_type="a2")),
        ("b1", LocIndex(ast_class="a", lineno=1, col_offset=2, op_type="b1")),
        ("c1", LocIndex(ast_class="a", lineno=1, col_offset=2, op_type="c1")),
    ]

    result = filter_wl_bl_categories(sample_space=sample, wlbl_categories={"aa"})

    assert len(result) == 2
    for i, _ in result:
        assert i.startswith("a")
Exemplo n.º 4
0
def nameconst_expected_locs():
    """The nameconst expected location based on the fixture"""
    return [
        LocIndex(ast_class="NameConstant",
                 lineno=1,
                 col_offset=14,
                 op_type=True),
        LocIndex(ast_class="NameConstant",
                 lineno=4,
                 col_offset=25,
                 op_type=False),
        LocIndex(ast_class="NameConstant",
                 lineno=6,
                 col_offset=22,
                 op_type=False),
        LocIndex(ast_class="NameConstant",
                 lineno=7,
                 col_offset=22,
                 op_type=None),
    ]
Exemplo n.º 5
0
def index_expected_locs():
    """The index expected location based on the fixture"""
    return [
        LocIndex(ast_class="Index_NumNeg",
                 lineno=2,
                 col_offset=20,
                 op_type="Index_NumNeg"),
        LocIndex(ast_class="Index_NumZero",
                 lineno=3,
                 col_offset=20,
                 op_type="Index_NumZero"),
        LocIndex(ast_class="Index_NumPos",
                 lineno=4,
                 col_offset=20,
                 op_type="Index_NumPos"),
        LocIndex(ast_class="Index_NumPos",
                 lineno=4,
                 col_offset=23,
                 op_type="Index_NumPos"),
    ]
Exemplo n.º 6
0
def augassign_expected_locs():
    """The AugAssign expected location based on the fixture"""
    return [
        LocIndex(ast_class="AugAssign",
                 lineno=2,
                 col_offset=4,
                 op_type="AugAssign_Add"),
        LocIndex(ast_class="AugAssign",
                 lineno=3,
                 col_offset=4,
                 op_type="AugAssign_Sub"),
        LocIndex(ast_class="AugAssign",
                 lineno=4,
                 col_offset=4,
                 op_type="AugAssign_Div"),
        LocIndex(ast_class="AugAssign",
                 lineno=5,
                 col_offset=4,
                 op_type="AugAssign_Mult"),
    ]
Exemplo n.º 7
0
def mock_precov_sample():
    """Mock pre-coverage sample that aligns to mock_coverage_file fixture."""
    return [
        (
            "/simple_isnot/isnot/run.py",
            LocIndex(ast_class="a", lineno=1, col_offset=1, op_type="o"),
        ),
        (
            "/simple_isnot/isnot/run.py",
            LocIndex(ast_class="a", lineno=2, col_offset=1, op_type="o"),
        ),
        (
            "/simple_isnot/isnot/run.py",
            LocIndex(ast_class="a", lineno=3, col_offset=1, op_type="o"),
        ),
        (
            "/simple_isnot/isnot/run.py",
            LocIndex(ast_class="a", lineno=4, col_offset=1, op_type="o"),
        ),
        (
            "/simple_isnot/isnot/run.py",
            LocIndex(ast_class="a", lineno=5, col_offset=1, op_type="o"),
        ),
        (
            "/simple_isnot/isnot/run.py",
            LocIndex(ast_class="a", lineno=5, col_offset=2, op_type="o"),
        ),
    ]
Exemplo n.º 8
0
def test_get_sample_space(size):
    """Sample space should flatten out a dictionary of multiple entries to tuple pairs."""
    mock_LocIdx = LocIndex(ast_class="BinOp", lineno=1, col_offset=2, op_type=ast.Add)

    mock_src_file = "source.py"
    mock_src_targets = {mock_src_file: [mock_LocIdx] * size}

    results = get_sample_space(mock_src_targets)

    assert len(results) == size
    for s, l in results:
        assert s == mock_src_file
        assert l == mock_LocIdx
Exemplo n.º 9
0
def test_get_mutation_sample_locations(popsize, nlocs, nexp):
    """Test sample size draws for the mutation sample."""
    mock_LocIdx = LocIndex(ast_class="BinOp", lineno=1, col_offset=2, op_type=ast.Add)

    mock_src_file = "source.py"
    mock_sample = [(mock_src_file, mock_LocIdx)] * popsize

    # if n is unspecified then the full sample is used and result_n is the sample size
    result_sample = get_mutation_sample_locations(sample_space=mock_sample, n_locations=nlocs)
    assert len(result_sample) == nexp

    # special case when nlocs is None, result_sample is mock_sample
    if not nlocs:
        assert result_sample == mock_sample
Exemplo n.º 10
0
def slice_expected_locs():
    """The slice expected locations based on the fixture."""
    return [
        LocIndex(ast_class="Slice_Swap",
                 lineno=2,
                 col_offset=13,
                 op_type="Slice_UnboundLower"),
        LocIndex(ast_class="Slice_RangeChange",
                 lineno=3,
                 col_offset=13,
                 op_type="Slice_UPosToZero"),
        LocIndex(ast_class="Slice_Swap",
                 lineno=4,
                 col_offset=14,
                 op_type="Slice_UnboundUpper"),
        LocIndex(ast_class="Slice_RangeChange",
                 lineno=5,
                 col_offset=15,
                 op_type="Slice_UNegToZero"),
        LocIndex(ast_class="Slice_Swap",
                 lineno=6,
                 col_offset=14,
                 op_type="Slice_UnboundUpper"),
    ]
Exemplo n.º 11
0
def mock_Mutant():
    """Mock mutant definition."""
    return Mutant(
        mutant_code=None,
        src_file=Path("src.py"),
        cfile=Path("__pycache__") / "src.pyc",
        loader=None,
        mode=1,
        source_stats={
            "mtime": 1,
            "size": 1
        },
        src_idx=LocIndex(ast_class="BinOp",
                         lineno=1,
                         col_offset=2,
                         op_type=ast.Add),
        mutation=ast.Mult,
    )
Exemplo n.º 12
0
def compare_expected_loc():
    """The compare expected location based on the fixture"""
    return LocIndex(ast_class="Compare",
                    lineno=2,
                    col_offset=11,
                    op_type=ast.Eq)
Exemplo n.º 13
0
def boolop_expected_loc():
    """Expected location index of the boolop fixture"""
    return LocIndex(ast_class="BoolOp",
                    lineno=2,
                    col_offset=11,
                    op_type=ast.And)