summaryrefslogtreecommitdiff
path: root/cherrypy/lib/covercp.py
diff options
context:
space:
mode:
authorGustavo Picon <tabo@tabo.pe>2014-01-12 13:57:44 -0500
committerGustavo Picon <tabo@tabo.pe>2014-01-12 13:57:44 -0500
commitc26eb490862e664dc4ef4ea6e55c1dbd106146c4 (patch)
treef997c23aa6d04fc7db78e66ad5f58429b3be824e /cherrypy/lib/covercp.py
parentfb84f7713d6ced0031dacb0e7e59d516cc681a4d (diff)
downloadcherrypy-git-c26eb490862e664dc4ef4ea6e55c1dbd106146c4.tar.gz
Running: autopep8 -vvvvv -i `find . -name '*.py'`
--HG-- branch : autopep8
Diffstat (limited to 'cherrypy/lib/covercp.py')
-rw-r--r--cherrypy/lib/covercp.py25
1 files changed, 17 insertions, 8 deletions
diff --git a/cherrypy/lib/covercp.py b/cherrypy/lib/covercp.py
index 656d99da..83fa69b0 100644
--- a/cherrypy/lib/covercp.py
+++ b/cherrypy/lib/covercp.py
@@ -24,13 +24,15 @@ import re
import sys
import cgi
from cherrypy._cpcompat import quote_plus
-import os, os.path
+import os
+import os.path
localFile = os.path.join(os.path.dirname(__file__), "coverage.cache")
the_coverage = None
try:
from coverage import coverage
the_coverage = coverage(data_file=localFile)
+
def start():
the_coverage.start()
except ImportError:
@@ -39,7 +41,8 @@ except ImportError:
the_coverage = None
import warnings
- warnings.warn("No code coverage will be performed; coverage.py could not be imported.")
+ warnings.warn(
+ "No code coverage will be performed; coverage.py could not be imported.")
def start():
pass
@@ -175,6 +178,7 @@ TEMPLATE_LOC_EXCLUDED = """<tr class="excluded">
TEMPLATE_ITEM = "%s%s<a class='file' href='report?name=%s' target='main'>%s</a>\n"
+
def _percent(statements, missing):
s = len(statements)
e = s - len(missing)
@@ -182,6 +186,7 @@ def _percent(statements, missing):
return int(round(100.0 * e / s))
return 0
+
def _show_branch(root, base, path, pct=0, showpct=False, exclude="",
coverage=the_coverage):
@@ -195,7 +200,7 @@ def _show_branch(root, base, path, pct=0, showpct=False, exclude="",
relpath = newpath[len(base):]
yield "| " * relpath.count(os.sep)
yield "<a class='directory' href='menu?base=%s&exclude=%s'>%s</a>\n" % \
- (newpath, quote_plus(exclude), name)
+ (newpath, quote_plus(exclude), name)
for chunk in _show_branch(root[name], base, newpath, pct, showpct, exclude, coverage=coverage):
yield chunk
@@ -217,7 +222,7 @@ def _show_branch(root, base, path, pct=0, showpct=False, exclude="",
pass
else:
pc = _percent(statements, missing)
- pc_str = ("%3d%% " % pc).replace(' ','&nbsp;')
+ pc_str = ("%3d%% " % pc).replace(' ', '&nbsp;')
if pc < float(pct) or pc == -1:
pc_str = "<span class='fail'>%s</span>" % pc_str
else:
@@ -226,10 +231,12 @@ def _show_branch(root, base, path, pct=0, showpct=False, exclude="",
yield TEMPLATE_ITEM % ("| " * (relpath.count(os.sep) + 1),
pc_str, newpath, name)
+
def _skip_file(path, exclude):
if exclude:
return bool(re.search(exclude, path))
+
def _graft(path, tree):
d = tree
@@ -249,6 +256,7 @@ def _graft(path, tree):
if node:
d = d.setdefault(node, {})
+
def get_tree(base, exclude, coverage=the_coverage):
"""Return covered module names as a nested dict."""
tree = {}
@@ -258,6 +266,7 @@ def get_tree(base, exclude, coverage=the_coverage):
_graft(path, tree)
return tree
+
class CoverStats(object):
def __init__(self, coverage, root=None):
@@ -301,7 +310,7 @@ class CoverStats(object):
yield "<p>No modules covered.</p>"
else:
for chunk in _show_branch(tree, base, "/", pct,
- showpct=='checked', exclude, coverage=self.coverage):
+ showpct == 'checked', exclude, coverage=self.coverage):
yield chunk
yield "</div>"
@@ -331,7 +340,8 @@ class CoverStats(object):
yield template % (lineno, cgi.escape(line))
def report(self, name):
- filename, statements, excluded, missing, _ = self.coverage.analysis2(name)
+ filename, statements, excluded, missing, _ = self.coverage.analysis2(
+ name)
pc = _percent(statements, missing)
yield TEMPLATE_COVERAGE % dict(name=os.path.basename(name),
fullpath=name,
@@ -350,7 +360,7 @@ def serve(path=localFile, port=8080, root=None):
if coverage is None:
raise ImportError("The coverage module could not be imported.")
from coverage import coverage
- cov = coverage(data_file = path)
+ cov = coverage(data_file=path)
cov.load()
import cherrypy
@@ -362,4 +372,3 @@ def serve(path=localFile, port=8080, root=None):
if __name__ == "__main__":
serve(*tuple(sys.argv[1:]))
-