From 1f7fcec9352691a6e7a90c20e13dc59b65865030 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Sat, 9 May 2009 20:46:58 -0400 Subject: More docstrings all around. --- coverage/__init__.py | 12 ++++++++++-- coverage/html.py | 22 ++++++++++++++++------ coverage/misc.py | 1 + coverage/templite.py | 38 +++++++++++++++++++++++++++++++++----- 4 files changed, 60 insertions(+), 13 deletions(-) (limited to 'coverage') diff --git a/coverage/__init__.py b/coverage/__init__.py index c1b95874..c787b341 100644 --- a/coverage/__init__.py +++ b/coverage/__init__.py @@ -23,12 +23,20 @@ from coverage.misc import CoverageException _the_coverage = None def _singleton_method(name): - def func(*args, **kwargs): + """Return a function to the `name` method on a singleton `coverage` object. + + The singleton object is created the first time one of these functions is + called. + + """ + def wrapper(*args, **kwargs): + """Singleton wrapper around a coverage method.""" global _the_coverage if not _the_coverage: _the_coverage = coverage() return getattr(_the_coverage, name)(*args, **kwargs) - return func + return wrapper + # Define the module-level functions. use_cache = _singleton_method('use_cache') diff --git a/coverage/html.py b/coverage/html.py index 6fc49ff5..d8f98c45 100644 --- a/coverage/html.py +++ b/coverage/html.py @@ -16,9 +16,7 @@ def data(fname): class HtmlReporter(Reporter): - """HTML reporting. - - """ + """HTML reporting.""" def __init__(self, coverage, ignore_errors=False): super(HtmlReporter, self).__init__(coverage, ignore_errors) @@ -27,7 +25,14 @@ class HtmlReporter(Reporter): self.files = [] - def report(self, morfs, directory=None, omit_prefixes=None): + def report(self, morfs, directory, omit_prefixes=None): + """Generate an HTML report for `morfs`. + + `morfs` is a list of modules or filenames. `directory` is where to put + the HTML files. `omit_prefixes` is a list of strings, prefixes of + modules to omit from the report. + + """ assert directory, "must provide a directory for html reporting" # Process all the files. @@ -147,10 +152,15 @@ def not_empty(t): return t or " " def format_pct(p): + """Format a percentage value for the HTML reports.""" return "%.0f" % p def spaceless(html): - """Squeeze out some of that annoying extra space that comes from - nicely-formatted templates.""" + """Squeeze out some annoying extra space from an HTML string. + + Nicely-formatted templates mean lots of extra space in the result. Get + rid of some. + + """ html = re.sub(">\s+

\n