Ejemplo n.º 1
0
def run_mutation_tests_for_file(config: Config, progress: Progress, file_to_mutate: str, mutations: List[MutationID]) -> None:
    """
    :type config: Config
    :type progress: Progress
    :type file_to_mutate: str
    :type mutations: list[MutationID]
    """
    def feedback(line):
        if not config.swallow_output:
            print(line)
        progress.print(total=config.total)

    for mutation_id in mutations:
        status = run_mutation(config, file_to_mutate, mutation_id, callback=feedback)
        update_mutant_status(file_to_mutate, mutation_id, status, config.hash_of_tests)

        if status == BAD_SURVIVED:
            progress.surviving_mutants += 1
        elif status == BAD_TIMEOUT:
            progress.surviving_mutants_timeout += 1
        elif status == OK_KILLED:
            progress.killed_mutants += 1
        elif status == OK_SUSPICIOUS:
            progress.suspicious_mutants += 1
        else:
            raise ValueError('Unknown status returned from run_mutation: {}'.format(status))

        progress.progress += 1
        progress.print(total=config.total)
Ejemplo n.º 2
0
def run_mutation_tests_for_file(config, file_to_mutate, mutations):
    for mutation_id in mutations:
        status = run_mutation(config, file_to_mutate, mutation_id)
        update_mutant_status(file_to_mutate, mutation_id, status,
                             config.hash_of_tests)
        config.progress += 1
        config.print_progress()
Ejemplo n.º 3
0
def run_mutation_tests_for_file(config, file_to_mutate, mutations):
    """
    :type config: Config
    :type file_to_mutate: str
    :type mutations: list[MutationID]
    """
    for mutation_id in mutations:
        status = run_mutation(config, file_to_mutate, mutation_id)
        update_mutant_status(file_to_mutate, mutation_id, status,
                             config.hash_of_tests)
        config.progress += 1
        config.print_progress()
Ejemplo n.º 4
0
def run_mutation_tests(config, progress, mutations_by_file):
    """
    :type config: Config
    :type progress: Progress
    :type mutations_by_file: dict[str, list[RelativeMutationID]]
    """
    from mutmut.cache import update_mutant_status

    # Need to explicitly use the spawn method for python < 3.8 on macOS
    mp_ctx = multiprocessing.get_context('spawn')

    mutants_queue = mp_ctx.Queue(maxsize=100)
    add_to_active_queues(mutants_queue)
    queue_mutants_thread = Thread(
        target=queue_mutants,
        name='queue_mutants',
        daemon=True,
        kwargs=dict(
            progress=progress,
            config=config,
            mutants_queue=mutants_queue,
            mutations_by_file=mutations_by_file,
        )
    )
    queue_mutants_thread.start()

    results_queue = mp_ctx.Queue(maxsize=100)
    add_to_active_queues(results_queue)

    def create_worker():
        t = mp_ctx.Process(
            target=check_mutants,
            name='check_mutants',
            daemon=True,
            kwargs=dict(
                mutants_queue=mutants_queue,
                results_queue=results_queue,
                cycle_process_after=100,
            )
        )
        t.start()
        return t

    t = create_worker()

    while t.is_alive():
        command, status, filename, mutation_id = results_queue.get()
        if command == 'end':
            t.join()
            break

        elif command == 'cycle':
            t = create_worker()

        elif command == 'progress':
            if not config.swallow_output:
                print(status, end='', flush=True)
            else:
                progress.print()

        else:
            assert command == 'status'

            progress.register(status)

            update_mutant_status(file_to_mutate=filename, mutation_id=mutation_id, status=status, tests_hash=config.hash_of_tests)

            progress.print()