From 0f1b0d30e306ad35b1e29912e0613e9bf2618c47 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Mon, 4 Jul 2011 13:53:18 -0400 Subject: for-else constructs are handled properly, avoiding bogus partial branch warnings. Fixes issue #122. Bonus irony: this also makes while 1 loops automatically understood better too. --- CHANGES.txt | 4 ++++ test/farm/html/run_b_branch.py | 6 +++--- test/farm/html/src/b.py | 19 ++++++++++--------- test/test_arcs.py | 4 ++-- 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 03c310d..71aa26d 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -5,6 +5,10 @@ Change history for Coverage.py Version 3.5.1 ------------- +- for-else constructs are understood better, and don't cause erroneous partial + branch warnings. Fixes `issue 122`_. + +.. _issue 122: http://bitbucket.org/ned/coveragepy/issue/122/for-else-always-reports-missing-branch Version 3.5 --- 29 June 2011 diff --git a/test/farm/html/run_b_branch.py b/test/farm/html/run_b_branch.py index f129e43..3154339 100644 --- a/test/farm/html/run_b_branch.py +++ b/test/farm/html/run_b_branch.py @@ -15,14 +15,14 @@ compare("gold_b_branch", "html_b_branch", size_within=10, file_pattern="*.html") contains("html_b_branch/b.html", "if x < 2", "    a = 3", - "76%", + "70%", "8", "exit", - "25   26", + "23   25", ) contains("html_b_branch/index.html", "b", - "76%" + "70%" ) clean("html_b_branch") diff --git a/test/farm/html/src/b.py b/test/farm/html/src/b.py index dffdd50..3bf73a9 100644 --- a/test/farm/html/src/b.py +++ b/test/farm/html/src/b.py @@ -16,13 +16,14 @@ def two(x): two(1) -def three_way(): - # for-else can be a three-way branch. - for i in range(10): - if i == 3: - break - else: - return 23 - return 17 +def three(): + try: + # This if has two branches, *neither* one taken. + if name_error_this_variable_doesnt_exist: + a = 1 + else: + a = 2 + except: + pass -three_way() +three() diff --git a/test/test_arcs.py b/test/test_arcs.py index 9f86ecd..2c98317 100644 --- a/test/test_arcs.py +++ b/test/test_arcs.py @@ -213,12 +213,12 @@ class LoopArcTest(CoverageTest): i += 1 assert a == 4 and i == 3 """, - arcz=".1 12 23 27 34 45 36 63 57 7.", + arcz=".1 12 23 34 45 36 63 57 7.", ) # With "while True", 2.x thinks it's computation, 3.x thinks it's # constant. if sys.version_info >= (3, 0): - arcz = ".1 12 23 27 34 45 36 63 57 7." + arcz = ".1 12 23 34 45 36 63 57 7." else: arcz = ".1 12 23 27 34 45 36 62 57 7." self.check_coverage("""\ -- cgit v1.2.1