Package cherrypy :: Package lib :: Module covercp
[hide private]
[frames] | no frames]

Module covercp

source code

Code-coverage tools for CherryPy.

To use this module, or the coverage tools in the test suite, you need to download 'coverage.py', either Gareth Rees' `original implementation <http://www.garethrees.org/2001/12/04/python-coverage/>`_ or Ned Batchelder's `enhanced version: <http://www.nedbatchelder.com/code/modules/coverage.html>`_

To turn on coverage tracing, use the following code:

   cherrypy.engine.subscribe('start', covercp.start)

DO NOT subscribe anything on the 'start_thread' channel, as previously recommended. Calling start once in the main thread should be sufficient to start coverage on all threads. Calling start again in each thread effectively clears any coverage data gathered up to that point.

Run your code, then use the ``covercp.serve()`` function to browse the results in a web browser. If you run this module from the command line, it will call ``serve()`` for you.

Classes [hide private]
  CoverStats
Functions [hide private]
 
start() source code
 
_percent(statements, missing) source code
 
_show_branch(root, base, path, pct=0, showpct=False, exclude='', coverage=None) source code
 
_skip_file(path, exclude) source code
 
_graft(path, tree) source code
 
get_tree(base, exclude, coverage=None)
Return covered module names as a nested dict.
source code
 
serve(path='/build/buildd/cherrypy3-3.2.2/cherrypy/lib/coverage.cache', port=8080, root=None) source code
Variables [hide private]
  localFile = '/build/buildd/cherrypy3-3.2.2/cherrypy/lib/covera...
  the_coverage = None
hash(x)
  TEMPLATE_MENU = '<html>\n<head>\n <title>CherryPy Coverage ...
  TEMPLATE_FORM = '\n<div id="options">\n<form action=\'menu\' m...
  TEMPLATE_FRAMESET = '<html>\n<head><title>CherryPy coverage da...
  TEMPLATE_COVERAGE = '<html>\n<head>\n <title>Coverage for %...
  TEMPLATE_LOC_COVERED = '<tr class="covered">\n <td class="l...
  TEMPLATE_LOC_NOT_COVERED = '<tr class="notcovered">\n <td c...
  TEMPLATE_LOC_EXCLUDED = '<tr class="excluded">\n <td class=...
  TEMPLATE_ITEM = '%s%s<a class=\'file\' href=\'report?name=%s\'...
  __package__ = 'cherrypy.lib'
  __warningregistry__ = {('No code coverage will be performed; c...
Variables Details [hide private]

localFile

Value:
'/build/buildd/cherrypy3-3.2.2/cherrypy/lib/coverage.cache'

TEMPLATE_MENU

Value:
'''<html>
<head>
    <title>CherryPy Coverage Menu</title>
    <style>
        body {font: 9pt Arial, serif;}
        #tree {
            font-size: 8pt;
            font-family: Andale Mono, monospace;
...

TEMPLATE_FORM

Value:
'''
<div id="options">
<form action=\'menu\' method=GET>
    <input type=\'hidden\' name=\'base\' value=\'%(base)s\' />
    Show percentages <input type=\'checkbox\' %(showpct)s name=\'showp\
ct\' value=\'checked\' /><br />
    Hide files over <input type=\'text\' id=\'pct\' name=\'pct\' value\
=\'%(pct)s\' size=\'3\' />%%<br />
...

TEMPLATE_FRAMESET

Value:
'''<html>
<head><title>CherryPy coverage data</title></head>
<frameset cols=\'250, 1*\'>
    <frame src=\'menu?base=%s\' />
    <frame name=\'main\' src=\'\' />
</frameset>
</html>
'''

TEMPLATE_COVERAGE

Value:
'''<html>
<head>
    <title>Coverage for %(name)s</title>
    <style>
        h2 { margin-bottom: .25em; }
        p { margin: .25em; }
        .covered { color: #000; background-color: #fff; }
        .notcovered { color: #fee; background-color: #500; }
...

TEMPLATE_LOC_COVERED

Value:
'''<tr class="covered">
    <td class="lineno">%s&nbsp;</td>
    <td>%s</td>
</tr>
'''

TEMPLATE_LOC_NOT_COVERED

Value:
'''<tr class="notcovered">
    <td class="lineno">%s&nbsp;</td>
    <td>%s</td>
</tr>
'''

TEMPLATE_LOC_EXCLUDED

Value:
'''<tr class="excluded">
    <td class="lineno">%s&nbsp;</td>
    <td>%s</td>
</tr>
'''

TEMPLATE_ITEM

Value:
'''%s%s<a class=\'file\' href=\'report?name=%s\' target=\'main\'>%s</a\
>
'''

__warningregistry__

Value:
{('No code coverage will be performed; coverage.py could not be import\
ed.',
  <type 'exceptions.UserWarning'>,
  42): True}