summaryrefslogtreecommitdiff
path: root/coverage/control.py
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2015-01-17 16:44:34 -0500
committerNed Batchelder <ned@nedbatchelder.com>2015-01-17 16:44:34 -0500
commita7fc111387f1f782f3404a21c103cac4812f9e74 (patch)
treef8ee2033ab7d6227cb4e42512461aa904b8ab836 /coverage/control.py
parenta13742532a3a283f2e690256d38fe5c9ffcf2049 (diff)
downloadpython-coveragepy-git-a7fc111387f1f782f3404a21c103cac4812f9e74.tar.gz
When finding the source for a frame, really check if it exists
Diffstat (limited to 'coverage/control.py')
-rw-r--r--coverage/control.py17
1 files changed, 12 insertions, 5 deletions
diff --git a/coverage/control.py b/coverage/control.py
index 63c9d382..1044fad0 100644
--- a/coverage/control.py
+++ b/coverage/control.py
@@ -308,11 +308,18 @@ class Coverage(object):
def _source_for_file(self, filename):
"""Return the source file for `filename`."""
- if not filename.endswith(".py"):
- if filename[-4:-1] == ".py":
- filename = filename[:-1]
- elif filename.endswith("$py.class"): # jython
- filename = filename[:-9] + ".py"
+ if filename.endswith(".py"):
+ return filename
+ elif filename.endswith((".pyc", ".pyo")):
+ try_filename = filename[:-1]
+ if os.path.exists(try_filename):
+ return try_filename
+ if sys.platform == "win32":
+ try_filename += "w"
+ if os.path.exists(try_filename):
+ return try_filename
+ elif filename.endswith("$py.class"): # Jython
+ filename = filename[:-9] + ".py"
return filename
def _name_for_module(self, module_globals, filename):