| 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 | |
|---|
| 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>" + ("| " * 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 |
|---|
| 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 = " " + pc_str |
|---|
| | 165 | if pc < 10: |
|---|
| | 166 | pc_str = " " + 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 | % ("| " * 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>" |
|---|