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 SET_LINENO problem again. This is unfortunate. > But fortunately <wink>, 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.PyCode_Line2Addr.func_code # some code object > >>> codeutil.PyCode_GetExecLines(co) > [20, 21, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36] > >>> codeutil.PyCode_Line2Addr(co, 29) > 173 > >>> codeutil.PyCode_Addr2Line(co, 173) > 29 > >>> codeutil.PyCode_Line2Addr(co, 10) > Traceback (innermost last): > File "<stdin>", line 1, in ? > File "codeutil.py", line 26, in PyCode_Line2Addr > 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/
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4