From 04ded420c8bd92eb5694c27433ded5829b0b80aa Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Fri, 21 Aug 2020 11:48:19 +0200 Subject: [PATCH] python: Exception.message was removed in python3 (#45995) --- bindings/python/lang.py | 5 ++++- bindings/python/tests/binding_tests.py | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/bindings/python/lang.py b/bindings/python/lang.py index 22b7d028..f97c63ce 100644 --- a/bindings/python/lang.py +++ b/bindings/python/lang.py @@ -188,7 +188,10 @@ class Error(Exception): if self.code: return '' % (self.__class__.__name__, self.code, _lasso.strError(self.code)) else: - return '' % (self.__class__.__name__, self.message) + if sys.version_info >= (3,): + return '' % (self.__class__.__name__, self) + else: + return '' % (self.__class__.__name__, self.message) def __getitem__(self, i): # compatibility with SWIG bindings diff --git a/bindings/python/tests/binding_tests.py b/bindings/python/tests/binding_tests.py index 936e8b3b..feca4694 100755 --- a/bindings/python/tests/binding_tests.py +++ b/bindings/python/tests/binding_tests.py @@ -329,6 +329,14 @@ class BindingTestCase(unittest.TestCase): node.sessionIndexes = () assert node.sessionIndexes == (), node.sessionIndexes + def test14(self): + # verify Error implementation + with self.assertRaises(lasso.Error) as cm: + lasso.Server('', '', '') + assert isinstance(str(cm.exception), str) + with self.assertRaises(lasso.Error) as cm: + lasso.Error.raise_on_rc(lasso._lasso.XML_ERROR_SCHEMA_INVALID_FRAGMENT) + self.assertEqual(str(cm.exception), '') -- 2.28.0