diff options
Diffstat (limited to 'test/test_arcs.py')
-rw-r--r-- | test/test_arcs.py | 78 |
1 files changed, 67 insertions, 11 deletions
diff --git a/test/test_arcs.py b/test/test_arcs.py index dea3700f..41731dba 100644 --- a/test/test_arcs.py +++ b/test/test_arcs.py @@ -25,16 +25,16 @@ class SimpleArcTest(CoverageTest): a = 2 b = 3 - + c = 5 """, - arcz=".2 23 35 5.") + arcz=".2 23 35 5-2") def test_function_def(self): self.check_coverage("""\ def foo(): a = 2 - + foo() """, arcz=".1 .2 14 2. 4.") @@ -54,7 +54,7 @@ class SimpleArcTest(CoverageTest): assert a == 1 """, arcz=".1 12 23 24 34 4.", arcz_missing="23 34") - + def test_if_else(self): self.check_coverage("""\ if len([]) == 0: @@ -90,6 +90,12 @@ class SimpleArcTest(CoverageTest): arcz=".1 14 45 5. .2 2. 23 3.", arcz_missing="23 3.") def test_multiline(self): + # The firstlineno of the a assignment below differs among Python + # versions. + if sys.version_info >= (2, 5): + arcz = ".1 15 5-2" + else: + arcz = ".1 15 5-1" self.check_coverage("""\ a = ( 2 + @@ -98,7 +104,7 @@ class SimpleArcTest(CoverageTest): b = \\ 6 """, - arcz=".1 15 5.", arcz_missing="") + arcz=arcz, arcz_missing="") def test_if_return(self): self.check_coverage("""\ @@ -113,10 +119,33 @@ class SimpleArcTest(CoverageTest): arcz=".1 16 67 7. .2 23 24 3. 45 5.", arcz_missing="" ) + def test_dont_confuse_exit_and_else(self): + self.check_coverage("""\ + def foo(): + if foo: + a = 3 + else: + a = 5 + return a + assert foo() == 3 # 7 + """, + arcz=".1 17 7. .2 23 36 25 56 6.", arcz_missing="25 56" + ) + self.check_coverage("""\ + def foo(): + if foo: + a = 3 + else: + a = 5 + foo() # 6 + """, + arcz=".1 16 6. .2 23 3. 25 5.", arcz_missing="25 5." + ) + class LoopArcTest(CoverageTest): """Arc-measuring tests involving loops.""" - + def test_loop(self): self.check_coverage("""\ for i in range(10): @@ -189,7 +218,7 @@ class LoopArcTest(CoverageTest): ) # With "while True", 2.x thinks it's computation, 3.x thinks it's # constant. - if sys.hexversion >= 0x03000000: + if sys.version_info >= (3, 0): arcz = ".1 12 23 34 45 36 63 57 27 7." else: arcz = ".1 12 23 34 45 36 62 57 27 7." @@ -206,6 +235,33 @@ class LoopArcTest(CoverageTest): arcz_missing="27" # while loop never exits naturally. ) + def test_for_if_else_for(self): + self.check_coverage("""\ + def branches_2(l): + if l: + for e in l: + a = 4 + else: + a = 6 + + def branches_3(l): + for x in l: + if x: + for e in l: + a = 12 + else: + a = 14 + + branches_2([0,1]) + branches_3([0,1]) + """, + arcz= + ".1 18 8G GH H. " + ".2 23 34 43 26 3. 6. " + ".9 9A 9-8 AB BC CB B9 AE E9", + arcz_missing="26 6." + ) + class ExceptionArcTest(CoverageTest): """Arc-measuring tests involving exception handling.""" @@ -246,7 +302,7 @@ class ExceptionArcTest(CoverageTest): b = 9 assert a == 5 and b == 9 """, - arcz=".1 12 .3 3. 24 45 56 67 7A 89 9A A.", + arcz=".1 12 .3 3-2 24 45 56 67 7A 89 9A A.", arcz_missing="67 7A", arcz_unpredicted="68") def test_except_with_type(self): @@ -265,7 +321,7 @@ class ExceptionArcTest(CoverageTest): assert try_it(0) == 8 # C assert try_it(1) == 6 # D """, - arcz=".1 12 .3 3. 24 4C CD D. .5 56 67 78 8B 9A AB B.", + arcz=".1 12 .3 3-2 24 4C CD D. .5 56 67 78 8B 9A AB B-4", arcz_missing="", arcz_unpredicted="79") @@ -364,7 +420,7 @@ class ExceptionArcTest(CoverageTest): 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="") - if sys.hexversion >= 0x02050000: + if sys.version_info >= (2, 5): # Try-except-finally was new in 2.5 def test_except_finally(self): self.check_coverage("""\ @@ -392,7 +448,7 @@ class ExceptionArcTest(CoverageTest): c = 11 assert a == 5 and b == 9 and c == 11 """, - arcz=".1 12 .3 3. 24 45 56 67 7B 89 9B BC C.", + arcz=".1 12 .3 3-2 24 45 56 67 7B 89 9B BC C.", arcz_missing="67 7B", arcz_unpredicted="68") |