summaryrefslogtreecommitdiff
path: root/coverage/files.py
diff options
context:
space:
mode:
Diffstat (limited to 'coverage/files.py')
-rw-r--r--coverage/files.py23
1 files changed, 14 insertions, 9 deletions
diff --git a/coverage/files.py b/coverage/files.py
index 400646ca..5690679f 100644
--- a/coverage/files.py
+++ b/coverage/files.py
@@ -6,6 +6,7 @@ class FileLocator(object):
"""Understand how filenames work."""
def __init__(self):
+ # The absolute path to our current directory.
self.relative_dir = self.abs_file(os.curdir) + os.sep
# Cache of results of calling the canonical_filename() method, to
@@ -18,18 +19,20 @@ class FileLocator(object):
def relative_filename(self, filename):
"""Return the relative form of `filename`.
-
+
The filename will be relative to the current directory when the
- FileLocator was constructed.
-
+ `FileLocator` was constructed.
+
"""
- return filename.replace(self.relative_dir, "")
+ if filename.startswith(self.relative_dir):
+ filename = filename.replace(self.relative_dir, "")
+ return filename
def canonical_filename(self, filename):
"""Return a canonical filename for `filename`.
-
+
An absolute path with no redundant components and normalized case.
-
+
"""
if filename not in self.canonical_filename_cache:
f = filename
@@ -38,6 +41,8 @@ class FileLocator(object):
f = os.path.basename(f)
if not os.path.isabs(f):
for path in [os.curdir] + sys.path:
+ if path is None:
+ continue
g = os.path.join(path, f)
if os.path.exists(g):
f = g
@@ -48,11 +53,11 @@ class FileLocator(object):
def get_zip_data(self, filename):
"""Get data from `filename` if it is a zip file path.
-
+
Returns the string data read from the zip file, or None if no zip file
could be found or `filename` isn't in it. The data returned will be
an empty string if the file is empty.
-
+
"""
import zipimport
markers = ['.zip'+os.sep, '.egg'+os.sep]
@@ -67,7 +72,7 @@ class FileLocator(object):
data = zi.get_data(parts[1])
except IOError:
continue
- if sys.hexversion > 0x03000000:
+ if sys.version_info >= (3, 0):
data = data.decode('utf8') # TODO: How to do this properly?
return data
return None