summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2013-07-23 13:28:25 +0000
committerGerrit Code Review <review@openstack.org>2013-07-23 13:28:25 +0000
commit53bd102c75ee5040323b47e14ad9b3faae6db6eb (patch)
tree27c41112013a57e38b78e0c1a90585e5d7216f7e
parent9a0eea8749aecff040b2be446a80c53013dc6602 (diff)
parent9a3ebf2ff5b995085d0fb8e075687b48681d391f (diff)
Merge "Avoid shadowing Exception 'message' attribute"
-rw-r--r--openstack/common/exception.py22
-rw-r--r--tests/unit/rpc/test_common.py12
-rw-r--r--tests/unit/test_exception.py14
3 files changed, 24 insertions, 24 deletions
diff --git a/openstack/common/exception.py b/openstack/common/exception.py
index fdf17b2..2a9a751 100644
--- a/openstack/common/exception.py
+++ b/openstack/common/exception.py
@@ -33,7 +33,7 @@ class Error(Exception):
class ApiError(Error):
def __init__(self, message='Unknown', code='Unknown'):
- self.message = message
+ self.api_message = message
self.code = code
super(ApiError, self).__init__('%s: %s' % (code, message))
@@ -44,19 +44,19 @@ class NotFound(Error):
class UnknownScheme(Error):
- msg = "Unknown scheme '%s' found in URI"
+ msg_fmt = "Unknown scheme '%s' found in URI"
def __init__(self, scheme):
- msg = self.__class__.msg % scheme
+ msg = self.__class__.msg_fmt % scheme
super(UnknownScheme, self).__init__(msg)
class BadStoreUri(Error):
- msg = "The Store URI %s was malformed. Reason: %s"
+ msg_fmt = "The Store URI %s was malformed. Reason: %s"
def __init__(self, uri, reason):
- msg = self.__class__.msg % (uri, reason)
+ msg = self.__class__.msg_fmt % (uri, reason)
super(BadStoreUri, self).__init__(msg)
@@ -113,29 +113,29 @@ class OpenstackException(Exception):
"""Base Exception class.
To correctly use this class, inherit from it and define
- a 'message' property. That message will get printf'd
+ a 'msg_fmt' property. That message will get printf'd
with the keyword arguments provided to the constructor.
"""
- message = "An unknown exception occurred"
+ msg_fmt = "An unknown exception occurred"
def __init__(self, **kwargs):
try:
- self._error_string = self.message % kwargs
+ self._error_string = self.msg_fmt % kwargs
except Exception:
if _FATAL_EXCEPTION_FORMAT_ERRORS:
raise
else:
# at least get the core message out if something happened
- self._error_string = self.message
+ self._error_string = self.msg_fmt
def __str__(self):
return self._error_string
class MalformedRequestBody(OpenstackException):
- message = "Malformed message body: %(reason)s"
+ msg_fmt = "Malformed message body: %(reason)s"
class InvalidContentType(OpenstackException):
- message = "Invalid content type %(content_type)s"
+ msg_fmt = "Invalid content type %(content_type)s"
diff --git a/tests/unit/rpc/test_common.py b/tests/unit/rpc/test_common.py
index f0608af..669e8f7 100644
--- a/tests/unit/rpc/test_common.py
+++ b/tests/unit/rpc/test_common.py
@@ -66,12 +66,12 @@ class RpcCommonTestCase(test_utils.BaseTestCase):
def test_serialize_remote_custom_exception(self):
def raise_custom_exception():
- raise exception.OpenstackException()
+ raise exception.MalformedRequestBody(reason='test')
expected = {
- 'class': 'OpenstackException',
+ 'class': 'MalformedRequestBody',
'module': 'openstack.common.exception',
- 'message': exception.OpenstackException.message,
+ 'message': str(exception.MalformedRequestBody(reason='test')),
}
try:
@@ -92,7 +92,7 @@ class RpcCommonTestCase(test_utils.BaseTestCase):
expected = {
'class': 'OpenstackException',
'module': 'openstack.common.exception',
- 'message': exception.OpenstackException.message,
+ 'message': exception.OpenstackException.msg_fmt,
'tb': ['raise OpenstackException'],
}
@@ -139,7 +139,7 @@ class RpcCommonTestCase(test_utils.BaseTestCase):
failure = {
'class': 'OpenstackException',
'module': 'openstack.common.exception',
- 'message': exception.OpenstackException.message,
+ 'message': exception.OpenstackException.msg_fmt,
'tb': ['raise OpenstackException'],
}
serialized = jsonutils.dumps(failure)
@@ -221,7 +221,7 @@ class RpcCommonTestCase(test_utils.BaseTestCase):
after_exc = rpc_common.deserialize_remote_exception(FLAGS, serialized)
self.assertTrue(isinstance(after_exc, rpc_common.RemoteError))
- self.assertTrue(after_exc.message.startswith(
+ self.assertTrue(six.text_type(after_exc).startswith(
"Remote error: FakeIDontExistException"))
#assure the traceback was added
self.assertTrue('raise FakeIDontExistException' in
diff --git a/tests/unit/test_exception.py b/tests/unit/test_exception.py
index 97ac58e..e0c55d5 100644
--- a/tests/unit/test_exception.py
+++ b/tests/unit/test_exception.py
@@ -52,13 +52,13 @@ class ApiErrorTest(utils.BaseTestCase):
err = exception.ApiError('fake error')
self.assertEqual(err.__str__(), 'Unknown: fake error')
self.assertEqual(err.code, 'Unknown')
- self.assertEqual(err.message, 'fake error')
+ self.assertEqual(err.api_message, 'fake error')
def test_with_code(self):
err = exception.ApiError('fake error', 'blah code')
self.assertEqual(err.__str__(), 'blah code: fake error')
self.assertEqual(err.code, 'blah code')
- self.assertEqual(err.message, 'fake error')
+ self.assertEqual(err.api_message, 'fake error')
class BadStoreUriTest(utils.BaseTestCase):
@@ -67,8 +67,8 @@ class BadStoreUriTest(utils.BaseTestCase):
uri = 'http:///etc/passwd'
reason = 'Permission DENIED!'
err = exception.BadStoreUri(uri, reason)
- self.assertTrue(uri in str(err.message))
- self.assertTrue(reason in str(err.message))
+ self.assertTrue(uri in str(err))
+ self.assertTrue(reason in str(err))
class UnknownSchemeTest(utils.BaseTestCase):
@@ -76,12 +76,12 @@ class UnknownSchemeTest(utils.BaseTestCase):
def test(self):
scheme = 'http'
err = exception.UnknownScheme(scheme)
- self.assertTrue(scheme in str(err.message))
+ self.assertTrue(scheme in str(err))
class OpenstackExceptionTest(utils.BaseTestCase):
class TestException(exception.OpenstackException):
- message = '%(test)s'
+ msg_fmt = '%(test)s'
def test_format_error_string(self):
test_message = 'Know Your Meme'
@@ -91,7 +91,7 @@ class OpenstackExceptionTest(utils.BaseTestCase):
def test_error_formating_error_string(self):
self.stubs.Set(exception, '_FATAL_EXCEPTION_FORMAT_ERRORS', False)
err = self.TestException(lol='U mad brah')
- self.assertEqual(err._error_string, self.TestException.message)
+ self.assertEqual(err._error_string, self.TestException.msg_fmt)
def test_str(self):
message = 'Y u no fail'