diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2012-04-18 07:27:59 -0400 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2012-04-18 07:27:59 -0400 |
commit | 42f5efa9bc9e5ec2fd02f9cf6b95541a93fca632 (patch) | |
tree | 28baf3d41e7a89c1082a9b6e9138474a50a0124e /coverage/codeunit.py | |
parent | ac8cf1852de2837234dab8cc823127e70c48e55e (diff) | |
download | python-coveragepy-42f5efa9bc9e5ec2fd02f9cf6b95541a93fca632.tar.gz |
Don't complain about files that can't be parsed as Python if they didn't seem like Python at all. #82.
Diffstat (limited to 'coverage/codeunit.py')
-rw-r--r-- | coverage/codeunit.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/coverage/codeunit.py b/coverage/codeunit.py index 55f44a2..1999c50 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 |