Ejemplo n.º 1
0
def test_multiple_mutations(original, expected):
    mutations = list_mutations(Context(source=original))
    assert len(mutations) == 3
    assert mutate(Context(source=original,
                          mutation_id=mutations[0])) == (expected[0], 1)
    assert mutate(Context(source=original,
                          mutation_id=mutations[1])) == (expected[1], 1)
Ejemplo n.º 2
0
def test_mutate_both():
    source = 'a = b + c'
    mutations = list_mutations(Context(source=source))
    assert len(mutations) == 2
    assert mutate(Context(source=source,
                          mutation_id=mutations[0])) == ('a = b - c', 1)
    assert mutate(Context(source=source,
                          mutation_id=mutations[1])) == ('a = None', 1)
Ejemplo n.º 3
0
def add_mutations_by_file(mutations_by_file, filename, dict_synonyms, config):
    """
    :type mutations_by_file: dict[str, list[MutationID]]
    :type filename: str
    :type exclude: Callable[[Context], bool]
    :type dict_synonyms: list[str]
    """
    with open(filename) as f:
        source = f.read()
    context = Context(
        source=source,
        filename=filename,
        config=config,
        dict_synonyms=dict_synonyms,
    )

    try:
        mutations_by_file[filename] = list_mutations(context)
        register_mutants(mutations_by_file)
    except Exception as e:
        raise RuntimeError('Failed while creating mutations for {}, for line "{}"'.format(context.filename, context.current_source_line)) from e