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

Changeset 551

Show
Ignore:
Timestamp:
08/24/05 01:23:59
Author:
fumanchu
Message:

1. More improvements to coverage browser.
2. Fix for ticket #261 (autoreload failed on file deletions).

Files:

Legend:

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

    r480 r551  
    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 
  • trunk/cherrypy/lib/covercp.py

    r550 r551  
    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> 
     
    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 /> 
     
    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> 
     
    154201</tr>\n""" 
    155202 
    156  
    157 def _skip_file(path, exclude): 
    158     if exclude: 
    159         return bool(re.search(exclude, path)) 
     203TEMPLATE_ITEM = "%s%s<a class='file' href='report?name=%s' target='main'>%s</a>\n" 
    160204 
    161205def _percent(statements, missing): 
     
    166210    return 0 
    167211 
    168 def _show_branch(root, base="", path="", pct=0, showpct=False, exclude=""): 
     212def _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: 
    175             newpath = os.sep.join((path, name)) 
    176         else: 
    177             newpath = name 
     218        newpath = os.path.join(path, name) 
    178219         
    179220        if newpath.startswith(base): 
    180221            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" 
     222            yield "| " * relpath.count(os.sep) 
     223            yield "<a class='directory' href='menu?base=%s&exclude=%s'>%s</a>\n" % \ 
     224                   (newpath, urllib.quote_plus(exclude), name) 
    185225         
    186226        for chunk in _show_branch(root[name], base, newpath, pct, showpct, exclude): 
     
    190230    if path.startswith(base): 
    191231        relpath = path[len(base):] 
    192         files = [k for k, v in root.iteritems() if v is None
     232        files = [k for k, v in root.iteritems() if not v
    193233        files.sort() 
    194234        for name in files: 
    195             if path: 
    196                 newpath = os.sep.join((path, name)) 
    197             else: 
    198                 newpath = name 
     235            newpath = os.path.join(path, name) 
    199236             
    200237            pc_str = "" 
     
    213250                        pc_str = "<span class='pass'>%s</span>" % pc_str 
    214251             
    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)) 
     252            yield TEMPLATE_ITEM % ("| " * (relpath.count(os.sep) + 1), 
     253                                   pc_str, newpath, name) 
     254 
     255def _skip_file(path, exclude): 
     256    if exclude: 
     257        return bool(re.search(exclude, path)) 
     258 
     259def _graft(path, tree): 
     260    d = tree 
     261     
     262    p = path 
     263    atoms = [] 
     264    while True: 
     265        p, tail = os.path.split(p) 
     266        if not tail: 
     267            break 
     268        atoms.append(tail) 
     269    atoms.append(p) 
     270    if p != "/": 
     271        atoms.append("/") 
     272     
     273    atoms.reverse() 
     274    for node in atoms: 
     275        if node: 
     276            d = d.setdefault(node, {}) 
    217277 
    218278def get_tree(base, exclude): 
     
    222282    runs = coverage.cexecuted.keys() 
    223283    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          
    232284        for path in runs: 
    233285            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 
     286                _graft(path, tree) 
     287    print tree 
    237288    return tree 
    238  
    239289 
    240290class CoverStats(object): 
     
    244294    index.exposed = True 
    245295     
    246     def menu(self, base="", pct="50", showpct="", 
     296    def menu(self, base="/", pct="50", showpct="", 
    247297             exclude=r'python\d\.\d|test|tut\d|tutorial'): 
    248298         
     
    253303        yield TEMPLATE_FORM % locals() 
    254304         
    255         yield "<div id='tree'>" 
    256          
    257305        # Start by showing links for parent paths 
     306        yield "<div id='crumbs'>" 
    258307        path = "" 
    259308        atoms = base.split(os.sep) 
     
    261310        for atom in atoms: 
    262311            path += atom + os.sep 
    263             yield ("<nobr><b><a href='menu?base=%s&exclude=%s'>%s</a></b></nobr>%s\n
     312            yield ("<a href='menu?base=%s&exclude=%s'>%s</a> %s
    264313                   % (path, urllib.quote_plus(exclude), atom, os.sep)) 
    265          
     314        yield "</div>" 
     315         
     316        yield "<div id='tree'>" 
     317         
     318        # Then display the tree 
    266319        tree = get_tree(base, exclude) 
    267320        if not tree: 
    268321            yield "<p>No modules covered.</p>" 
    269322        else: 
    270             # Now show all visible branches 
    271             yield "<br />" 
    272             for chunk in _show_branch(tree, base, "", pct, showpct=='checked', exclude): 
     323            for chunk in _show_branch(tree, base, "/", pct, 
     324                                      showpct=='checked', exclude): 
    273325                yield chunk 
    274326         
     
    316368def serve(path=localFile, port=8080): 
    317369    if coverage is None: 
    318         raise ImportError("<p>The coverage module could not be imported.</p>") 
     370        raise ImportError("The coverage module could not be imported.") 
    319371    coverage.cache_default = path 
    320372     
  • trunk/cherrypy/test/test.py

    r533 r551  
    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) 

Hosted by WebFaction

Log in as guest/cpguest to create tickets