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
This commit is contained in:
parent
fa22662d2d
commit
d86368c0be
@ -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):
|
||||
|
@ -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)
|
||||
|
@ -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):
|
||||
|
Loading…
x
Reference in New Issue
Block a user