Ejemplo n.º 1
0
def test_base_mutant():
    """Test BaseMutant functionality.

    """

    # check duplicated mutations
    m1 = mutants.Mutation("foo", 1, "bar")
    m2 = mutants.Mutation("foo", 1, "far")
    m3 = mutants.Mutation("bar", 0, "foo")
    m4 = mutants.Mutation("foo", 0, "bar")

    with pytest.raises(ValueError):
        mutants.BaseMutant._check_duplicated_mutations([m1, m2])

    mutants.BaseMutant._check_duplicated_mutations([m1, m3])

    # check invalid mutations
    df = plainframe.PlainFrame.from_dict({"foo:str": ["bar"]})

    with pytest.raises(ValueError):
        mutants.BaseMutant._check_valid_mutations([m1], df)  # check row

    with pytest.raises(ValueError):
        mutants.BaseMutant._check_valid_mutations([m3], df)  # check column

    mutants.BaseMutant._check_valid_mutations([m4], df)
Ejemplo n.º 2
0
def test_mutation():
    """Test correct mutant instantiation.

    """

    mutation = mutants.Mutation("foo", 1, "bar")

    assert mutation.column == "foo"
    assert mutation.row == 1
    assert mutation.value == "bar"
    assert mutation.key == ("foo", 1)
Ejemplo n.º 3
0
def test_collection_mutant():
    """Test MutantCollection functionality.

    """

    # test combination
    df = plainframe.PlainFrame.from_dict({"foo:str": ["foo", "foo"]})
    value_mutant = mutants.ValueMutant("foo", 0, "bar")
    func = lambda _: [mutants.Mutation("foo", 1, "bar")]
    func_mutant = mutants.FunctionMutant(func)

    result = [
        mutants.Mutation("foo", 0, "bar"),
        mutants.Mutation("foo", 1, "bar")
    ]

    df_result = plainframe.PlainFrame.from_dict({"foo:str": ["bar", "bar"]})

    mutant_collection = mutants.MutantCollection([value_mutant, func_mutant])
    assert mutant_collection.generate_mutations(df) == result
    assert mutant_collection.mutate(df) == df_result
Ejemplo n.º 4
0
def test_value_mutant():
    """Test ValueMutant functionality.

    """

    df = plainframe.PlainFrame.from_dict({"foo:str": ["bar"]})
    df_test = plainframe.PlainFrame.from_dict({"foo:str": ["foo"]})
    mutant = mutants.ValueMutant("foo", 0, "foo")
    mutation = mutants.Mutation("foo", 0, "foo")

    assert mutant.generate_mutations(df) == [mutation]
    assert mutant.mutate(df) == df_test
Ejemplo n.º 5
0
def test_function_mutant():
    """Test FunctionMutant functionality.

    """

    df = plainframe.PlainFrame.from_dict({"foo:str": ["bar"]})
    df_test = plainframe.PlainFrame.from_dict({"foo:str": ["foo"]})
    mutation = mutants.Mutation("foo", 0, "foo")

    def custom_func(df):
        return [mutation]

    mutant = mutants.FunctionMutant(custom_func)

    assert mutant.generate_mutations(df) == [mutation]
    assert mutant.mutate(df) == df_test