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_line_numbers(filename):
hash = hash_of(filename)
sourcefile = get_or_create(SourceFile, filename=filename)
if hash == sourcefile.hash:
return
cached_line_objects = list(sourcefile.lines.order_by(Line.line_number))
cached_lines = [x.line for x in cached_line_objects]
with open(filename) as f:
existing_lines = [x.strip('\n') for x in f.readlines()]
if not cached_lines:
for i, line in enumerate(existing_lines):
Line(sourcefile=sourcefile, line=line, line_number=i)
return
for command, a, a_index, b, b_index in sequence_ops(cached_lines, existing_lines):
if command == 'equal':
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
NO_TESTS_FOUND = 'NO TESTS FOUND'
class MiscData(db.Entity):
key = PrimaryKey(str, auto=True)
value = Optional(str, autostrip=False)
class SourceFile(db.Entity):
filename = Required(str, autostrip=False)
hash = Optional(str)
lines = Set('Line')
class Line(db.Entity):
sourcefile = Required(SourceFile)
line = Optional(str, autostrip=False)
line_number = Required(int)
mutants = Set('Mutant')
class Mutant(db.Entity):
line = Required(Line)
index = Required(int)
tested_against_hash = Optional(str, autostrip=False)
status = Required(str, autostrip=False) # really an enum of mutant_statuses
def init_db(f):
@wraps(f)
def wrapper(*args, **kwargs):
if db.provider is None: