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. --- .pylintrc | 4 ++-- coverage/__init__.py | 12 ++++++++++-- coverage/html.py | 22 ++++++++++++++++------ coverage/misc.py | 1 + coverage/templite.py | 38 +++++++++++++++++++++++++++++++++----- test/coverage_coverage.py | 2 +- test/coveragetest.py | 18 +++++++++++++----- 7 files changed, 76 insertions(+), 21 deletions(-) diff --git a/.pylintrc b/.pylintrc index e7d76c31..834dcc3c 100644 --- a/.pylintrc +++ b/.pylintrc @@ -69,7 +69,7 @@ load-plugins= # Messages that are noisy for now, eventually maybe we'll turn them on: # C0111:169:coverage.analyze_morf: Missing docstring # C0103:256:coverage.morf_filename: Invalid name "f" (should match [a-z_][a-z0-9_]{2,30}$) -disable-msg=I0011,W0122,W0142,W0232,C0323,C0324,W0603, R0201,R0401,W0403,E1103, C0111,C0103 +disable-msg=I0011,W0122,W0142,W0232,C0323,C0324,W0603, R0201,R0401,W0403,E1103, C0103 [REPORTS] @@ -123,7 +123,7 @@ required-attributes= # Regular expression which should only match functions or classes name which do # not require a docstring -no-docstring-rgx=__.*__ +no-docstring-rgx=__.*__|test[A-Z_].*|setUp|tearDown # Regular expression which should only match correct module names module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$ 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