<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
This is very interesting work, and I'm excited to see where it could
lead.<br>
<br>
For the sake of completeness, as I'm sure many on the list already know
this: coverage.py now measures branch coverage, at least in a
line-oriented way. It does it by recording not just which lines were
executed, but pairs of lines to know which line followed which in the
execution.<br>
<br>
--Ned.<br>
<br>
Andrew Dalke wrote:
<blockquote
 cite="mid:DECB0787-A497-43FB-8F5C-AA5A442A4FE3@dalkescientific.com"
 type="cite">
  <pre wrap="">On Jan 24, 2008, at 8:41 AM, Andrew Dalke wrote:
  </pre>
  <blockquote type="cite">
    <pre wrap="">I was talking with Laura a few days ago about a lightning talk I wanted to present at PyCon - branch coverage.  There's no easy way to do it with Python.  The closest is to use the compiler module to generate the AST then instrument the AST.  The problem is, the compiler module is a bear to work with and doesn't record everything I want.  For example, in the coverage report I want to see which branches weren't covered, pinpointed to the character range of the expression.  Python's AST doesn't have byte positions.
    </pre>
  </blockquote>
  <pre wrap=""><!---->
I presented this work at the TiP BoF at PyCon 2010 last week. (Enough acronyms for you there?) It only took a bit over two years to actually do it.

 <a class="moz-txt-link-freetext" href="http://www.dalkescientific.com/writings/diary/archive/2010/02/22/instrumenting_the_ast.html">http://www.dalkescientific.com/writings/diary/archive/2010/02/22/instrumenting_the_ast.html</a>

During that time, Python 2.6 was released with a public ast.py module with writeable AST nodes. That made AST instrumentation possible without having to use something like my python4ply module. (Which is still useful for things like supporting Python 2.7 syntax under Python 2.6, but it would involve a lot of work to strip out the python4ply's use of the old compiler module with the ast module.)

The presentation I did was a proof-of-concept prototype I put together on Friday afternoon through Saturday evening, but based directly on the things I wanted to do two years ago. In it I go through an example of how to add one sort of line coverage, which includes coverage for multiple statements on a single line, as well as how to add tests for an error which isn't otherwise easily tested.


                                Andrew
                                <a class="moz-txt-link-abbreviated" href="mailto:dalke@dalkescientific.com">dalke@dalkescientific.com</a>



_______________________________________________
testing-in-python mailing list
<a class="moz-txt-link-abbreviated" href="mailto:testing-in-python@lists.idyll.org">testing-in-python@lists.idyll.org</a>
<a class="moz-txt-link-freetext" href="http://lists.idyll.org/listinfo/testing-in-python">http://lists.idyll.org/listinfo/testing-in-python</a>

  </pre>
</blockquote>
</body>
</html>