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 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)
def run_mutation(context: Context, callback) -> str: """ :return: (computed or cached) status of the tested mutant, one of mutant_statuses """ from mutmut.cache import cached_mutation_status cached_status = cached_mutation_status(context.filename, context.mutation_id, context.config.hash_of_tests) if cached_status != UNTESTED and context.config.total != 1: return cached_status config = context.config if hasattr(mutmut_config, 'pre_mutation'): context.current_line_index = context.mutation_id.line_number try: mutmut_config.pre_mutation(context=context) except SkipException: return SKIPPED if context.skip: return SKIPPED if config.pre_mutation: result = subprocess.check_output(config.pre_mutation, shell=True).decode().strip() if result and not config.swallow_output: callback(result) try: mutate_file(backup=True, context=context) start = time() try: survived = tests_pass(config=config, callback=callback) except TimeoutError: return BAD_TIMEOUT time_elapsed = time() - start if not survived and time_elapsed > config.test_time_base + ( config.baseline_time_elapsed * config.test_time_multipler): return OK_SUSPICIOUS if survived: return BAD_SURVIVED else: return OK_KILLED except SkipException: return SKIPPED finally: move(context.filename + '.bak', context.filename) if config.post_mutation: result = subprocess.check_output(config.post_mutation, shell=True).decode().strip() if result and not config.swallow_output: callback(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 try: number_of_mutations_performed = mutate_file( backup=True, context=context ) assert number_of_mutations_performed start = datetime.now() try: survived = tests_pass(config) except TimeoutError: context.config.surviving_mutants_timeout += 1 return BAD_TIMEOUT time_elapsed = datetime.now() - start if time_elapsed.total_seconds() > config.baseline_time_elapsed * 2: 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)
def run_mutation(config: Config, filename: str, mutation_id: MutationID, callback) -> str: """ :return: (computed or cached) status of the tested mutant, one of mutant_statuses """ context = Context( mutation_id=mutation_id, filename=filename, dict_synonyms=config.dict_synonyms, config=config, ) cached_status = cached_mutation_status(filename, mutation_id, config.hash_of_tests) if cached_status != UNTESTED: return cached_status if config.pre_mutation: result = subprocess.check_output(config.pre_mutation, shell=True).decode().strip() if result and not config.swallow_output: print(result) try: mutate_file(backup=True, context=context) start = time() try: survived = tests_pass(config=config, callback=callback) except TimeoutError: return BAD_TIMEOUT time_elapsed = time() - start if not survived and time_elapsed > config.test_time_base + ( config.baseline_time_elapsed * config.test_time_multipler): return OK_SUSPICIOUS if survived: return BAD_SURVIVED else: 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 and not config.swallow_output: print(result)