59 from __future__
import print_function
76 """return all of the SET_LINENO information from a code block"""
77 co_code = code.co_code
88 if op == dis.SET_LINENO:
93 del linenos[prev_lineno]
94 prev_lineno = ord(co_code[i+1]) + ord(co_code[i+2])*256
95 linenos[prev_lineno] = 1
96 if op >= dis.HAVE_ARGUMENT:
107 for (o, l)
in dis.findlinestarts (code):
112 if 'SET_LINENO' in dis.__dict__:
113 _find_LINENO_from_code = _find_LINENO_from_code_22
115 _find_LINENO_from_code = _find_LINENO_from_code_23
118 """return all of the SET_LINENO information from a code object"""
126 for c
in code.co_consts:
127 if isinstance(c, types.CodeType):
133 """return a dict of the line numbers from executable statements in a file
135 Works by finding all of the code-like objects in the module then searching
136 the byte code for 'SET_LINENO' terms (so this won't work one -O files).
141 code = compile (prog, filename,
'exec')
151 global running_coverage
157 if 'NOCOVER' not in os.environ:
160 sys.settrace (self.
trace)
200 modulename = frame.f_globals.get (
"__name__")
203 if not (modulename == self.
modname or
204 (modulename ==
'__main__' and
209 lineno = frame.f_lineno
216 elif why ==
'return':
228 filename = sys.modules[self.
modname].__file__
229 if filename[-4:] ==
".pyc" or filename[-4:] ==
".pyo":
230 orig_filename = filename[:-4] +
'.py'
232 orig_filename = filename
236 lines =
open(orig_filename,
'r').readlines()
237 except IOError
as err:
239 "%s: Could not open %s for reading because: %s - skipping\n" %
241 (
"trace",
repr(filename), err.strerror))
246 blank = re.compile(
r'^\s*(#.*)?$')
253 for i
in range(len(lines)):
258 if (i+1)
in lines_hit:
260 prefix =
'%5d: ' % lines_hit[i+1]
261 elif blank.match(line):
269 if (i+1)
in executable_linenos
and \
270 lines[i].
find(
'#pragma: NO COVER') == -1:
272 uncovered = uncovered + 1
275 outlines.append (prefix + line.expandtabs(8))
278 print(
"*** There were %d uncovered lines." % uncovered)
284 listfilename = self.
modname +
".cover"
286 outfile =
open(listfilename,
'w')
287 except IOError
as err:
289 '%s: Could not open %s for writing because: %s - skipping\n' %
290 (
"trace",
repr(listfilename), err.strerror))
309 m = getattr (m, mm[-1])
311 oldrun = doctest.DocTestRunner.run
312 def xrun (xself, *args, **kw):
313 sys.settrace (self.
trace)
314 return oldrun (xself, *args, **kw)
315 doctest.DocTestRunner.run = xrun
318 old_set_continue = bdb.Bdb.set_continue
319 def xcontinue (xself):
320 old_set_continue (xself)
321 sys.settrace (self.
trace)
323 bdb.Bdb.set_continue = xcontinue
325 doctest.testmod (m, *args, **kw)
327 main = sys.modules[
'__main__']
329 doctest.testmod (main, *args, **kw)