OLD | NEW |
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 coverage.backward import sorted # pylint: disable=W0622 |
5 from coverage.report import Reporter | 6 from coverage.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 |
10 This reporter creates annotated copies of the measured source files. Each | 11 This reporter creates annotated copies of the measured source files. Each |
11 .py file is copied as a .py,cover file, with a left-hand margin annotating | 12 .py file is copied as a .py,cover file, with a left-hand margin annotating |
12 each line:: | 13 each line:: |
13 | 14 |
14 > def h(x): | 15 > def h(x): |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 | 53 |
53 filename = cu.filename | 54 filename = cu.filename |
54 source = cu.source_file() | 55 source = cu.source_file() |
55 if self.directory: | 56 if self.directory: |
56 dest_file = os.path.join(self.directory, cu.flat_rootname()) | 57 dest_file = os.path.join(self.directory, cu.flat_rootname()) |
57 dest_file += ".py,cover" | 58 dest_file += ".py,cover" |
58 else: | 59 else: |
59 dest_file = filename + ",cover" | 60 dest_file = filename + ",cover" |
60 dest = open(dest_file, 'w') | 61 dest = open(dest_file, 'w') |
61 | 62 |
62 statements = analysis.statements | 63 statements = sorted(analysis.statements) |
63 missing = analysis.missing | 64 missing = sorted(analysis.missing) |
64 excluded = analysis.excluded | 65 excluded = sorted(analysis.excluded) |
65 | 66 |
66 lineno = 0 | 67 lineno = 0 |
67 i = 0 | 68 i = 0 |
68 j = 0 | 69 j = 0 |
69 covered = True | 70 covered = True |
70 while True: | 71 while True: |
71 line = source.readline() | 72 line = source.readline() |
72 if line == '': | 73 if line == '': |
73 break | 74 break |
74 lineno += 1 | 75 lineno += 1 |
(...skipping 17 matching lines...) Expand all Loading... |
92 dest.write('> ') | 93 dest.write('> ') |
93 elif lineno in excluded: | 94 elif lineno in excluded: |
94 dest.write('- ') | 95 dest.write('- ') |
95 elif covered: | 96 elif covered: |
96 dest.write('> ') | 97 dest.write('> ') |
97 else: | 98 else: |
98 dest.write('! ') | 99 dest.write('! ') |
99 dest.write(line) | 100 dest.write(line) |
100 source.close() | 101 source.close() |
101 dest.close() | 102 dest.close() |
OLD | NEW |