Py3k compliance: check for bytes when making a string

When faking stdout in tests we must account for the case when
"strings" might be bytes, which python3 cares about.

Change-Id: I0e9349c86371055eed479799d39ab6adbcad6f95
Closes-Bug: #1499004
This commit is contained in:
Henry Gessau 2015-09-23 13:31:50 -04:00
parent 3e115991c1
commit fcf289797c
1 changed files with 6 additions and 0 deletions

View File

@ -73,6 +73,12 @@ class FakeStdout(object):
def make_string(self):
result = ''
for line in self.content:
if six.PY3:
if isinstance(line, bytes):
try:
line = line.decode(encoding='utf-8')
except UnicodeError:
pass
result = result + line
return result