71 """return all of the SET_LINENO information from a code block"""
72 co_code = code.co_code
83 if op == dis.SET_LINENO:
88 del linenos[prev_lineno]
89 prev_lineno = ord(co_code[i+1]) + ord(co_code[i+2])*256
90 linenos[prev_lineno] = 1
91 if op >= dis.HAVE_ARGUMENT:
102 for (o, l)
in dis.findlinestarts (code):
107 if 'SET_LINENO' in dis.__dict__:
108 _find_LINENO_from_code = _find_LINENO_from_code_22
110 _find_LINENO_from_code = _find_LINENO_from_code_23
113 """return all of the SET_LINENO information from a code object"""
121 for c
in code.co_consts:
122 if isinstance(c, types.CodeType):
128 """return a dict of the line numbers from executable statements in a file
130 Works by finding all of the code-like objects in the module then searching
131 the byte code for 'SET_LINENO' terms (so this won't work one -O files).
136 code = compile (prog, filename,
'exec')
146 global running_coverage
152 if 'NOCOVER' not in os.environ:
155 sys.settrace (self.
trace)
195 modulename = frame.f_globals.get (
"__name__")
198 if not (modulename == self.
modname or
199 (modulename ==
'__main__' and
204 lineno = frame.f_lineno
211 elif why ==
'return':
223 filename = sys.modules[self.
modname].__file__
224 if filename[-4:] ==
".pyc" or filename[-4:] ==
".pyo":
225 orig_filename = filename[:-4] +
'.py'
227 orig_filename = filename
231 lines =
open(orig_filename,
'r').readlines()
232 except IOError
as err:
234 "%s: Could not open %s for reading because: %s - skipping\n" %
236 (
"trace",
repr(filename), err.strerror))
241 blank = re.compile(
r'^\s*(#.*)?$')
248 for i
in range(len(lines)):
253 if (i+1)
in lines_hit:
255 prefix =
'%5d: ' % lines_hit[i+1]
256 elif blank.match(line):
264 if (i+1)
in executable_linenos
and \
265 lines[i].
find(
'#pragma: NO COVER') == -1:
267 uncovered = uncovered + 1
270 outlines.append (prefix + line.expandtabs(8))
273 print(
"*** There were %d uncovered lines." % uncovered)
279 listfilename = self.
modname +
".cover"
281 outfile =
open(listfilename,
'w')
282 except IOError
as err:
284 '%s: Could not open %s for writing because: %s - skipping\n' %
285 (
"trace",
repr(listfilename), err.strerror))
304 m = getattr (m, mm[-1])
306 oldrun = doctest.DocTestRunner.run
307 def xrun (xself, *args, **kw):
308 sys.settrace (self.
trace)
309 return oldrun (xself, *args, **kw)
310 doctest.DocTestRunner.run = xrun
313 old_set_continue = bdb.Bdb.set_continue
314 def xcontinue (xself):
315 old_set_continue (xself)
316 sys.settrace (self.
trace)
318 bdb.Bdb.set_continue = xcontinue
320 doctest.testmod (m, *args, **kw)
322 main = sys.modules[
'__main__']
324 doctest.testmod (main, *args, **kw)