From 31695d1eb54242c3a4976a8a7ee15a489e5d0878 Mon Sep 17 00:00:00 2001 From: Cyril Roelandt Date: Fri, 24 Jan 2014 16:38:06 +0100 Subject: [PATCH] Python 3: fix tests/test_utils.py Only call decode('utf-8') on bytes, not on text strings. Change-Id: Id856ab4775797d486831f5abb927429b8230c5c1 --- keystoneclient/tests/test_utils.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/keystoneclient/tests/test_utils.py b/keystoneclient/tests/test_utils.py index f560b3aaf..fe0f90796 100644 --- a/keystoneclient/tests/test_utils.py +++ b/keystoneclient/tests/test_utils.py @@ -120,9 +120,19 @@ class PrintTestCase(test_utils.TestCase): # NOTE(Jeffrey4l) If the text's encode is proper, this method will not # raise UnicodeEncodeError exceptions 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): name = u'\u540d\u5b57' 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)