From d86368c0be1fefdd44b09977598090070c57a138 Mon Sep 17 00:00:00 2001 From: Ivan Kolodyazhny Date: Thu, 2 Apr 2015 18:10:21 +0300 Subject: [PATCH] Use six.text_type instead of unicode unicode type renamed in Python 3.x. We need to use six.text_type to get code works with both Python 2.7 and 3.x Related-Bug: #1380806 Change-Id: Ia26a29fab377b61ce4abf81f3eb778988eb8b893 --- os_brick/exception.py | 4 +++- os_brick/tests/initiator/test_connector.py | 3 ++- os_brick/tests/test_exception.py | 12 ++++++++---- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/os_brick/exception.py b/os_brick/exception.py index 5f1db5286..14d76dc74 100644 --- a/os_brick/exception.py +++ b/os_brick/exception.py @@ -14,6 +14,8 @@ """Exceptions for the Brick library.""" +import six + from os_brick.i18n import _, _LE from os_brick.openstack.common import log as logging @@ -64,7 +66,7 @@ class BrickException(Exception): super(BrickException, self).__init__(message) def __unicode__(self): - return unicode(self.msg) + return six.text_type(self.msg) class NotFound(BrickException): diff --git a/os_brick/tests/initiator/test_connector.py b/os_brick/tests/initiator/test_connector.py index debd6da28..7d00ee7bf 100644 --- a/os_brick/tests/initiator/test_connector.py +++ b/os_brick/tests/initiator/test_connector.py @@ -20,6 +20,7 @@ import time import mock from oslo_concurrency import processutils as putils +import six import testtools from os_brick import exception @@ -722,7 +723,7 @@ class FibreChannelConnectorTestCase(ConnectorTestCase): name = 'volume-00000001' vol = {'id': 1, 'name': name} # Should work for string, unicode, and list - wwns = ['1234567890123456', unicode('1234567890123456'), + wwns = ['1234567890123456', six.text_type('1234567890123456'), ['1234567890123456', '1234567890123457']] for wwn in wwns: connection_info = self.fibrechan_connection(vol, location, wwn) diff --git a/os_brick/tests/test_exception.py b/os_brick/tests/test_exception.py index fac416a36..8f5d9ce14 100644 --- a/os_brick/tests/test_exception.py +++ b/os_brick/tests/test_exception.py @@ -15,6 +15,8 @@ # License for the specific language governing permissions and limitations # under the License. +import six + from os_brick import exception from os_brick.tests import base @@ -25,24 +27,26 @@ class BrickExceptionTestCase(base.TestCase): message = "default message" exc = FakeBrickException() - self.assertEqual(unicode(exc), 'default message') + self.assertEqual(six.text_type(exc), 'default message') def test_error_msg(self): - self.assertEqual(unicode(exception.BrickException('test')), 'test') + self.assertEqual(six.text_type(exception.BrickException('test')), + 'test') def test_default_error_msg_with_kwargs(self): class FakeBrickException(exception.BrickException): message = "default message: %(code)s" exc = FakeBrickException(code=500) - self.assertEqual(unicode(exc), 'default message: 500') + self.assertEqual(six.text_type(exc), 'default message: 500') def test_error_msg_exception_with_kwargs(self): class FakeBrickException(exception.BrickException): message = "default message: %(mispelled_code)s" exc = FakeBrickException(code=500) - self.assertEqual(unicode(exc), 'default message: %(mispelled_code)s') + self.assertEqual(six.text_type(exc), + 'default message: %(mispelled_code)s') def test_default_error_code(self): class FakeBrickException(exception.BrickException):