Skip to content

Commit

Permalink
add coverage style diff boxed#193
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Ledermann committed May 30, 2021
1 parent afe4db7 commit 5f89005
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions mutmut/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,22 @@ def print_stuff(title, mutant_query):
print_stuff('Survived 🙁', select(x for x in Mutant if x.status == BAD_SURVIVED))
print_stuff('Untested/skipped', select(x for x in Mutant if x.status == UNTESTED))

def _get_line_diff(source, filename, mutation_id, dict_synonyms, update_cache):
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 ""
try:
return mutated_source.splitlines()[mutation_id.line_number]
except IndexError as exc:
print(exc)
return str(exc)


def get_unified_diff(argument, dict_synonyms, update_cache=True, source=None):
filename, mutation_id = filename_and_mutation_id_from_pk(argument)
Expand Down Expand Up @@ -253,6 +269,12 @@ def print_result_cache_junitxml(dict_synonyms, suspicious_policy, untested_polic
@db_session
def create_html_report(dict_synonyms):
mutants = list(select(x for x in Mutant))
status_emoji = {
BAD_TIMEOUT: '⏰',
OK_SUSPICIOUS: '🤔',
BAD_SURVIVED : '🙁',

}

os.makedirs('html', exist_ok=True)

Expand All @@ -276,6 +298,9 @@ def create_html_report(dict_synonyms):
mutants_by_status = defaultdict(list)
for mutant in mutants:
mutants_by_status[mutant.status].append(mutant)
mutants_by_line = defaultdict(list)
for mutant in mutants:
mutants_by_line[mutant.line.line_number].append(mutant)

f.write('<html><body>')

Expand All @@ -293,6 +318,18 @@ def create_html_report(dict_synonyms):
len(mutants_by_status[BAD_SURVIVED]),
))

def print_line_diff(line_no):
mutants = mutants_by_line[line_no]
for mutant in sorted(mutants, key=lambda m: m.id):
if mutant.status in [BAD_TIMEOUT, BAD_SURVIVED, OK_SUSPICIOUS]:
diff = _get_line_diff(source, filename, RelativeMutationID(mutant.line.line, mutant.index, mutant.line.line_number), dict_synonyms, update_cache=False)
yield mutant.status, diff

for i, line in enumerate(source.splitlines()):
f.write(f'<p><span style="float: left; width: 4em;">{i}</span><pre>{line}</pre>&nbsp;</p>')
for status, diff in print_line_diff(i):
f.write(f'<p><span style="float: left; width: 4em;">{status_emoji[status]}</span><pre>{diff}</pre></p>')

def print_diffs(status):
mutants = mutants_by_status[status]
for mutant in sorted(mutants, key=lambda m: m.id):
Expand Down

0 comments on commit 5f89005

Please sign in to comment.