Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def update_mutant_status(file_to_mutate, mutation_id, status, tests_hash):
sourcefile = SourceFile.get(filename=file_to_mutate)
line = Line.get(sourcefile=sourcefile, line=mutation_id.line, line_number=mutation_id.line_number)
mutant = Mutant.get(line=line, index=mutation_id.index)
mutant.status = status
mutant.tested_against_hash = tests_hash
def cached_mutation_status(filename, mutation_id, hash_of_tests):
sourcefile = SourceFile.get(filename=filename)
assert sourcefile
line = Line.get(sourcefile=sourcefile, line=mutation_id.line, line_number=mutation_id.line_number)
assert line
mutant = Mutant.get(line=line, index=mutation_id.index)
if mutant is None:
mutant = get_or_create(Mutant, line=line, index=mutation_id.index, defaults=dict(status=UNTESTED))
if mutant.status == OK_KILLED:
# We assume that if a mutant was killed, a change to the test
# suite will mean it's still killed
return OK_KILLED
if mutant.tested_against_hash != hash_of_tests or \
mutant.tested_against_hash == NO_TESTS_FOUND or \
hash_of_tests == NO_TESTS_FOUND:
return UNTESTED
return mutant.status
def get_cached_mutation_statuses(filename, mutations, hash_of_tests):
sourcefile = SourceFile.get(filename=filename)
assert sourcefile
line_obj_by_line = {}
result = {}
for mutation_id in mutations:
if mutation_id.line not in line_obj_by_line:
line_obj_by_line[mutation_id.line] = Line.get(sourcefile=sourcefile, line=mutation_id.line, line_number=mutation_id.line_number)
line = line_obj_by_line[mutation_id.line]
assert line
mutant = Mutant.get(line=line, index=mutation_id.index)
if mutant is None:
mutant = get_or_create(Mutant, line=line, index=mutation_id.index, defaults=dict(status=UNTESTED))
result[mutation_id] = mutant.status
if mutant.status == OK_KILLED:
# We assume that if a mutant was killed, a change to the test
# suite will mean it's still killed
result[mutation_id] = mutant.status
else:
if mutant.tested_against_hash != hash_of_tests or \
mutant.tested_against_hash == NO_TESTS_FOUND or \
hash_of_tests == NO_TESTS_FOUND:
result[mutation_id] = UNTESTED
def register_mutants(mutations_by_file):
for filename, mutation_ids in mutations_by_file.items():
hash = hash_of(filename)
sourcefile = get_or_create(SourceFile, filename=filename)
if hash == sourcefile.hash:
continue
for mutation_id in mutation_ids:
line = Line.get(sourcefile=sourcefile, line=mutation_id.line, line_number=mutation_id.line_number)
if line is None:
raise ValueError("Obtained null line for mutation_id: {}".format(mutation_id))
get_or_create(Mutant, line=line, index=mutation_id.index, defaults=dict(status=UNTESTED))
sourcefile.hash = hash