Download Install Tutorial Docs FAQ Tools WikiLicense Team IRC Planet Involvement Shop Book

Ticket #262: improve-covercp.patch

  • cherrypy/test/test.py

    old new  
    209209            sys.stdout.write(".") 
    210210            sys.stdout.flush() 
    211211            name = os.path.split(morf)[1] 
     212            if morf.find('test') != -1: 
     213                continue 
    212214            try: 
    213215                _, statements, _, missing, readable  = self.coverage.analysis2(morf) 
    214216                n = len(statements) 
  • cherrypy/lib/autoreload.py

    old new  
    1616        for filename in filter(lambda v: v, map(lambda m: getattr(m, "__file__", None), sys.modules.values())) + reloadFiles: 
    1717            if filename.endswith(".pyc"): 
    1818                filename = filename[:-1] 
    19             mtime = os.stat(filename).st_mtime 
     19            try: 
     20                mtime = os.stat(filename).st_mtime 
     21            except OSError: 
     22                sys.exit(3) # force reload 
    2023            if filename not in mtimes: 
    2124                mtimes[filename] = mtime 
    2225                continue 
  • cherrypy/lib/covercp.py

    old new  
    7777    <title>CherryPy Coverage Menu</title> 
    7878    <style> 
    7979        body {font: 9pt Arial, serif;} 
    80         #tree {font: 8pt Courier, sans-serif;} 
     80        #tree { 
     81            font-size: 8pt; 
     82            font-family: Andale Mono, monospace; 
     83            white-space: pre; 
     84            } 
    8185        #tree a:active, a:focus { 
    82             background-color: #EEEEFF
     86            background-color: black
    8387            padding: 1px; 
    84             border: 1px solid #9999FF; 
     88            color: white; 
     89            border: 0px solid #9999FF; 
    8590            -moz-outline-style: none; 
    86         } 
    87         .fail {color: red;} 
    88         .pass {color: #888;} 
    89         #pct {text-align: right;} 
    90         h3 { font-size: small; font-weight: bold; font-style: italic; margin-top: 5px;} 
     91            } 
     92        .fail { color: red;} 
     93        .pass { color: #888;} 
     94        #pct { text-align: right;} 
     95        h3 { 
     96            font-size: small; 
     97            font-weight: bold; 
     98            font-style: italic; 
     99            margin-top: 5px;  
     100            } 
    91101        input { border: 1px solid #ccc; padding: 2px; } 
     102        .directory { 
     103            color: #933; 
     104            font-style: italic; 
     105            font-weight: bold; 
     106            font-size: 10pt; 
     107            } 
     108        .file { 
     109            color: #400; 
     110            } 
     111        a { text-decoration: none; } 
     112        #crumbs { 
     113            color: white; 
     114            font-size: 8pt; 
     115            font-family: Andale Mono, monospace; 
     116            width: 100%; 
     117            background-color: black; 
     118            } 
     119        #crumbs a { 
     120            color: #f88; 
     121            } 
     122        #options { 
     123            line-height: 2.3em; 
     124            border: 1px solid black; 
     125            background-color: #eee; 
     126            padding: 4px; 
     127            } 
     128        #exclude { 
     129            width: 100%; 
     130            margin-bottom: 3px; 
     131            border: 1px solid #999; 
     132            } 
     133        #submit { 
     134            background-color: black; 
     135            color: white; 
     136            border: 0; 
     137            margin-bottom: -9px; 
     138            } 
    92139    </style> 
    93140</head> 
    94141<body> 
    95142<h2>CherryPy Coverage</h2>""" 
    96143 
    97144TEMPLATE_FORM = """ 
     145<div id="options"> 
    98146<form action='menu' method=GET> 
    99147    <input type='hidden' name='base' value='%(base)s' /> 
    100     <h3>Options</h3> 
    101     <input type='checkbox' %(showpct)s name='showpct' value='checked'/> 
    102     show percentages <br /> 
     148    Show percentages <input type='checkbox' %(showpct)s name='showpct' value='checked'/><br /> 
    103149    Hide files over <input type='text' id='pct' name='pct' value='%(pct)s' size='3' />%%<br /> 
    104150    Exclude files matching<br /> 
    105151    <input type='text' id='exclude' name='exclude' value='%(exclude)s' size='20' /> 
    106152    <br /> 
    107153 
    108     <input type='submit' value='Change view' /> 
    109 </form>"""  
     154    <input type='submit' value='Change view' id="submit"/> 
     155</form> 
     156</div>"""  
    110157 
    111158TEMPLATE_FRAMESET = """<html> 
    112159<head><title>CherryPy coverage data</title></head> 
     
    153200    <td>%s</td> 
    154201</tr>\n""" 
    155202 
     203TEMPLATE_ITEM = "%s%s<a class='file' href='report?name=%s' target='main'>%s</a>\n" 
    156204 
    157 def _skip_file(path, exclude): 
    158     if exclude: 
    159         return bool(re.search(exclude, path)) 
    160  
    161205def _percent(statements, missing): 
    162206    s = len(statements) 
    163207    e = s - len(missing) 
     
    168212def _show_branch(root, base="", path="", pct=0, showpct=False, exclude=""): 
    169213     
    170214    # Show the directory name and any of our children 
    171     dirs = [k for k, v in root.iteritems() if v is not None
     215    dirs = [k for k, v in root.iteritems() if v
    172216    dirs.sort() 
    173217    for name in dirs: 
    174         if path: 
     218        if path == '/': 
     219            newpath = '/' + name 
     220        else: 
    175221            newpath = os.sep.join((path, name)) 
    176         else: 
    177             newpath = name 
    178222         
    179223        if newpath.startswith(base): 
    180224            relpath = newpath[len(base):] 
    181             yield "<nobr>" + ("|&nbsp;" * relpath.count(os.sep)) + "<b>" 
    182             yield ("<a href='menu?base=%s&exclude=%s'>%s</a>" % 
    183                    (newpath, urllib.quote_plus(exclude), name)) 
    184             yield "</b></nobr><br />\n" 
     225            yield "| " * relpath.count(os.sep) 
     226            yield "<a class='directory' href='menu?base=%s&exclude=%s'>%s</a>\n" % \ 
     227                   (newpath, urllib.quote_plus(exclude), name) 
    185228         
    186229        for chunk in _show_branch(root[name], base, newpath, pct, showpct, exclude): 
    187230            yield chunk 
     
    189232    # Now list the files 
    190233    if path.startswith(base): 
    191234        relpath = path[len(base):] 
    192         files = [k for k, v in root.iteritems() if v is None
     235        files = [k for k, v in root.iteritems() if not v
    193236        files.sort() 
    194237        for name in files: 
    195             if path: 
     238            if path == '/': 
     239                newpath = '/' + name 
     240            else: 
    196241                newpath = os.sep.join((path, name)) 
    197             else: 
    198                 newpath = name 
    199242             
    200243            pc_str = "" 
    201244            if showpct: 
     
    212255                    else: 
    213256                        pc_str = "<span class='pass'>%s</span>" % pc_str 
    214257             
    215             yield ("<nobr>%s%s<a href='report?name=%s' target='main'>%s</a></nobr><br />\n" 
    216                    % ("|&nbsp;" * (relpath.count(os.sep) + 1), pc_str, newpath, name)
     258            yield TEMPLATE_ITEM % ("| " * (relpath.count(os.sep) + 1), 
     259                                   pc_str, newpath, name
    217260 
     261def _skip_file(path, exclude): 
     262    if exclude: 
     263        return bool(re.search(exclude, path)) 
     264 
     265def _graft(path, tree): 
     266    d = tree 
     267    for node in path.split(os.sep): 
     268        if node: 
     269            d = d.setdefault(node, {}) 
     270 
    218271def get_tree(base, exclude): 
    219272    """Return covered module names as a nested dict.""" 
    220273    tree = {} 
    221274    coverage.get_ready() 
    222275    runs = coverage.cexecuted.keys() 
    223276    if runs: 
    224         tree = {} 
    225         def graft(path): 
    226             head, tail = os.path.split(path) 
    227             if tail: 
    228                 return graft(head).setdefault(tail, {}) 
    229             else: 
    230                 return tree.setdefault(head.strip(r"\/"), {}) 
    231          
    232277        for path in runs: 
    233278            if not _skip_file(path, exclude) and not os.path.isdir(path): 
    234                 head, tail = os.path.split(path) 
    235                 if head.startswith(base): 
    236                     graft(head)[tail] = None 
     279                _graft(path, tree) 
    237280    return tree 
    238281 
    239  
    240282class CoverStats(object): 
    241283     
    242284    def index(self): 
    243285        return TEMPLATE_FRAMESET 
    244286    index.exposed = True 
    245287     
    246     def menu(self, base="", pct="50", showpct="", 
     288    def menu(self, base="/", pct="50", showpct="", 
    247289             exclude=r'python\d\.\d|test|tut\d|tutorial'): 
    248290         
    249291        # The coverage module uses all-lower-case names. 
     
    252294        yield TEMPLATE_MENU 
    253295        yield TEMPLATE_FORM % locals() 
    254296         
    255         yield "<div id='tree'>" 
    256          
    257297        # Start by showing links for parent paths 
     298        yield "<div id='crumbs'>" 
    258299        path = "" 
    259300        atoms = base.split(os.sep) 
    260301        atoms.pop() 
    261302        for atom in atoms: 
    262303            path += atom + os.sep 
    263             yield ("<nobr><b><a href='menu?base=%s&exclude=%s'>%s</a></b></nobr>%s\n
     304            yield ("<a href='menu?base=%s&exclude=%s'>%s</a> %s
    264305                   % (path, urllib.quote_plus(exclude), atom, os.sep)) 
     306        yield "</div>" 
    265307         
     308        yield "<div id='tree'>" 
     309         
     310        # Then display the tree 
    266311        tree = get_tree(base, exclude) 
    267312        if not tree: 
    268313            yield "<p>No modules covered.</p>" 
    269314        else: 
    270             # Now show all visible branches 
    271             yield "<br />" 
    272             for chunk in _show_branch(tree, base, "", pct, showpct=='checked', exclude): 
     315            for chunk in _show_branch(tree, base, '/', pct, 
     316                                      showpct=='checked', exclude): 
    273317                yield chunk 
    274318         
    275319        yield "</div>" 
     
    315359 
    316360def serve(path=localFile, port=8080): 
    317361    if coverage is None: 
    318         raise ImportError("<p>The coverage module could not be imported.</p>") 
     362        raise ImportError("The coverage module could not be imported.") 
    319363    coverage.cache_default = path 
    320364     
    321365    import cherrypy 
    322366    cherrypy.root = CoverStats() 
    323367    cherrypy.config.update({'server.socketPort': port, 
    324368                            'server.threadPool': 10, 
    325                             'server.environment': "production", 
     369                            'server.environment': "development", 
    326370                            }) 
    327371    cherrypy.server.start() 
    328372 

Hosted by WebFaction

Log in as guest/cpguest to create tickets