diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/coveragetest.py | 4 | ||||
-rw-r--r-- | tests/test_arcs.py | 24 |
2 files changed, 28 insertions, 0 deletions
diff --git a/tests/coveragetest.py b/tests/coveragetest.py index cf3d2474..0e80f4a9 100644 --- a/tests/coveragetest.py +++ b/tests/coveragetest.py @@ -166,6 +166,8 @@ class CoverageTest( `arcs_unpredicted` are the arcs executed in the code, but not deducible from the code. + Returns the Coverage object, in case you want to poke at it some more. + """ # We write the code into a file so that we can import it. # Coverage wants to deal with things as modules with file names. @@ -248,6 +250,8 @@ class CoverageTest( rep = " ".join(frep.getvalue().split("\n")[2].split()[1:]) self.assertEqual(report, rep) + return cov + def nice_file(self, *fparts): """Canonicalize the filename composed of the parts in `fparts`.""" fname = os.path.join(*fparts) diff --git a/tests/test_arcs.py b/tests/test_arcs.py index 42e10510..6f28d05e 100644 --- a/tests/test_arcs.py +++ b/tests/test_arcs.py @@ -1,7 +1,10 @@ """Tests for Coverage.py's arc measurement.""" +import os.path + from tests.coveragetest import CoverageTest +import coverage from coverage import env @@ -627,3 +630,24 @@ class ExcludeTest(CoverageTest): [1,2,3,4,5], partials=["only some"], arcz=".1 12 23 34 45 25 5.", arcz_missing="") + + +class LineDataTest(CoverageTest): + """Tests that line_data gives us what we expect.""" + + def test_branch(self): + cov = coverage.Coverage(branch=True) + + self.make_file("fun1.py", """\ + def fun1(x): + if x == 1: + return + + fun1(3) + """) + + self.start_import_stop(cov, "fun1") + + cov._harvest_data() + fun1_lines = cov.data.line_data()[os.path.abspath("fun1.py")] + self.assertEqual(fun1_lines, [1, 2, 5]) |