1 """Summary reporting"""
5 from coverage
.report
import Reporter
6 from coverage
.results
import Numbers
7 from coverage
.misc
import NotPython
10 class SummaryReporter(Reporter
):
11 """A reporter for writing the summary report."""
13 def __init__(self
, coverage
, config
):
14 super(SummaryReporter
, self
).__init
__(coverage
, config
)
15 self
.branches
= coverage
.data
.has_arcs()
17 def report(self
, morfs
, outfile
=None):
18 """Writes a report summarizing coverage statistics per module.
20 `outfile` is a file object to write the summary to.
23 self
.find_code_units(morfs
)
25 # Prepare the formatting strings
26 max_name
= max([len(cu
.name
) for cu
in self
.code_units
] + [5])
27 fmt_name
= "%%- %ds " % max_name
28 fmt_err
= "%s %s: %s\n"
29 header
= (fmt_name
% "Name") + " Stmts Miss"
30 fmt_coverage
= fmt_name
+ "%6d %6d"
32 header
+= " Branch BrMiss"
33 fmt_coverage
+= " %6d %6d"
34 width100
= Numbers
.pc_str_width()
35 header
+= "%*s" % (width100
+4, "Cover")
36 fmt_coverage
+= "%%%ds%%%%" % (width100
+3,)
37 if self
.config
.show_missing
:
40 rule
= "-" * len(header
) + "\n"
53 for cu
in self
.code_units
:
55 analysis
= self
.coverage
._analyze
(cu
)
56 nums
= analysis
.numbers
57 args
= (cu
.name
, nums
.n_statements
, nums
.n_missing
)
59 args
+= (nums
.n_branches
, nums
.n_missing_branches
)
60 args
+= (nums
.pc_covered_str
,)
61 if self
.config
.show_missing
:
62 args
+= (analysis
.missing_formatted(),)
63 outfile
.write(fmt_coverage
% args
)
65 except KeyboardInterrupt: # pragma: not covered
68 report_it
= not self
.config
.ignore_errors
70 typ
, msg
= sys
.exc_info()[:2]
71 if typ
is NotPython
and not cu
.should_be_python():
74 outfile
.write(fmt_err
% (cu
.name
, typ
.__name
__, msg
))
78 args
= ("TOTAL", total
.n_statements
, total
.n_missing
)
80 args
+= (total
.n_branches
, total
.n_missing_branches
)
81 args
+= (total
.pc_covered_str
,)
82 if self
.config
.show_missing
:
84 outfile
.write(fmt_coverage
% args
)
86 return total
.pc_covered