1. Álvaro Justen - Turicas
  2. coverage.py


Ned Batchelder  committed 99a2574

If there are no files to report, show a nice exception rather than fall into a trap trying to subscript integers. Fixes #59.

  • Participants
  • Parent commits 2ace457
  • Branches default

Comments (0)

Files changed (2)

File CHANGES.txt

View file
 - 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
 .. _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

File coverage/html.py

View file
 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
         # 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.
 # 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("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;")
 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)