1 """Source file annotation for Coverage.""" |
1 """Source file annotation for Coverage.""" |
2 |
2 |
3 import os, re |
3 import os, re |
4 |
4 |
|
5 from .backward import sorted # pylint: disable=W0622 |
5 from .report import Reporter |
6 from .report import Reporter |
6 |
7 |
7 class AnnotateReporter(Reporter): |
8 class AnnotateReporter(Reporter): |
8 """Generate annotated source files showing line coverage. |
9 """Generate annotated source files showing line coverage. |
9 |
10 |
24 Executed lines use '>', lines not executed use '!', lines excluded from |
25 Executed lines use '>', lines not executed use '!', lines excluded from |
25 consideration use '-'. |
26 consideration use '-'. |
26 |
27 |
27 """ |
28 """ |
28 |
29 |
29 def __init__(self, coverage, ignore_errors=False): |
30 def __init__(self, coverage, config): |
30 super(AnnotateReporter, self).__init__(coverage, ignore_errors) |
31 super(AnnotateReporter, self).__init__(coverage, config) |
31 self.directory = None |
32 self.directory = None |
32 |
33 |
33 blank_re = re.compile(r"\s*(#|$)") |
34 blank_re = re.compile(r"\s*(#|$)") |
34 else_re = re.compile(r"\s*else\s*:\s*(#|$)") |
35 else_re = re.compile(r"\s*else\s*:\s*(#|$)") |
35 |
36 |
36 def report(self, morfs, directory=None, omit_prefixes=None): |
37 def report(self, morfs, directory=None): |
37 """Run the report.""" |
38 """Run the report. |
38 self.report_files(self.annotate_file, morfs, directory, omit_prefixes) |
39 |
|
40 See `coverage.report()` for arguments. |
|
41 |
|
42 """ |
|
43 self.report_files(self.annotate_file, morfs, directory) |
39 |
44 |
40 def annotate_file(self, cu, analysis): |
45 def annotate_file(self, cu, analysis): |
41 """Annotate a single file. |
46 """Annotate a single file. |
42 |
47 |
43 `cu` is the CodeUnit for the file to annotate. |
48 `cu` is the CodeUnit for the file to annotate. |
53 dest_file += ".py,cover" |
58 dest_file += ".py,cover" |
54 else: |
59 else: |
55 dest_file = filename + ",cover" |
60 dest_file = filename + ",cover" |
56 dest = open(dest_file, 'w') |
61 dest = open(dest_file, 'w') |
57 |
62 |
58 statements = analysis.statements |
63 statements = sorted(analysis.statements) |
59 missing = analysis.missing |
64 missing = sorted(analysis.missing) |
60 excluded = analysis.excluded |
65 excluded = sorted(analysis.excluded) |
61 |
66 |
62 lineno = 0 |
67 lineno = 0 |
63 i = 0 |
68 i = 0 |
64 j = 0 |
69 j = 0 |
65 covered = True |
70 covered = True |