From eba18707241a052419d54cdc304aea346aa0605c Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Sat, 12 Oct 2019 19:37:58 -0400 Subject: Better presentation of contexts. #855 --- coverage/html.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'coverage/html.py') diff --git a/coverage/html.py b/coverage/html.py index 5b4c6ca9..4a0e1a33 100644 --- a/coverage/html.py +++ b/coverage/html.py @@ -77,6 +77,8 @@ def write_html(fname, html): class HtmlDataGeneration(object): """Generate structured data to be turned into HTML reports.""" + EMPTY = "(empty)" + def __init__(self, cov): self.coverage = cov self.config = self.coverage.config @@ -121,10 +123,15 @@ class HtmlDataGeneration(object): elif lineno in analysis.statements: category = 'run' + contexts = contexts_label = None + context_list = None if category and self.config.show_contexts: - contexts = sorted(c or "(empty)" for c in contexts_by_lineno[lineno]) - else: - contexts = None + contexts = sorted(c or self.EMPTY for c in contexts_by_lineno[lineno]) + if contexts == [self.EMPTY]: + contexts_label = self.EMPTY + else: + contexts_label = "{} ctx".format(len(contexts)) + context_list = contexts lines.append(SimpleNamespace( tokens=tokens, @@ -132,6 +139,8 @@ class HtmlDataGeneration(object): category=category, statement=(lineno in analysis.statements), contexts=contexts, + contexts_label=contexts_label, + context_list=context_list, short_annotations=short_annotations, long_annotations=long_annotations, )) -- cgit v1.2.1