Example #1
0
def test_base_mutant_from_multiple_any():
    func = mutants.BaseMutant.from_multiple_any

    # test empty result
    assert func([]) == []
    assert func(None) == []

    # test Mutant
    raw_single = {("col1", 0): 1}
    conv_single = mutants.ValueMutant(column="col1", row=0, value=1)
    assert func(conv_single) == [conv_single]

    # test dict single single
    assert func(raw_single) == [conv_single]

    # test dict single multi
    raw_multi = {("col1", 0): 1, ("col2", 0): 0}

    conv_multi = mutants.MutantCollection([
        mutants.ValueMutant(column="col1", row=0, value=1),
        mutants.ValueMutant(column="col2", row=0, value=0)
    ])

    assert func(raw_multi) == [conv_multi]

    # test list mixed
    raw = [raw_multi, conv_single]
    assert func(raw) == [conv_multi, conv_single]

    # test incorrect type
    with pytest.raises(ValueError):
        func(tuple([1, 2, 3]))
Example #2
0
def test_base_mutant_from_dict():
    # test dict single
    raw = {("col1", 0): 1}
    conv = mutants.ValueMutant(column="col1", row=0, value=1)
    assert mutants.BaseMutant.from_dict(raw) == conv

    # test dict multi
    raw = {("col1", 0): 1, ("col2", 0): 0}

    conv = mutants.MutantCollection([
        mutants.ValueMutant(column="col1", row=0, value=1),
        mutants.ValueMutant(column="col2", row=0, value=0)
    ])

    assert mutants.BaseMutant.from_dict(raw) == conv

    # test wrong type
    with pytest.raises(ValueError):
        mutants.BaseMutant.from_dict(("col1", 2))
Example #3
0
def test_mutant_assertions():
    """Test invalid type changes due to mutations.

    """

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

    mutant = mutants.ValueMutant("foo", 1, 2)
    with pytest.raises(TypeError):
        mutant.mutate(df)
Example #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
Example #5
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