| 
 1 2 4 5 6 7 8 9 10 12 18 19 20 21 22 24 30 31 32 33 34 35 36 37 38 39 41 42 43 44 45 46 47 48 49 50 51 56 60 61 62 63 76 77  | 
 # Demonstrate some issues with coverage.py branch testing. 
 """This isn't real code, just snippets...""" 
 # An infinite loop is structurally still a branch: it can next execute the # first line of the loop, or the first line after the loop. But # "while True" will never jump to the line after the loop, so the line # is shown as a partial branch: 
 17 while True: 
 # Notice that "while 1" also has this problem. Even though the compiler # knows there's no computation at the top of the loop, it's still expressed # in byte code as a branch with two possibilities. 
 29 while 1: 
 # Coverage.py lets the developer exclude lines that he knows will not be # executed. So far, the branch coverage doesn't use all that information # when deciding which lines are partially executed. # # Here, even though the else line is explicitly marked as never executed, # the if line complains that it never branched to the else: 
 42 if x < 1000: # This branch is always taken else: # pragma: nocover print "this never happens" 
 # try-except structures are complex branches. An except clause with a # type is a three-way branch: there could be no exception, there could be # a matching exception, and there could be a non-matching exception. # # Here we run the code twice: once with no exception, and once with a # matching exception. The "except" line is marked as partial because we # never executed its third case: a non-matching exception. 
 58 59 except ValueError: 
 # Another except clause, but this time all three cases are executed. No # partial lines are shown: 
 
 
  |