[Python-Dev] Line number tools (tests for standard library modules) (original) (raw)

M.-A. Lemburg mal@lemburg.com
Fri, 04 Aug 2000 00:36:33 +0200


Vladimir Marangozov wrote:

Jeremy Hylton wrote: > > Skip's trace.py code coverage tool is now available in Tools/script. > You can use it to examine how much of a particular module is covered > by existing tests. Hmm. Glancing quickly at trace.py, I see that half of it is guessing line numbers. The same SETLINENO problem again. This is unfortunate. But fortunately , here's another piece of code, modeled after its C counterpart, that comes to Skip's rescue and that works with -O. Example: >>> import codeutil >>> co = codeutil.PyCodeLine2Addr.funccode # some code object >>> codeutil.PyCodeGetExecLines(co) [20, 21, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36] >>> codeutil.PyCodeLine2Addr(co, 29) 173 >>> codeutil.PyCodeAddr2Line(co, 173) 29 >>> codeutil.PyCodeLine2Addr(co, 10) Traceback (innermost last): File "", line 1, in ? File "codeutil.py", line 26, in PyCodeLine2Addr raise IndexError, "line must be in range [%d,%d]" % (line, lastlineno) IndexError: line must be in range [20,36] etc...

Cool.

With proper Python style names these utilities would be nice additions for e.g. codeop.py or code.py.

BTW, I wonder why code.py includes Python console emulations: there seems to be a naming bug there... I would have named the module PythonConsole.py and left code.py what it was previously: a collection of tools dealing with Python code objects.

-- Marc-Andre Lemburg


Business: http://www.lemburg.com/ Python Pages: http://www.lemburg.com/python/