Python 3: fix tests/test_utils.py

Only call decode('utf-8') on bytes, not on text strings.

Change-Id: Id856ab4775797d486831f5abb927429b8230c5c1
This commit is contained in:
Cyril Roelandt
2014-01-24 16:38:06 +01:00
parent 02d1339ae7
commit 31695d1eb5

View File

@@ -120,9 +120,19 @@ class PrintTestCase(test_utils.TestCase):
# NOTE(Jeffrey4l) If the text's encode is proper, this method will not # NOTE(Jeffrey4l) If the text's encode is proper, this method will not
# raise UnicodeEncodeError exceptions # raise UnicodeEncodeError exceptions
utils.print_list(objs, ['name']) utils.print_list(objs, ['name'])
self.assertIn(name, self.stdout.getvalue().decode('utf8')) output = self.stdout.getvalue()
# In Python 2, output will be bytes, while in Python 3, it will not.
# Let's decode the value if needed.
if isinstance(output, six.binary_type):
output = output.decode('utf-8')
self.assertIn(name, output)
def test_print_dict_unicode(self): def test_print_dict_unicode(self):
name = u'\u540d\u5b57' name = u'\u540d\u5b57'
utils.print_dict({'name': name}) utils.print_dict({'name': name})
self.assertIn(name, self.stdout.getvalue().decode('utf8')) output = self.stdout.getvalue()
# In Python 2, output will be bytes, while in Python 3, it will not.
# Let's decode the value if needed.
if isinstance(output, six.binary_type):
output = output.decode('utf-8')
self.assertIn(name, output)