diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2010-06-03 22:27:37 -0400 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2010-06-03 22:27:37 -0400 |
commit | 6d958f8931e0097e56cfd9d95601fc8a68553327 (patch) | |
tree | 594bd5d76ca458ad812e218bc73978c654132b84 /coverage/html.py | |
parent | 934eaa087bc833bbfdc353a038e5ec1ece2376bd (diff) | |
download | python-coveragepy-git-6d958f8931e0097e56cfd9d95601fc8a68553327.tar.gz |
If there are no files to report, show a nice exception rather than fall into a trap trying to subscript integers. Fixes #59.
Diffstat (limited to 'coverage/html.py')
-rw-r--r-- | coverage/html.py | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/coverage/html.py b/coverage/html.py index 80d3615d..fc6d8016 100644 --- a/coverage/html.py +++ b/coverage/html.py @@ -3,6 +3,7 @@ import os, re, shutil from coverage import __url__, __version__ # pylint: disable-msg=W0611 +from coverage.misc import CoverageException from coverage.phystokens import source_token_lines from coverage.report import Reporter from coverage.templite import Templite @@ -45,6 +46,9 @@ class HtmlReporter(Reporter): # Process all the files. self.report_files(self.html_file, morfs, directory, omit, include) + if not self.files: + raise CoverageException("No data to report.") + # Write the index file. self.index_file() @@ -158,7 +162,7 @@ class HtmlReporter(Reporter): # Helpers for templates and generating HTML def escape(t): - """HTML-escape the text in t.""" + """HTML-escape the text in `t`.""" return (t # Convert HTML special chars into HTML entities. .replace("&", "&").replace("<", "<").replace(">", ">") @@ -171,14 +175,14 @@ def escape(t): ) def format_pct(p): - """Format a percentage value for the HTML reports.""" + """Format `p` as a percentage value for the HTML reports.""" return "%.0f" % p def spaceless(html): """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. + Nicely-formatted templates mean lots of extra space in the result. + Get rid of some. """ html = re.sub(">\s+<p ", ">\n<p ", html) |