diff options
-rw-r--r-- | CHANGES.txt | 3 | ||||
-rw-r--r-- | coverage/parser.py | 5 | ||||
-rw-r--r-- | tests/test_arcs.py | 75 |
3 files changed, 40 insertions, 43 deletions
diff --git a/CHANGES.txt b/CHANGES.txt index 316df0c1..2f4516e5 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -5,7 +5,7 @@ Change history for Coverage.py 3.6.1 ----- -- Improved the branch coverage mechanism, fixing `issue 175`_. +- Improved the branch coverage facility, fixing `issue 90`_ and `issue 175`_. - Running code with ``coverage run -m`` now behaves more like Python does, setting sys.path properly, which fixes `issue 207`_ and `issue 242`_. @@ -18,6 +18,7 @@ Change history for Coverage.py a spurious warning about the trace function changing: "Trace function changed, measurement is likely wrong: None." This fixes `issue 164`_. +.. _issue 92: https://bitbucket.org/ned/coveragepy/issue/92/finally-clauses-arent-treated-properly-in .. _issue 164: https://bitbucket.org/ned/coveragepy/issue/164/trace-function-changed-warning-when-using .. _issue 175: https://bitbucket.org/ned/coveragepy/issue/175/branch-coverage-gets-confused-in-certain .. _issue 207: https://bitbucket.org/ned/coveragepy/issue/207/run-m-cannot-find-module-or-package-in diff --git a/coverage/parser.py b/coverage/parser.py index 8d6a077b..2d777a5d 100644 --- a/coverage/parser.py +++ b/coverage/parser.py @@ -512,11 +512,6 @@ class ByteParser(object): chunk.exits.add(block_stack[-1][1]) chunk = None if bc.op == OP_END_FINALLY: - if block_stack: - # A break that goes through a finally will jump to whatever - # block is on top of the stack. - # print self._block_stack_repr(block_stack) - chunk.exits.add(block_stack[-1][1]) # For the finally clause we need to find the closest exception # block, and use its jump target as an exit. for block in reversed(block_stack): diff --git a/tests/test_arcs.py b/tests/test_arcs.py index f09af8c1..d7e2e483 100644 --- a/tests/test_arcs.py +++ b/tests/test_arcs.py @@ -141,7 +141,7 @@ class SimpleArcTest(CoverageTest): ) if 0: # expected failure - def test_lambdas_are_confusing_bug_90(self): + def test_unused_lambdas_are_confusing_bug_90(self): self.check_coverage("""\ a = 1 fn = lambda x: x @@ -456,8 +456,8 @@ class ExceptionArcTest(CoverageTest): d = 12 # C assert a == 5 and c == 10 and d == 12 # D """, - arcz=".1 12 23 34 3D 45 56 67 68 8A A3 AB AD BC CD D.", - arcz_missing="3D AD", arcz_unpredicted="7A") + arcz=".1 12 23 34 3D 45 56 67 68 8A A3 AB BC CD D.", + arcz_missing="3D", arcz_unpredicted="7A") self.check_coverage("""\ a, c, d, i = 1, 1, 1, 99 try: @@ -473,8 +473,8 @@ class ExceptionArcTest(CoverageTest): d = 12 # C assert a == 8 and c == 10 and d == 1 # D """, - arcz=".1 12 23 34 3D 45 56 67 68 8A A3 AB AD BC CD D.", - arcz_missing="67 AB AD BC CD", arcz_unpredicted="") + arcz=".1 12 23 34 3D 45 56 67 68 8A A3 AB BC CD D.", + arcz_missing="67 AB BC CD", arcz_unpredicted="") def test_break_in_finally(self): @@ -493,42 +493,43 @@ class ExceptionArcTest(CoverageTest): d = 12 # C assert a == 5 and c == 10 and d == 1 # D """, - arcz=".1 12 23 34 3D 45 56 67 68 7A 8A A3 AB AD BC CD D.", - arcz_missing="3D AB BC CD", arcz_unpredicted="") + arcz=".1 12 23 34 3D 45 56 67 68 7A 8A A3 AB BC CD D.", + arcz_missing="3D AB BC CD", arcz_unpredicted="AD") - if 0: # expected failure - def test_finally_in_loop_bug_92(self): - self.check_coverage("""\ - for i in range(5): - try: - j = 3 - finally: - f = 5 - g = 6 - h = 7 - """, - arcz=".1 12 23 35 56 61 17 7.", - arcz_missing="", arcz_unpredicted="") - - def test_bug_212(self): + def test_finally_in_loop_bug_92(self): self.check_coverage("""\ - def b(exc): + for i in range(5): try: - while True: - raise Exception(exc) - except Exception as e: - if e.args != ('expected',): - raise e - q = 1 - - b('expected') - try: - b('unexpected') - except: - pass + j = 3 + finally: + f = 5 + g = 6 + h = 7 """, - arcz=".1 .2 1A 23 34 56 67 68 8. 85 AB BC C. DE E.", - arcz_missing="") + arcz=".1 12 23 35 56 61 17 7.", + arcz_missing="", arcz_unpredicted="") + + if sys.version_info >= (2, 6): + # "except Exception as e" is crucial here. + def test_bug_212(self): + self.check_coverage("""\ + def b(exc): + try: + while 1: + raise Exception(exc) # 4 + except Exception as e: + if exc != 'expected': + raise + q = 8 + + b('expected') + try: + b('unexpected') # C + except: + pass + """, + arcz=".1 .2 1A 23 34 56 67 68 8. AB BC C. DE E.", + arcz_missing="C.", arcz_unpredicted="45 7. CD") if sys.version_info >= (2, 5): # Try-except-finally was new in 2.5 |