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

Changeset 543

Show
Ignore:
Timestamp:
08/18/05 21:18:17
Author:
fumanchu
Message:

Prettier covercp report output (tree format plus percents).

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/cherrypy/lib/covercp.py

    r542 r543  
    4242""" 
    4343 
    44  
     44import re 
    4545import sys 
    4646import os, os.path 
     
    7474        return """<html> 
    7575        <head><title>CherryPy coverage data</title></head> 
    76         <frameset cols='200, 1*'> 
     76        <frameset cols='250, 1*'> 
    7777            <frame src='menu' /> 
    7878            <frame name='main' src='' /> 
     
    8282    index.exposed = True 
    8383     
    84     def menu(self): 
    85         yield "<h2>CherryPy Coverage</h2>" 
    86         yield "<p>Click on one of the modules below to see coverage analysis.</p>" 
     84    def menu(self, base="", pct=""): 
     85        yield """<html> 
     86<head> 
     87    <title>CherryPy Coverage Menu</title> 
     88    <style> 
     89        body {font: 9pt Arial, serif;} 
     90        #tree {font: 8pt Courier, sans-serif;} 
     91        #tree a:active, a:focus { 
     92            background-color: #EEEEFF; 
     93            padding: 1px; 
     94            border: 1px solid #9999FF; 
     95            -moz-outline-style: none; 
     96        } 
     97        .fail {color: red;} 
     98        #pct {text-align: right;} 
     99    </style> 
     100</head> 
     101<body> 
     102<h2>CherryPy Coverage</h2>""" 
     103         
    87104        coverage.get_ready() 
    88         runs = [os.path.split(x) for x in coverage.cexecuted.keys()] 
    89         runs.sort() 
     105        runs = coverage.cexecuted.keys() 
    90106        if runs: 
    91             base = "" 
    92             for newbase, fname in runs: 
    93                 # Make each directory a new section with a header 
    94                 if base != newbase: 
    95                     base = newbase 
    96                     yield "<h3>%s</h3>\n" % newbase 
     107            yield """<form action='menu'> 
     108    <input type='hidden' name='base' value='%s' /> 
     109    <input type='submit' value='Show %%' /> 
     110    threshold: <input type='text' id='pct' name='pct' value='%s' size='3' />%% 
     111</form>""" % (base, pct or "50") 
     112             
     113            yield "<div id='tree'>" 
     114            tree = {} 
     115            def graft(path): 
     116                b, n = os.path.split(path) 
     117                if n: 
     118                    return graft(b).setdefault(n, {}) 
     119                else: 
     120                    return tree.setdefault(b.strip(r"\/"), {}) 
     121            for path in runs: 
     122                if not os.path.isdir(path): 
     123                    b, n = os.path.split(path) 
     124                    if b.startswith(base): 
     125                        graft(b)[n] = None 
     126             
     127            def show(root, depth=0, path=""): 
     128                dirs = [k for k, v in root.iteritems() if v is not None] 
     129                dirs.sort() 
     130                for name in dirs: 
     131                    if path: 
     132                        newpath = os.sep.join((path, name)) 
     133                    else: 
     134                        newpath = name 
     135                     
     136                    yield "<nobr>" + ("|&nbsp;" * depth) + "<b>" 
     137                    yield "<a href='menu?base=%s'>%s</a>" % (newpath, name) 
     138                    yield "</b></nobr><br />\n" 
     139                    for chunk in show(root[name], depth + 1, newpath): 
     140                        yield chunk 
    97141                 
    98                 # Yield a link to each annotated file. 
    99                 yield ("<a href='report?name=%s' target='main'>%s</a><br />\n" 
    100                        % (os.path.join(newbase, fname), fname)) 
     142                files = [k for k, v in root.iteritems() if v is None] 
     143                files.sort() 
     144                for name in files: 
     145                    if path: 
     146                        newpath = os.sep.join((path, name)) 
     147                    else: 
     148                        newpath = name 
     149                     
     150                    pc_str = "" 
     151                    if pct: 
     152                        try: 
     153                            _, statements, _, missing, _ = coverage.analysis2(newpath) 
     154                        except: 
     155                            # Yes, we really want to pass on all errors. 
     156                            pass 
     157                        else: 
     158                            s = len(statements) 
     159                            e = s - len(missing) 
     160                            if s > 0: 
     161                                pc = 100.0 * e / s 
     162                                pc_str = "%d%% " % pc 
     163                                if pc < 100: 
     164                                    pc_str = "&nbsp;" + pc_str 
     165                                    if pc < 10: 
     166                                        pc_str = "&nbsp;" + pc_str 
     167                                if pc < float(pct): 
     168                                    pc_str = "<span class='fail'>%s</span>" % pc_str 
     169                    yield ("<nobr>%s%s<a href='report?name=%s' target='main'>%s</a></nobr><br />\n" 
     170                           % ("|&nbsp;" * depth, pc_str, newpath, name)) 
     171             
     172            for chunk in show(tree): 
     173                yield chunk 
     174             
     175            yield "</div>" 
     176        else: 
     177            yield "<p>No modules covered.</p>" 
     178        yield "</body></html>" 
    101179    menu.exposed = True 
    102180     

Hosted by WebFaction

Log in as guest/cpguest to create tickets