diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2010-04-27 22:00:59 -0400 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2010-04-27 22:00:59 -0400 |
commit | 2ad723a05059d723d9dda504df9bbcd1e091caa2 (patch) | |
tree | 8e0c5af70768b6e3bb0a0ad669c90df04ea3ed91 /test | |
parent | 3e4217569a648776e7d6a689f0ed5b3e87caccbe (diff) | |
download | python-coveragepy-git-2ad723a05059d723d9dda504df9bbcd1e091caa2.tar.gz |
Properly record multiple exits separately. Fixes #62.
Diffstat (limited to 'test')
-rw-r--r-- | test/coveragetest.py | 36 | ||||
-rw-r--r-- | test/test_arcs.py | 18 |
2 files changed, 41 insertions, 13 deletions
diff --git a/test/coveragetest.py b/test/coveragetest.py index 981beeea..277b4f03 100644 --- a/test/coveragetest.py +++ b/test/coveragetest.py @@ -176,18 +176,34 @@ class CoverageTest(TestCase): ".1 12 2." --> [(-1,1), (1,2), (2,-1)] + Minus signs can be included in the pairs: + + "-11, 12, 2-5" --> [(-1,1), (1,2), (2,-5)] + """ arcs = [] - for a,b in arcz.split(): - arcs.append((self._arcz_map[a], self._arcz_map[b])) + for pair in arcz.split(): + asgn = bsgn = 1 + if len(pair) == 2: + a,b = pair + else: + assert len(pair) == 3 + if pair[0] == '-': + _,a,b = pair + asgn = -1 + else: + assert pair[1] == '-' + a,_,b = pair + bsgn = -1 + arcs.append((asgn*self._arcz_map[a], bsgn*self._arcz_map[b])) return sorted(arcs) - def assertEqualArcs(self, a1, a2): + def assertEqualArcs(self, a1, a2, msg=None): """Assert that the arc lists `a1` and `a2` are equal.""" # Make them into multi-line strings so we can see what's going wrong. s1 = "\n".join([repr(a) for a in a1]) + "\n" s2 = "\n".join([repr(a) for a in a2]) + "\n" - self.assertMultiLineEqual(s1, s2) + self.assertMultiLineEqual(s1, s2, msg) def check_coverage(self, text, lines=None, missing="", excludes=None, report="", arcz=None, arcz_missing="", arcz_unpredicted=""): @@ -265,14 +281,20 @@ class CoverageTest(TestCase): ) if arcs is not None: - self.assertEqualArcs(analysis.arc_possibilities(), arcs) + self.assertEqualArcs( + analysis.arc_possibilities(), arcs, "Possible arcs differ" + ) if arcs_missing is not None: - self.assertEqualArcs(analysis.arcs_missing(), arcs_missing) + self.assertEqualArcs( + analysis.arcs_missing(), arcs_missing, + "Missing arcs differ" + ) if arcs_unpredicted is not None: self.assertEqualArcs( - analysis.arcs_unpredicted(), arcs_unpredicted + analysis.arcs_unpredicted(), arcs_unpredicted, + "Unpredicted arcs differ" ) if report: diff --git a/test/test_arcs.py b/test/test_arcs.py index 5698ca5c..41731dba 100644 --- a/test/test_arcs.py +++ b/test/test_arcs.py @@ -28,7 +28,7 @@ class SimpleArcTest(CoverageTest): c = 5 """, - arcz=".2 23 35 5.") + arcz=".2 23 35 5-2") def test_function_def(self): self.check_coverage("""\ @@ -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("""\ @@ -252,7 +258,7 @@ class LoopArcTest(CoverageTest): arcz= ".1 18 8G GH H. " ".2 23 34 43 26 3. 6. " - ".9 9A 9. AB BC CB B9 AE E9", + ".9 9A 9-8 AB BC CB B9 AE E9", arcz_missing="26 6." ) @@ -296,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): @@ -315,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") @@ -442,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") |