def data_for_file(self, fr, analysis): """Produce the data needed for one file's report.""" if self.has_arcs: missing_branch_arcs = analysis.missing_branch_arcs() arcs_executed = analysis.arcs_executed() contexts_by_lineno = collections.defaultdict(list) if self.config.show_contexts: # Lookup line number contexts. contexts_by_lineno = analysis.data.contexts_by_lineno(fr.filename) lines = [] for lineno, tokens in enumerate(fr.source_token_lines(), start=1): # Figure out how to mark this line. css_classes = [] short_annotations = [] long_annotations = [] if lineno in analysis.statements: css_classes.append("stm") if lineno in analysis.excluded: css_classes.append(self.c_exc) elif lineno in analysis.missing: css_classes.append(self.c_mis) elif self.has_arcs and lineno in missing_branch_arcs: css_classes.append(self.c_par) for b in missing_branch_arcs[lineno]: if b < 0: short_annotations.append("exit") else: short_annotations.append(b) long_annotations.append( fr.missing_arc_description(lineno, b, arcs_executed)) elif lineno in analysis.statements: css_classes.append(self.c_run) if self.config.show_contexts: contexts = sorted(filter(None, contexts_by_lineno[lineno])) else: contexts = None lines.append( SimpleNamespace( tokens=tokens, number=lineno, css_class=' '.join(css_classes) or "pln", contexts=contexts, short_annotations=short_annotations, long_annotations=long_annotations, )) file_data = SimpleNamespace( relative_filename=fr.relative_filename(), nums=analysis.numbers, lines=lines, ) return file_data
def data_for_file(self, fr, analysis): """Produce the data needed for one file's report.""" if self.has_arcs: missing_branch_arcs = analysis.missing_branch_arcs() arcs_executed = analysis.arcs_executed() contexts_by_lineno = collections.defaultdict(list) if self.config.show_contexts: # Lookup line number contexts. contexts_by_lineno = analysis.data.contexts_by_lineno(fr.filename) lines = [] for lineno, tokens in enumerate(fr.source_token_lines(), start=1): # Figure out how to mark this line. category = None short_annotations = [] long_annotations = [] if lineno in analysis.excluded: category = 'exc' elif lineno in analysis.missing: category = 'mis' elif self.has_arcs and lineno in missing_branch_arcs: category = 'par' for b in missing_branch_arcs[lineno]: if b < 0: short_annotations.append("exit") else: short_annotations.append(b) long_annotations.append( fr.missing_arc_description(lineno, b, arcs_executed)) elif lineno in analysis.statements: category = 'run' if category and self.config.show_contexts: contexts = sorted(c or "(empty)" for c in contexts_by_lineno[lineno]) else: contexts = None lines.append( SimpleNamespace( tokens=tokens, number=lineno, category=category, statement=(lineno in analysis.statements), contexts=contexts, short_annotations=short_annotations, long_annotations=long_annotations, )) file_data = SimpleNamespace( relative_filename=fr.relative_filename(), nums=analysis.numbers, lines=lines, ) return file_data