summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2016-01-29 11:26:18 -0500
committerNed Batchelder <ned@nedbatchelder.com>2016-01-29 11:26:18 -0500
commit3ef7b040af5186b2d716cdc35c9ea278504ea04a (patch)
tree49484589eddbae2dd7a8a4c158491e9b88c018b3
parentcd83e41d7ee0eb2e48c8340539213f3bdee49239 (diff)
downloadpython-coveragepy-git-3ef7b040af5186b2d716cdc35c9ea278504ea04a.tar.gz
Don't track unhandled exception branches
-rw-r--r--CHANGES.rst8
-rw-r--r--coverage/parser.py17
-rw-r--r--tests/test_arcs.py24
3 files changed, 20 insertions, 29 deletions
diff --git a/CHANGES.rst b/CHANGES.rst
index 550a595c..709e1395 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -6,6 +6,14 @@ Change history for Coverage.py
==============================
+Unreleased
+----------
+
+- When running your program, execution can jump from an ``except X:`` line to
+ some other line when an exception other than ``X`` happens. This jump is no
+ longer considered a branch when measuring branch coverage.
+
+
Version 4.1b2 --- 2016-01-23
----------------------------
diff --git a/coverage/parser.py b/coverage/parser.py
index 27c17438..17f1f0d5 100644
--- a/coverage/parser.py
+++ b/coverage/parser.py
@@ -631,13 +631,6 @@ class AstArcAnalyzer(object):
self.arcs.add((last_handler_start, handler_start))
last_handler_start = handler_start
handler_exits |= self.add_body_arcs(handler_node.body, from_line=handler_start)
- if handler_node.type is None:
- # "except:" doesn't jump to subsequent handlers, or
- # "finally:".
- last_handler_start = None
- # Note that once we have `except:`, no further handlers
- # will ever be run. We'll keep collecting them, and the
- # code will get marked as not run.
if node.orelse:
exits = self.add_body_arcs(node.orelse, prev_lines=exits)
@@ -653,11 +646,6 @@ class AstArcAnalyzer(object):
try_block.raise_from | # or a `raise`,
try_block.return_from # or a `return`.
)
- if last_handler_start is not None:
- # If we had handlers, and we didn't have a bare `except:`
- # handler, then the last handler jumps to the `finally` for the
- # unhandled exceptions.
- final_from.add(last_handler_start)
exits = self.add_body_arcs(node.finalbody, prev_lines=final_from)
if try_block.break_from:
@@ -668,11 +656,6 @@ class AstArcAnalyzer(object):
self.process_raise_exits(exits)
if try_block.return_from:
self.process_return_exits(exits)
- else:
- # No final body: if there is an `except` handler without a
- # catch-all, then exceptions can raise from there.
- if last_handler_start is not None:
- self.process_raise_exits([last_handler_start])
return exits
diff --git a/tests/test_arcs.py b/tests/test_arcs.py
index 5c0d1e50..030b719d 100644
--- a/tests/test_arcs.py
+++ b/tests/test_arcs.py
@@ -704,8 +704,8 @@ class ExceptionArcTest(CoverageTest):
c = 9
assert a == 3 and b == 1 and c == 9
""",
- arcz=".1 12 23 45 46 39 59 67 79 69 9A A.",
- arcz_missing="45 59 46 67 79 69",
+ arcz=".1 12 23 45 46 39 59 67 79 9A A.",
+ arcz_missing="45 59 46 67 79",
)
self.check_coverage("""\
a, b, c = 1, 1, 1
@@ -719,8 +719,8 @@ class ExceptionArcTest(CoverageTest):
c = 9
assert a == 1 and b == 5 and c == 9
""",
- arcz=".1 12 23 45 46 69 39 59 67 79 9A A.",
- arcz_missing="39 46 67 79 69",
+ arcz=".1 12 23 45 46 39 59 67 79 9A A.",
+ arcz_missing="39 46 67 79",
arcz_unpredicted="34",
)
self.check_coverage("""\
@@ -735,8 +735,8 @@ class ExceptionArcTest(CoverageTest):
c = 9
assert a == 7 and b == 1 and c == 9
""",
- arcz=".1 12 23 45 46 39 59 67 79 69 9A A.",
- arcz_missing="39 45 59 69",
+ arcz=".1 12 23 45 46 39 59 67 79 9A A.",
+ arcz_missing="39 45 59",
arcz_unpredicted="34",
)
self.check_coverage("""\
@@ -754,9 +754,9 @@ class ExceptionArcTest(CoverageTest):
pass
assert a == 1 and b == 1 and c == 10
""",
- arcz=".1 12 23 34 4A 56 6A 57 78 8A 7A AD BC CD D.",
+ arcz=".1 12 23 34 4A 56 6A 57 78 8A AD BC CD D.",
arcz_missing="4A 56 6A 78 8A AD",
- arcz_unpredicted="45 AB",
+ arcz_unpredicted="45 7A AB",
)
def test_return_finally(self):
@@ -808,11 +808,11 @@ class ExceptionArcTest(CoverageTest):
""",
arcz=
".1 1Q QR RS ST T. "
- ".2 23 34 45 56 4O 6L 7L "
+ ".2 23 34 45 56 4O 6L "
"78 89 9A AL 8B BC CD DL BE EF FG GL EH HI IJ JL HL "
"LO L4 L. LM "
"MN NO O.",
- arcz_missing="6L 7L HL",
+ arcz_missing="6L HL",
arcz_unpredicted="67",
)
@@ -852,11 +852,11 @@ class ExceptionArcTest(CoverageTest):
""",
arcz=
".1 1S ST TU UV V. "
- ".2 23 34 45 56 6A 78 7N 8N 4Q "
+ ".2 23 34 45 56 6A 78 8N 4Q "
"AB BC CN AD DE EF FN DG GH HI IN GJ JK KL LN JN "
"NQ N4 N. NO "
"OP PQ Q.",
- arcz_missing="78 8N 7N JN",
+ arcz_missing="78 8N JN",
arcz_unpredicted="",
)