Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def filename_and_mutation_id_from_pk(pk) -> Tuple[str, RelativeMutationID]:
mutant = Mutant.get(id=pk)
if mutant is None:
raise ValueError("Obtained null mutant for pk: {}".format(pk))
return mutant.line.sourcefile.filename, mutation_id_from_pk(pk)
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
else:
result[mutation_id] = mutant.status
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 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
print('')
print("---- {} ({}) ----".format(filename, len(mutants)))
print('')
if show_diffs:
with open(filename) as f:
source = f.read()
for x in mutants:
print('# mutant {}'.format(x.id))
print(get_unified_diff(x.id, dict_synonyms, update_cache=False, source=source))
else:
print(ranges([x.id for x in mutants]))
print_stuff('Timed out ⏰', select(x for x in Mutant if x.status == BAD_TIMEOUT))
print_stuff('Suspicious 🤔', select(x for x in Mutant if x.status == OK_SUSPICIOUS))
print_stuff('Survived 🙁', select(x for x in Mutant if x.status == BAD_SURVIVED))
print_stuff('Untested/skipped', select(x for x in Mutant if x.status == UNTESTED))
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
else:
result[mutation_id] = mutant.status
return result