Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add coverage style html report #211

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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