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_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_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_basic_mutations_python3(original, expected):
actual = mutate(Context(source=original, mutation_id=ALL, dict_synonyms=['Struct', 'FooBarDict']))[0]
assert actual == expected
def test_multiple_mutations(original, expected):
mutations = list_mutations(Context(source=original))
assert len(mutations) == 3
assert mutate(Context(source=original, mutation_id=mutations[0])) == (expected[0], 1)
assert mutate(Context(source=original, mutation_id=mutations[1])) == (expected[1], 1)
def test_do_not_mutate_python3(source):
actual = mutate(Context(source=source, mutation_id=ALL, dict_synonyms=['Struct', 'FooBarDict']))[0]
assert actual == source
def test_bug_github_issue_26():
source = """
class ConfigurationOptions(Protocol):
min_name_length: int
"""
mutate(Context(source=source))
def test_multiline_dunder_whitelist():
source = """
__all__ = [
1,
2,
'foo',
'bar',
]
"""
assert mutate(Context(source=source)) == (source, 0)