From 7c003bb14493f170fca65e2b39d3c962635ad064 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Sun, 18 May 2014 18:11:59 -0400 Subject: Include all files when annotating, not just relative ones. #57 --- coverage/annotate.py | 3 --- 1 file changed, 3 deletions(-) (limited to 'coverage/annotate.py') diff --git a/coverage/annotate.py b/coverage/annotate.py index 19777eaf..8074df91 100644 --- a/coverage/annotate.py +++ b/coverage/annotate.py @@ -47,9 +47,6 @@ class AnnotateReporter(Reporter): `cu` is the CodeUnit for the file to annotate. """ - if not cu.relative: - return - filename = cu.filename source = cu.source_file() if self.directory: -- cgit v1.2.1 From 32782e38316c8bb3cf9d6f8b5c62081177399ffe Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Sun, 18 May 2014 18:32:33 -0400 Subject: Modernize annotate.py --- coverage/annotate.py | 78 +++++++++++++++++++++++----------------------------- 1 file changed, 35 insertions(+), 43 deletions(-) (limited to 'coverage/annotate.py') diff --git a/coverage/annotate.py b/coverage/annotate.py index 8074df91..dae9f4cf 100644 --- a/coverage/annotate.py +++ b/coverage/annotate.py @@ -47,52 +47,44 @@ class AnnotateReporter(Reporter): `cu` is the CodeUnit for the file to annotate. """ - filename = cu.filename - source = cu.source_file() - if self.directory: - dest_file = os.path.join(self.directory, cu.flat_rootname()) - dest_file += ".py,cover" - else: - dest_file = filename + ",cover" - dest = open(dest_file, 'w') - statements = sorted(analysis.statements) missing = sorted(analysis.missing) excluded = sorted(analysis.excluded) - lineno = 0 - i = 0 - j = 0 - covered = True - while True: - line = source.readline() - if line == '': - break - lineno += 1 - while i < len(statements) and statements[i] < lineno: - i += 1 - while j < len(missing) and missing[j] < lineno: - j += 1 - if i < len(statements) and statements[i] == lineno: - covered = j >= len(missing) or missing[j] > lineno - if self.blank_re.match(line): - dest.write(' ') - elif self.else_re.match(line): - # Special logic for lines containing only 'else:'. - if i >= len(statements) and j >= len(missing): - dest.write('! ') - elif i >= len(statements) or j >= len(missing): + if self.directory: + dest_file = os.path.join(self.directory, cu.flat_rootname()) + dest_file += ".py,cover" + else: + dest_file = cu.filename + ",cover" + + with open(dest_file, 'w') as dest: + i = 0 + j = 0 + covered = True + source = cu.source_file().read() + for lineno, line in enumerate(source.splitlines(True), start=1): + while i < len(statements) and statements[i] < lineno: + i += 1 + while j < len(missing) and missing[j] < lineno: + j += 1 + if i < len(statements) and statements[i] == lineno: + covered = j >= len(missing) or missing[j] > lineno + if self.blank_re.match(line): + dest.write(' ') + elif self.else_re.match(line): + # Special logic for lines containing only 'else:'. + if i >= len(statements) and j >= len(missing): + dest.write('! ') + elif i >= len(statements) or j >= len(missing): + dest.write('> ') + elif statements[i] == missing[j]: + dest.write('! ') + else: + dest.write('> ') + elif lineno in excluded: + dest.write('- ') + elif covered: dest.write('> ') - elif statements[i] == missing[j]: - dest.write('! ') else: - dest.write('> ') - elif lineno in excluded: - dest.write('- ') - elif covered: - dest.write('> ') - else: - dest.write('! ') - dest.write(line) - source.close() - dest.close() + dest.write('! ') + dest.write(line) -- cgit v1.2.1 From a189b3bb1846d8e0c7b003a94af69822d3890f9e Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Sun, 18 May 2014 21:26:57 -0400 Subject: Continued refactoring of CodeUnit --- coverage/annotate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'coverage/annotate.py') diff --git a/coverage/annotate.py b/coverage/annotate.py index dae9f4cf..5b96448a 100644 --- a/coverage/annotate.py +++ b/coverage/annotate.py @@ -61,7 +61,7 @@ class AnnotateReporter(Reporter): i = 0 j = 0 covered = True - source = cu.source_file().read() + source = cu.source() for lineno, line in enumerate(source.splitlines(True), start=1): while i < len(statements) and statements[i] < lineno: i += 1 -- cgit v1.2.1