diff options
Diffstat (limited to 'test/test_arcs.py')
-rw-r--r-- | test/test_arcs.py | 95 |
1 files changed, 78 insertions, 17 deletions
diff --git a/test/test_arcs.py b/test/test_arcs.py index dafe0fbb..a9f7470b 100644 --- a/test/test_arcs.py +++ b/test/test_arcs.py @@ -143,6 +143,23 @@ class SimpleArcTest(CoverageTest): ) +if sys.version_info >= (2, 6): + class WithTest(CoverageTest): + """Arc-measuring tests involving context managers.""" + + def test_with(self): + self.check_coverage("""\ + def example(): + with open("test", "w") as f: # exit + f.write("") + return 1 + + example() + """, + arcz=".1 .2 23 34 4. 16 6." + ) + + class LoopArcTest(CoverageTest): """Arc-measuring tests involving loops.""" @@ -213,15 +230,14 @@ class LoopArcTest(CoverageTest): i += 1 assert a == 4 and i == 3 """, - arcz=".1 12 23 34 45 36 63 57 27 7.", - arcz_missing="27" # while loop never exits naturally. + 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 34 45 36 63 57 27 7." + arcz = ".1 12 23 34 45 36 63 57 7." else: - arcz = ".1 12 23 34 45 36 62 57 27 7." + arcz = ".1 12 23 27 34 45 36 62 57 7." self.check_coverage("""\ a, i = 1, 0 while True: @@ -232,7 +248,6 @@ class LoopArcTest(CoverageTest): assert a == 4 and i == 3 """, arcz=arcz, - arcz_missing="27" # while loop never exits naturally. ) def test_for_if_else_for(self): @@ -262,6 +277,21 @@ class LoopArcTest(CoverageTest): arcz_missing="26 6." ) + def test_for_else(self): + self.check_coverage("""\ + def forelse(seq): + for n in seq: + if n > 5: + break + else: + print('None of the values were greater than 5') + print('Done') + forelse([1,2]) + forelse([1,6]) + """, + arcz=".1 .2 23 32 34 47 26 67 7. 18 89 9." + ) + class ExceptionArcTest(CoverageTest): """Arc-measuring tests involving exception handling.""" @@ -420,18 +450,19 @@ 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="") - def xxx_xest_finally_in_loop_2(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="") + if 0: + def test_finally_in_loop_2(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="") if sys.version_info >= (2, 5): # Try-except-finally was new in 2.5 @@ -481,3 +512,33 @@ class MiscArcTest(CoverageTest): assert d """, arcz=".1 19 9.") + + +class ExcludeTest(CoverageTest): + """Tests of exclusions to indicate known partial branches.""" + + def test_default(self): + # A number of forms of pragma comment are accepted. + self.check_coverage("""\ + a = 1 + if a: #pragma: no branch + b = 3 + c = 4 + if c: # pragma NOBRANCH + d = 6 + e = 7 + """, + [1,2,3,4,5,6,7], + arcz=".1 12 23 24 34 45 56 57 67 7.", arcz_missing="") + + def test_custom_pragmas(self): + self.check_coverage("""\ + a = 1 + while a: # [only some] + c = 3 + break + assert c == 5-2 + """, + [1,2,3,4,5], + partials=["only some"], + arcz=".1 12 23 34 45 25 5.", arcz_missing="") |