diff options
author | Chuck Short <chuck.short@canonical.com> | 2013-05-01 11:22:23 -0500 |
---|---|---|
committer | Chuck Short <chuck.short@canonical.com> | 2013-05-06 15:52:26 -0500 |
commit | fde1e156a38633ce9018569145390bce2047fea8 (patch) | |
tree | ff31b1d70f5e6e35cff4a40101db0ea90ed58bcb /tests/unit/rpc | |
parent | 0c9047cc334578f9f4974c3bc006ba9bc62814d2 (diff) | |
download | oslo-fde1e156a38633ce9018569145390bce2047fea8.tar.gz oslo-fde1e156a38633ce9018569145390bce2047fea8.tar.xz oslo-fde1e156a38633ce9018569145390bce2047fea8.zip |
Convert unicode for python3 portability
From http://docs.python.org/3.1/whatsnew/3.0.html:
"Python 3.0 uses the concepts of text and (binary) data instead of
Unicode strings and 8-bit strings."
Use six.text_type to Type for representing (Unicode) textual data. This
is unicode() in Python 2 and str in Python 3.
Change-Id: I3da268a714a34a8e626a2590f01b86e414dc3411
Signed-off-by: Chuck Short <chuck.short@canonical.com>
Diffstat (limited to 'tests/unit/rpc')
-rw-r--r-- | tests/unit/rpc/test_common.py | 14 | ||||
-rw-r--r-- | tests/unit/rpc/test_kombu.py | 10 | ||||
-rw-r--r-- | tests/unit/rpc/test_proxy.py | 4 |
3 files changed, 18 insertions, 10 deletions
diff --git a/tests/unit/rpc/test_common.py b/tests/unit/rpc/test_common.py index 2248a8f..18951df 100644 --- a/tests/unit/rpc/test_common.py +++ b/tests/unit/rpc/test_common.py @@ -20,6 +20,7 @@ Unit Tests for 'common' functons used through rpc code. import logging import sys +import six from oslo.config import cfg from openstack.common import exception @@ -96,7 +97,8 @@ class RpcCommonTestCase(test_utils.BaseTestCase): after_exc = rpc_common.deserialize_remote_exception(FLAGS, serialized) self.assertTrue(isinstance(after_exc, NotImplementedError)) #assure the traceback was added - self.assertTrue('raise NotImplementedError' in unicode(after_exc)) + self.assertTrue('raise NotImplementedError' in + six.text_type(after_exc)) def test_deserialize_remote_custom_exception(self): failure = { @@ -109,9 +111,9 @@ class RpcCommonTestCase(test_utils.BaseTestCase): after_exc = rpc_common.deserialize_remote_exception(FLAGS, serialized) self.assertTrue(isinstance(after_exc, exception.OpenstackException)) - self.assertTrue('An unknown' in unicode(after_exc)) + self.assertTrue('An unknown' in six.text_type(after_exc)) #assure the traceback was added - self.assertTrue('raise OpenstackException' in unicode(after_exc)) + self.assertTrue('raise OpenstackException' in six.text_type(after_exc)) def test_deserialize_remote_exception_bad_module(self): failure = { @@ -138,7 +140,8 @@ class RpcCommonTestCase(test_utils.BaseTestCase): after_exc = rpc_common.deserialize_remote_exception(FLAGS, serialized) self.assertTrue(isinstance(after_exc, FakeUserDefinedException)) #assure the traceback was added - self.assertTrue('raise FakeUserDefinedException' in unicode(after_exc)) + self.assertTrue('raise FakeUserDefinedException' in + six.text_type(after_exc)) def test_deserialize_remote_exception_args_and_kwargs(self): """ @@ -178,7 +181,8 @@ class RpcCommonTestCase(test_utils.BaseTestCase): after_exc = rpc_common.deserialize_remote_exception(FLAGS, serialized) self.assertTrue(isinstance(after_exc, rpc_common.RemoteError)) #assure the traceback was added - self.assertTrue('raise FakeIDontExistException' in unicode(after_exc)) + self.assertTrue('raise FakeIDontExistException' in + six.text_type(after_exc)) def test_loading_old_nova_config(self): self.config(rpc_backend='nova.rpc.impl_qpid') diff --git a/tests/unit/rpc/test_kombu.py b/tests/unit/rpc/test_kombu.py index ae07bed..73ce2ce 100644 --- a/tests/unit/rpc/test_kombu.py +++ b/tests/unit/rpc/test_kombu.py @@ -26,6 +26,7 @@ import contextlib import logging import mock +import six from oslo.config import cfg from openstack.common import exception @@ -465,9 +466,10 @@ class RpcKombuTestCase(amqp.BaseRpcAMQPTestCase): "args": {"value": value}}) self.fail("should have thrown Exception") except NotImplementedError as exc: - self.assertTrue(value in unicode(exc)) + self.assertTrue(value in six.text_type(exc)) #Traceback should be included in exception message - self.assertTrue('raise NotImplementedError(value)' in unicode(exc)) + self.assertTrue('raise NotImplementedError(value)' in + six.text_type(exc)) def test_call_converted_exception(self): """Test that exception gets passed back properly. @@ -492,9 +494,9 @@ class RpcKombuTestCase(amqp.BaseRpcAMQPTestCase): "args": {"value": value}}) self.fail("should have thrown Exception") except exception.ApiError as exc: - self.assertTrue(value in unicode(exc)) + self.assertTrue(value in six.text_type(exc)) #Traceback should be included in exception message - self.assertTrue('exception.ApiError' in unicode(exc)) + self.assertTrue('exception.ApiError' in six.text_type(exc)) def test_create_worker(self): meth = 'declare_topic_consumer' diff --git a/tests/unit/rpc/test_proxy.py b/tests/unit/rpc/test_proxy.py index fe4bffb..a84a7ea 100644 --- a/tests/unit/rpc/test_proxy.py +++ b/tests/unit/rpc/test_proxy.py @@ -20,6 +20,8 @@ Unit Tests for rpc.proxy import copy +import six + from openstack.common import context from openstack.common import lockutils from openstack.common import rpc @@ -102,7 +104,7 @@ class RpcProxyTestCase(utils.BaseTestCase): self.assertEqual( u'Timeout while waiting on RPC response - ' 'topic: "fake_topic", RPC method: "fake_method" ' - 'info: "The spider got you"', unicode(exc)) + 'info: "The spider got you"', six.text_type(exc)) _check_args(ctxt, topic, expected_msg, timeout=42) self.stubs.Set(rpc, rpc_method, _fake_rpc_method) |