summaryrefslogtreecommitdiff
path: root/coverage
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2014-12-13 18:47:18 -0500
committerNed Batchelder <ned@nedbatchelder.com>2014-12-13 18:47:18 -0500
commit70a5b5cde36adbe4002f8e3f73ec0d7af31ea387 (patch)
treef4ae4dbd9b9255e31db90592704d558abe9168c6 /coverage
parent83f2491c839ce73c085ae5e9c4bb8a345cadd5ba (diff)
downloadpython-coveragepy-70a5b5cde36adbe4002f8e3f73ec0d7af31ea387.tar.gz
Zip files always produce bytes, and test that we get them decoded properly.
Diffstat (limited to 'coverage')
-rw-r--r--coverage/codeunit.py5
-rw-r--r--coverage/files.py11
2 files changed, 9 insertions, 7 deletions
diff --git a/coverage/codeunit.py b/coverage/codeunit.py
index f34967e..09b86fe 100644
--- a/coverage/codeunit.py
+++ b/coverage/codeunit.py
@@ -4,7 +4,7 @@ import os
import sys
from coverage.backward import string_class, unicode_class
-from coverage.files import get_python_source, get_zip_data
+from coverage.files import get_python_source, get_zip_bytes
from coverage.misc import CoverageException, NoSource
from coverage.parser import PythonParser
from coverage.phystokens import source_token_lines, source_encoding
@@ -165,6 +165,7 @@ class PythonCodeUnit(CodeUnit):
if sys.version_info < (3, 0):
encoding = source_encoding(self._source)
self._source = self._source.decode(encoding, "replace")
+ assert isinstance(self._source, unicode_class)
return self._source
def get_parser(self, exclude=None):
@@ -206,7 +207,7 @@ class PythonCodeUnit(CodeUnit):
try_filename = base + try_ext
if os.path.exists(try_filename):
return try_filename, None
- source = get_zip_data(try_filename)
+ source = get_zip_bytes(try_filename)
if source:
return try_filename, source
raise NoSource("No source for code: '%s'" % filename)
diff --git a/coverage/files.py b/coverage/files.py
index 1400b6e..c2d7153 100644
--- a/coverage/files.py
+++ b/coverage/files.py
@@ -3,7 +3,7 @@
import fnmatch, os, os.path, re, sys
import ntpath, posixpath
-from coverage.backward import to_string, open_python_source
+from coverage.backward import open_python_source
from coverage.misc import CoverageException, join_regex
@@ -58,7 +58,7 @@ def get_python_source(filename):
return f.read()
# Maybe it's in a zip file?
- source = get_zip_data(filename)
+ source = get_zip_bytes(filename)
if source is not None:
return source
@@ -68,10 +68,10 @@ def get_python_source(filename):
)
-def get_zip_data(filename):
+def get_zip_bytes(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
+ Returns the bytestring 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.
@@ -89,7 +89,8 @@ def get_zip_data(filename):
data = zi.get_data(parts[1])
except IOError:
continue
- return to_string(data)
+ assert isinstance(data, bytes)
+ return data
return None