From 1a13091330fd552e47a9e18d7648e6ad83d5aac3 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Fri, 4 May 2018 15:02:42 +0200 Subject: [PATCH] =?UTF-8?q?annotate:=20annotate=20missing=20branches=20wit?= =?UTF-8?q?h=20"=E2=80=BC"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- coverage/annotate.py | 6 +++- .../farm/annotate/gold_branch/white.py,cover | 36 +++++++++++++++++++ tests/farm/annotate/run_branch.py | 12 +++++++ 3 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 tests/farm/annotate/gold_branch/white.py,cover create mode 100644 tests/farm/annotate/run_branch.py diff --git a/coverage/annotate.py b/coverage/annotate.py index 48e2b91ce..429e2cbfc 100644 --- a/coverage/annotate.py +++ b/coverage/annotate.py @@ -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())) @@ -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'! ') diff --git a/tests/farm/annotate/gold_branch/white.py,cover b/tests/farm/annotate/gold_branch/white.py,cover new file mode 100644 index 000000000..e164227d4 --- /dev/null +++ b/tests/farm/annotate/gold_branch/white.py,cover @@ -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 + + # 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) diff --git a/tests/farm/annotate/run_branch.py b/tests/farm/annotate/run_branch.py new file mode 100644 index 000000000..eb9f277c7 --- /dev/null +++ b/tests/farm/annotate/run_branch.py @@ -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")