Definition at line 149 of file coverage.py.
◆ __init__()
def python.coverage.Coverage.__init__ |
( |
|
self, |
|
|
|
modname, |
|
|
|
toplev_name = 'main' |
|
) |
| |
Definition at line 150 of file coverage.py.
150 def __init__(self, modname, toplev_name = 'main'):
151 global running_coverage
153 self.modname = modname
154 self.toplev_name = toplev_name
157 if 'NOCOVER' not in os.environ:
160 sys.settrace (self.trace)
◆ analyze()
def python.coverage.Coverage.analyze |
( |
|
self | ) |
|
Definition at line 227 of file coverage.py.
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*(#.*)?$')
250 lines_hit = self.counts
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))
◆ doctest_cover()
def python.coverage.Coverage.doctest_cover |
( |
|
self, |
|
|
* |
args, |
|
|
** |
kw |
|
) |
| |
Definition at line 301 of file coverage.py.
301 def doctest_cover (self, *args, **kw):
303 m = __import__ (self.modname)
307 mm = self.modname.split (
'.')
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)
◆ trace()
def python.coverage.Coverage.trace |
( |
|
self, |
|
|
|
frame, |
|
|
|
why, |
|
|
|
arg |
|
) |
| |
Definition at line 198 of file coverage.py.
198 def trace(self, frame, why, arg):
200 modulename = frame.f_globals.get (
"__name__")
203 if not (modulename == self.modname
or
204 (modulename ==
'__main__' and
205 frame.f_code.co_name == self.toplev_name)):
208 if modulename == self.modname:
209 lineno = frame.f_lineno
212 if self.mutex: self.mutex.acquire ()
213 self.counts[lineno] = self.counts.
get(lineno, 0) + 1
214 if self.mutex: self.mutex.release ()
216 elif why ==
'return':
217 if frame.f_code.co_name == self.toplev_name:
219 if self.mutex: self.mutex.acquire ()
◆ counts
python.coverage.Coverage.counts |
◆ modname
python.coverage.Coverage.modname |
◆ mutex
python.coverage.Coverage.mutex |
◆ toplev_name
python.coverage.Coverage.toplev_name |
The documentation for this class was generated from the following file: