Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_function():
source = "def capitalize(s):\n return s[0].upper() + s[1:] if s else s\n"
assert mutate(Context(source=source, mutation_id=RelativeMutationID(source.split('\n')[1], 0, line_number=1))) == ("def capitalize(s):\n return s[1].upper() + s[1:] if s else s\n", 1)
assert mutate(Context(source=source, mutation_id=RelativeMutationID(source.split('\n')[1], 1, line_number=1))) == ("def capitalize(s):\n return s[0].upper() - s[1:] if s else s\n", 1)
assert mutate(Context(source=source, mutation_id=RelativeMutationID(source.split('\n')[1], 2, line_number=1))) == ("def capitalize(s):\n return s[0].upper() + s[2:] if s else s\n", 1)
def test_function():
source = "def capitalize(s):\n return s[0].upper() + s[1:] if s else s\n"
assert mutate(Context(source=source, mutation_id=RelativeMutationID(source.split('\n')[1], 0, line_number=1))) == ("def capitalize(s):\n return s[1].upper() + s[1:] if s else s\n", 1)
assert mutate(Context(source=source, mutation_id=RelativeMutationID(source.split('\n')[1], 1, line_number=1))) == ("def capitalize(s):\n return s[0].upper() - s[1:] if s else s\n", 1)
assert mutate(Context(source=source, mutation_id=RelativeMutationID(source.split('\n')[1], 2, line_number=1))) == ("def capitalize(s):\n return s[0].upper() + s[2:] if s else s\n", 1)
def test_function_with_annotation():
source = "def capitalize(s : str):\n return s[0].upper() + s[1:] if s else s\n"
assert mutate(Context(source=source, mutation_id=RelativeMutationID(source.split('\n')[1], 0, line_number=1))) == ("def capitalize(s : str):\n return s[1].upper() + s[1:] if s else s\n", 1)
def test_bug_github_issue_162():
source = """
primes: List[int] = []
foo = 'bar'
"""
assert mutate(Context(source=source, mutation_id=RelativeMutationID("foo = 'bar'", 0, 2))) == (source.replace("'bar'", "'XXbarXX'"), 1)
def test_mutate_dict():
source = "dict(a=b, c=d)"
assert mutate(Context(source=source, mutation_id=RelativeMutationID(source, 1, line_number=0))) == ("dict(a=b, cXX=d)", 1)
def test_perform_one_indexed_mutation():
assert mutate(Context(source='1+1', mutation_id=RelativeMutationID(line='1+1', index=0, line_number=0))) == ('2+1', 1)
assert mutate(Context(source='1+1', mutation_id=RelativeMutationID('1+1', 1, line_number=0))) == ('1-1', 1)
assert mutate(Context(source='1+1', mutation_id=RelativeMutationID('1+1', 2, line_number=0))) == ('1+2', 1)
def test_performed_mutation_ids():
source = "dict(a=b, c=d)"
context = Context(source=source)
mutate(context)
# we found two mutation points: mutate "a" and "c"
assert context.performed_mutation_ids == [RelativeMutationID(source, 0, 0), RelativeMutationID(source, 1, 0)]
def test_perform_one_indexed_mutation():
assert mutate(Context(source='1+1', mutation_id=RelativeMutationID(line='1+1', index=0, line_number=0))) == ('2+1', 1)
assert mutate(Context(source='1+1', mutation_id=RelativeMutationID('1+1', 1, line_number=0))) == ('1-1', 1)
assert mutate(Context(source='1+1', mutation_id=RelativeMutationID('1+1', 2, line_number=0))) == ('1+2', 1)
def mutation_id_from_pk(pk):
mutant = Mutant.get(id=pk)
return RelativeMutationID(line=mutant.line.line, index=mutant.index, line_number=mutant.line.line_number)