diff options
| author | Ned Batchelder <ned@nedbatchelder.com> | 2015-02-19 21:14:55 -0500 |
|---|---|---|
| committer | Ned Batchelder <ned@nedbatchelder.com> | 2015-02-19 21:14:55 -0500 |
| commit | 3e901194d5fa45ede0bf23f20a407f242b6f56d8 (patch) | |
| tree | cf53e7c7a22f0730414a865d6e50fec6e8d4f780 /tests | |
| parent | ba65cc0d4f6e1d6757b2cb3fd43e8f488b68bf7d (diff) | |
| download | python-coveragepy-3e901194d5fa45ede0bf23f20a407f242b6f56d8.tar.gz | |
Don't report negative line numbers through get_line_data
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 cf3d247..0e80f4a 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 42e1051..6f28d05 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]) |
