diff options
-rw-r--r-- | coverage/files.py | 5 | ||||
-rw-r--r-- | coverage/python.py | 6 |
2 files changed, 4 insertions, 7 deletions
diff --git a/coverage/files.py b/coverage/files.py index 855d8157..44997d12 100644 --- a/coverage/files.py +++ b/coverage/files.py @@ -67,8 +67,6 @@ def canonical_filename(filename): filename = f break cf = abs_file(filename) - if env.PY2 and isinstance(cf, str): - cf = cf.decode(sys.getfilesystemencoding()) CANONICAL_FILENAME_CACHE[filename] = cf return CANONICAL_FILENAME_CACHE[filename] @@ -135,7 +133,8 @@ if env.PY2: def unicode_filename(filename): """Return a Unicode version of `filename`.""" if isinstance(filename, str): - filename = filename.decode(sys.getfilesystemencoding()) + encoding = sys.getfilesystemencoding() or sys.getdefaultencoding() + filename = filename.decode(encoding, "replace") return filename else: @contract(filename='unicode', returns='unicode') diff --git a/coverage/python.py b/coverage/python.py index fe32150a..a4247ce6 100644 --- a/coverage/python.py +++ b/coverage/python.py @@ -96,8 +96,7 @@ class PythonFileReporter(FileReporter): else: filename = morf - if env.PY2 and isinstance(filename, str): - filename = filename.decode(sys.getfilesystemencoding()) + filename = files.unicode_filename(filename) # .pyc files should always refer to a .py instead. if filename.endswith(('.pyc', '.pyo')): @@ -110,8 +109,7 @@ class PythonFileReporter(FileReporter): if hasattr(morf, '__name__'): name = morf.__name__ name = name.replace(".", os.sep) + ".py" - if isinstance(name, bytes): - name = name.decode(sys.getfilesystemencoding()) + name = files.unicode_filename(name) else: name = files.relative_filename(filename) self.relname = name |