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_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_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_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
def test_mutate_decorator():
source = """@foo\ndef foo():\n pass\n"""
assert mutate(Context(source=source, mutation_id=ALL)) == (source.replace('@foo', ''), 1)
def _get_unified_diff(source, filename, mutation_id, dict_synonyms, update_cache):
if update_cache:
update_line_numbers(filename)
if source is None:
with open(filename) as f:
source = f.read()
context = Context(
source=source,
filename=filename,
mutation_id=mutation_id,
dict_synonyms=dict_synonyms,
)
mutated_source, number_of_mutations_performed = mutate(context)
if not number_of_mutations_performed:
return ""
output = ""
for line in unified_diff(source.split('\n'), mutated_source.split('\n'), fromfile=filename, tofile=filename, lineterm=''):
output += line + "\n"
return output
:param mutation_pk: mutmut cache primary key of the mutant to apply
:type mutation_pk: str
:param dict_synonyms: list of synonym keywords for a python dictionary
:type dict_synonyms: list[str]
:param backup: if :obj:`True` create a backup of the source file
before applying the mutation
:type backup: bool
"""
filename, mutation_id = filename_and_mutation_id_from_pk(int(mutation_pk))
update_line_numbers(filename)
context = Context(
mutation_id=mutation_id,
filename=filename,
dict_synonyms=dict_synonyms,
)
mutate_file(
backup=backup,
context=context,
)