mutmut/__main__.py
def run_mutation(config, filename, mutation_id):
    """
    :type config: Config
    :type filename: str
    :type mutation_id: MutationID
    :return: (computed or cached) status of the tested mutant
    :rtype: str
    """
    context = Context(
        mutation_id=mutation_id,
        filename=filename,
        exclude=config.exclude_callback,
        dict_synonyms=config.dict_synonyms,
        config=config,
    )

    cached_status = cached_mutation_status(filename, mutation_id, config.hash_of_tests)
    if cached_status == BAD_SURVIVED:
        config.surviving_mutants += 1
    elif cached_status == BAD_TIMEOUT:
        config.surviving_mutants_timeout += 1
    elif cached_status == OK_KILLED:
        config.killed_mutants += 1
    elif cached_status == OK_SUSPICIOUS:
        config.suspicious_mutants += 1
    else:
        assert cached_status == UNTESTED, cached_status

    config.print_progress()

    if cached_status != UNTESTED:
        return cached_status

    if config.pre_mutation:
        result = subprocess.check_output(config.pre_mutation, shell=True).decode().strip()
        if result:
            print(result)

    try:
        number_of_mutations_performed = mutate_file(
            backup=True,
            context=context
        )
        assert number_of_mutations_performed
        start = time()
        try:
            survived = tests_pass(config)
        except TimeoutError:
            context.config.surviving_mutants_timeout += 1
            return BAD_TIMEOUT

        time_elapsed = time() - start
        if time_elapsed > config.test_time_base + (config.baseline_time_elapsed * config.test_time_multipler):
            config.suspicious_mutants += 1
            return OK_SUSPICIOUS

        if survived:
            context.config.surviving_mutants += 1
            return BAD_SURVIVED
        else:
            context.config.killed_mutants += 1
            return OK_KILLED
    finally:
        move(filename + '.bak', filename)

        if config.post_mutation:
            result = subprocess.check_output(config.post_mutation, shell=True).decode().strip()
            if result:
                print(result)
def run_mutation(config, filename, mutation_id):
    """
    :type config: Config
    :type filename: str
    :type mutation_id: MutationID
    :return: (computed or cached) status of the tested mutant
    :rtype: str
    """
    context = Context(
        mutation_id=mutation_id,
        filename=filename,
        exclude=config.exclude_callback,
        dict_synonyms=config.dict_synonyms,
        config=config,
    )

    cached_status = cached_mutation_status(filename, mutation_id, config.hash_of_tests)
    if cached_status == BAD_SURVIVED:
        config.surviving_mutants += 1
    elif cached_status == BAD_TIMEOUT:
        config.surviving_mutants_timeout += 1
    elif cached_status == OK_KILLED:
        config.killed_mutants += 1
    elif cached_status == OK_SUSPICIOUS:
        config.suspicious_mutants += 1
    else:
        assert cached_status == UNTESTED, cached_status

    config.print_progress()

    if cached_status != UNTESTED:
        return cached_status

    if config.pre_mutation:
        result = subprocess.check_output(config.pre_mutation, shell=True).decode().strip()
        if result:
            print(result)

    try:
        number_of_mutations_performed = mutate_file(
            backup=True,
            context=context
        )
        assert number_of_mutations_performed
        start = time()
        try:
            survived = tests_pass(config)
        except TimeoutError:
            context.config.surviving_mutants_timeout += 1
            return BAD_TIMEOUT

        time_elapsed = time() - start
        if time_elapsed > config.test_time_base + (config.baseline_time_elapsed * config.test_time_multipler):
            config.suspicious_mutants += 1
            return OK_SUSPICIOUS

        if survived:
            context.config.surviving_mutants += 1
            return BAD_SURVIVED
        else:
            context.config.killed_mutants += 1
            return OK_KILLED
    finally:
        move(filename + '.bak', filename)

        if config.post_mutation:
            result = subprocess.check_output(config.post_mutation, shell=True).decode().strip()
            if result:
                print(result)
def run_mutation ( config , filename , mutation_id ) : context = Context ( mutation_id = mutation_id , filename = filename , exclude = config . exclude_callback , dict_synonyms = config . dict_synonyms , config = config , ) cached_status = cached_mutation_status ( filename , mutation_id , config . hash_of_tests ) if cached_status == BAD_SURVIVED : config . surviving_mutants += 1 elif cached_status == BAD_TIMEOUT : config . surviving_mutants_timeout += 1 elif cached_status == OK_KILLED : config . killed_mutants += 1 elif cached_status == OK_SUSPICIOUS : config . suspicious_mutants += 1 else : assert cached_status == UNTESTED , cached_status config . print_progress ( ) if cached_status != UNTESTED : return cached_status if config . pre_mutation : result = subprocess . check_output ( config . pre_mutation , shell = True ) . decode ( ) . strip ( ) if result : print ( result ) try : number_of_mutations_performed = mutate_file ( backup = True , context = context ) assert number_of_mutations_performed start = time ( ) try : survived = tests_pass ( config ) except TimeoutError : context . config . surviving_mutants_timeout += 1 return BAD_TIMEOUT time_elapsed = time ( ) - start if time_elapsed > config . test_time_base + ( config . baseline_time_elapsed * config . test_time_multipler ) : config . suspicious_mutants += 1 return OK_SUSPICIOUS if survived : context . config . surviving_mutants += 1 return BAD_SURVIVED else : context . config . killed_mutants += 1 return OK_KILLED finally : move ( filename + '.bak' , filename ) if config . post_mutation : result = subprocess . check_output ( config . post_mutation , shell = True ) . decode ( ) . strip ( ) if result : print ( result )
:type config: Config
    :type filename: str
    :type mutation_id: MutationID
    :return: (computed or cached) status of the tested mutant
    :rtype: str
: type config : Config : type filename : str : type mutation_id : MutationID : return : ( computed or cached ) status of the tested mutant : rtype : str