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

annotate: annotate missing branches with "~" #676

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
6 changes: 5 additions & 1 deletion coverage/annotate.py
Original file line number Diff line number Diff line change
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())
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no reason to sort this, since we're just using in on it. Making it a set would be better. Same for excluded, though that was my fault! :) statements and missing need to be sorted because of how the algorithm walks them in tandem.


if self.directory:
dest_file = os.path.join(self.directory, flat_rootname(fr.relative_filename()))
Expand Down Expand Up @@ -96,7 +97,10 @@ def annotate_file(self, fr, analysis):
elif lineno in excluded:
dest.write(u'- ')
elif covered:
dest.write(u'> ')
if lineno in missing_branches:
dest.write(u'~ ')
else:
dest.write(u'> ')
else:
dest.write(u'! ')

Expand Down
36 changes: 36 additions & 0 deletions tests/farm/annotate/gold_branch/white.py,cover
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
# For details: https://bitbucket.org/ned/coveragepy/src/default/NOTICE.txt
Copy link
Owner

@nedbat nedbat Jun 30, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll need to correct the NOTICE links to GitHub to get the tests to pass.


# A test case sent to me by Steve White

> def f(self):
! if self==1:
! pass
! elif self.m('fred'):
! pass
! elif (g==1) and (b==2):
! pass
! elif self.m('fred')==True:
! pass
! elif ((g==1) and (b==2))==True:
! pass
! else:
! pass

> def g(x):
~ if x == 1:
> a = 1
! else:
! a = 2

> g(1)

> def h(x):
- if 0: #pragma: no cover
- pass
~ if x == 1:
! a = 1
> else:
> a = 2

> h(2)
12 changes: 12 additions & 0 deletions tests/farm/annotate/run_branch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
# For details: https://bitbucket.org/ned/coveragepy/src/default/NOTICE.txt

from tests.test_farm import clean, compare, copy, run

copy("src", "out")
run("""
coverage run --branch white.py
coverage annotate white.py
""", rundir="out")
compare("out", "gold_branch", "*,cover")
clean("out")