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 | 5fbaec77b7d51612c95d3204f50fd175ebd26bf9 (patch) | |
tree | adafbefa4b685991186f916dec6231d9317d381e | |
parent | 61d2a5b9ef820f80e8cfbd13be302b4cd197fc25 (diff) | |
download | python-coveragepy-5fbaec77b7d51612c95d3204f50fd175ebd26bf9.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.
-rw-r--r-- | CHANGES.txt | 4 | ||||
-rw-r--r-- | coverage/html.py | 12 |
2 files changed, 12 insertions, 4 deletions
diff --git a/CHANGES.txt b/CHANGES.txt index 9792369..b4b2c7b 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -55,6 +55,9 @@ Version 3.4a1 - Unusual code structure that confused exits from methods with exits from classes is now properly analyzed. See `issue 62`_. +- Asking for an HTML report with no files now shows a nice error message rather + than a cryptic failure ('int' object is unsubscriptable). Fixes `issue 59`_. + .. _issue 34: http://bitbucket.org/ned/coveragepy/issue/34/enhanced-omit-globbing-handling .. _issue 36: http://bitbucket.org/ned/coveragepy/issue/36/provide-regex-style-omit .. _issue 46: http://bitbucket.org/ned/coveragepy/issue/46 @@ -63,6 +66,7 @@ Version 3.4a1 .. _issue 56: http://bitbucket.org/ned/coveragepy/issue/56 .. _issue 61: http://bitbucket.org/ned/coveragepy/issue/61/annotate-i-doesnt-work .. _issue 62: http://bitbucket.org/ned/coveragepy/issue/62 +.. _issue 59: http://bitbucket.org/ned/coveragepy/issue/59/html-report-fails-with-int-object-is Version 3.3.1 --- 6 March 2010 diff --git a/coverage/html.py b/coverage/html.py index 80d3615..fc6d801 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) |