diff options
author | Jenkins <jenkins@review.openstack.org> | 2015-06-10 01:02:23 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2015-06-10 01:02:23 +0000 |
commit | d178d641c09e0223e308ca78184bcee729fdec13 (patch) | |
tree | 44b983f99648d44f84e6eddff6f1d5f7eeecd6e0 | |
parent | 5277c93e002047d55c521408ee31da1d03825263 (diff) | |
parent | 22ace8fd78738a33b2e08c47ab37384b90e43de2 (diff) | |
download | glance_store-d178d641c09e0223e308ca78184bcee729fdec13.tar.gz |
Merge "Port exception_to_str() to Python 3"
-rw-r--r-- | glance_store/common/utils.py | 4 | ||||
-rw-r--r-- | tests/unit/test_utils.py | 13 |
2 files changed, 13 insertions, 4 deletions
diff --git a/glance_store/common/utils.py b/glance_store/common/utils.py index 088cef6..d9d64af 100644 --- a/glance_store/common/utils.py +++ b/glance_store/common/utils.py @@ -150,4 +150,6 @@ def exception_to_str(exc): except UnicodeError: error = ("Caught '%(exception)s' exception." % {"exception": exc.__class__.__name__}) - return encodeutils.safe_encode(error, errors='ignore') + if six.PY2: + error = encodeutils.safe_encode(error, errors='ignore') + return error diff --git a/tests/unit/test_utils.py b/tests/unit/test_utils.py index 6bfb089..e3a4042 100644 --- a/tests/unit/test_utils.py +++ b/tests/unit/test_utils.py @@ -14,6 +14,7 @@ # under the License. from oslotest import base +import six from glance_store.common import utils @@ -29,9 +30,15 @@ class TestUtils(base.BaseTestCase): ret = utils.exception_to_str(Exception('error message')) self.assertEqual(ret, 'error message') - ret = utils.exception_to_str(Exception('\xa5 error message')) - self.assertEqual(ret, ' error message') - ret = utils.exception_to_str(FakeException('\xa5 error message')) self.assertEqual(ret, "Caught '%(exception)s' exception." % {'exception': 'FakeException'}) + + def test_exception_to_str_ignore(self): + if six.PY3: + # On Python 3, exception messages are unicode strings, they are not + # decoded from an encoding and so it's not possible to test the + # "ignore" error handler + self.skipTest("test specific to Python 2") + ret = utils.exception_to_str(Exception('\xa5 error message')) + self.assertEqual(ret, ' error message') |