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
commit756894693bb22ffb7213b4a60e850522ae2560eb (patch)
tree52cbb12fefc036c4fa0c536996175db456b0aeb3 /coverage/control.py
parentbd6779fe14f753e9062d20235d595762e7afd8b2 (diff)
downloadpython-coveragepy-756894693bb22ffb7213b4a60e850522ae2560eb.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 63c9d38..1044fad 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):