From 16559b8472fb706e95b9e1dd1264475dec1b1d1e Mon Sep 17 00:00:00 2001 From: zhongjun Date: Thu, 18 Jun 2015 05:16:31 +0800 Subject: [PATCH] Delete redundant period in ManilaException messages --Delete redundant period in the command echo. Change-Id: I0081643b0ba432b327a22473856d06b63f307873 Closes-Bug: #1466062 --- manila/exception.py | 3 +++ manila/tests/test_exception.py | 14 ++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/manila/exception.py b/manila/exception.py index 3894d43e..48ef5cb4 100644 --- a/manila/exception.py +++ b/manila/exception.py @@ -21,6 +21,7 @@ Includes decorator for re-raising Manila-type exceptions. SHOULD include dedicated exception logging. """ +import re from oslo_concurrency import processutils from oslo_config import cfg @@ -103,6 +104,8 @@ class ManilaException(Exception): elif isinstance(message, Exception): message = six.text_type(message) + if re.match('.*[^\.]\.\.$', message): + message = message[:-1] self.msg = message super(ManilaException, self).__init__(message) diff --git a/manila/tests/test_exception.py b/manila/tests/test_exception.py index 8abbc240..29e5b912 100644 --- a/manila/tests/test_exception.py +++ b/manila/tests/test_exception.py @@ -15,6 +15,7 @@ # License for the specific language governing permissions and limitations # under the License. +import ddt import six from manila import exception @@ -38,6 +39,7 @@ class FakeNotifier(object): self.provided_payload = payload +@ddt.ddt class ManilaExceptionTestCase(test.TestCase): def test_default_error_msg(self): class FakeManilaException(exception.ManilaException): @@ -104,6 +106,18 @@ class ManilaExceptionTestCase(test.TestCase): self.assertNotIn('foo_msg', exc.kwargs) self.assertNotIn('bar_msg', exc.kwargs) + @ddt.data("test message.", "test message....", ".") + def test_exception_not_redundant_period(self, msg): + exc1 = Exception(msg) + exc2 = exception.ManilaException(exc1) + self.assertEqual(msg, exc2.msg) + + def test_exception_redundant_period(self): + msg = "test message.." + exc1 = Exception(msg) + exc2 = exception.ManilaException(exc1) + self.assertEqual("test message.", exc2.msg) + class ManilaExceptionResponseCode400(test.TestCase):