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():
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_pragma_no_mutate():
source = """def foo():\n return 1+1 # pragma: no mutate\n"""
assert mutate(Context(source=source, mutation_id=ALL)) == (source, 0)
def test_mutate_body_of_function_with_return_type_annotation():
source = """
def foo() -> int:
return 0
"""
assert mutate(Context(source=source, mutation_id=ALL))[0] == source.replace('0', '1')
def test_mutate_all():
assert mutate(Context(source='def foo():\n return 1+1', mutation_id=ALL)) == ('def foo():\n return 2-2', 3)
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_bug_github_issue_77():
# Don't crash on this
Context(source='')
def test_basic_mutations_python36(original, expected):
actual = mutate(Context(source=original, mutation_id=ALL, dict_synonyms=['Struct', 'FooBarDict']))[0]
assert actual == expected