Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: fix annotate #677

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 10 additions & 25 deletions coverage/annotate.py
Expand Up @@ -60,6 +60,7 @@ def annotate_file(self, fr, analysis):
statements = sorted(analysis.statements)
missing = sorted(analysis.missing)
excluded = sorted(analysis.excluded)
missing_branches = sorted(analysis.missing_branch_arcs().keys())

if self.directory:
dest_file = os.path.join(self.directory, flat_rootname(fr.relative_filename()))
Expand All @@ -70,34 +71,18 @@ def annotate_file(self, fr, analysis):
dest_file = fr.filename + ",cover"

with io.open(dest_file, 'w', encoding='utf8') as dest:
i = 0
j = 0
covered = True
source = fr.source()
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(u' ')
elif self.else_re.match(line):
# Special logic for lines containing only 'else:'.
if i >= len(statements) and j >= len(missing):
dest.write(u'! ')
elif i >= len(statements) or j >= len(missing):
dest.write(u'> ')
elif statements[i] == missing[j]:
dest.write(u'! ')
else:
dest.write(u'> ')
elif lineno in excluded:
# if lineno in analysis.statements:
# line_class.append("stm")
if lineno in excluded:
dest.write(u'- ')
elif covered:
elif lineno in missing:
dest.write(u'! ')
elif lineno in missing_branches:
dest.write(u'~ ')
elif lineno in statements:
dest.write(u'> ')
else:
dest.write(u'! ')

dest.write(' ')
dest.write(line)