diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2012-04-18 07:28:37 -0400 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2012-04-18 07:28:37 -0400 |
commit | 964668c05af407eb95aad0b15e90b29f0ad0c53c (patch) | |
tree | 4d50baaaab4b61f40559a92fcfd29d7b1d9693ab /coverage | |
parent | 5ed649e55e14f7c8cd7a693f3d1fff966283c68d (diff) | |
parent | 67ea897f611a86fee7e3846ad3c4bc564cac6264 (diff) | |
download | python-coveragepy-git-964668c05af407eb95aad0b15e90b29f0ad0c53c.tar.gz |
Automated merge with ssh://bitbucket.org/ned/coveragepy
Diffstat (limited to 'coverage')
-rw-r--r-- | coverage/codeunit.py | 20 | ||||
-rw-r--r-- | coverage/control.py | 8 | ||||
-rw-r--r-- | coverage/report.py | 7 | ||||
-rw-r--r-- | coverage/summary.py | 7 |
4 files changed, 32 insertions, 10 deletions
diff --git a/coverage/codeunit.py b/coverage/codeunit.py index 55f44a24..1999c50c 100644 --- a/coverage/codeunit.py +++ b/coverage/codeunit.py @@ -115,3 +115,23 @@ class CodeUnit(object): raise CoverageException( "No source for code %r." % self.filename ) + + def should_be_python(self): + """Does it seem like this file should contain Python? + + This is used to decide if a file reported as part of the exection of + a program was really likely to have contained Python in the first + place. + + """ + # Get the file extension. + _, ext = os.path.splitext(self.filename) + + # Anything named *.py* should be Python. + if ext.startswith('.py'): + return True + # A file with no extension should be Python. + if not ext: + return True + # Everything else is probably not Python. + return False diff --git a/coverage/control.py b/coverage/control.py index ddeb77c0..eea6b00a 100644 --- a/coverage/control.py +++ b/coverage/control.py @@ -222,14 +222,6 @@ class coverage(object): # can't do anything with the data later anyway. return False - if filename.endswith(".html"): - # Jinja and maybe other templating systems compile templates into - # Python code, but use the template filename as the filename in - # the compiled code. Of course, those filenames are useless later - # so don't bother collecting. TODO: How should we really separate - # out good file extensions from bad? - return False - self._check_for_packages() # Compiled Python files have two filenames: frame.f_code.co_filename is diff --git a/coverage/report.py b/coverage/report.py index 6c5510ad..5d187996 100644 --- a/coverage/report.py +++ b/coverage/report.py @@ -84,6 +84,11 @@ class Reporter(object): for cu in self.code_units: try: report_fn(cu, self.coverage._analyze(cu)) - except (NoSource, NotPython): + except NoSource: if not self.ignore_errors: raise + except NotPython: + # Only report errors for .py files, and only if we didn't + # explicitly suppress those errors. + if cu.should_be_python(".py") and not self.ignore_errors: + raise diff --git a/coverage/summary.py b/coverage/summary.py index 599ae782..dcd5b159 100644 --- a/coverage/summary.py +++ b/coverage/summary.py @@ -4,6 +4,7 @@ import sys from coverage.report import Reporter from coverage.results import Numbers +from coverage.misc import NotPython class SummaryReporter(Reporter): @@ -66,8 +67,12 @@ class SummaryReporter(Reporter): except KeyboardInterrupt: # pragma: no cover raise except: - if not self.ignore_errors: + report_it = not self.ignore_errors + if report_it: typ, msg = sys.exc_info()[:2] + if typ is NotPython and not cu.should_be_python(".py"): + report_it = False + if report_it: outfile.write(fmt_err % (cu.name, typ.__name__, msg)) if total.n_files > 1: |