python: Exception.message was removed in python3 (#45995)

This commit is contained in:
Benjamin Dauvergne 2020-08-21 11:48:19 +02:00
parent 0b742b1f6d
commit 04ded420c8
2 changed files with 12 additions and 1 deletions

View File

@ -188,7 +188,10 @@ class Error(Exception):
if self.code:
return '<lasso.%s(%s): %s>' % (self.__class__.__name__, self.code, _lasso.strError(self.code))
else:
return '<lasso.%s: %s>' % (self.__class__.__name__, self.message)
if sys.version_info >= (3,):
return '<lasso.%s: %s>' % (self.__class__.__name__, self)
else:
return '<lasso.%s: %s>' % (self.__class__.__name__, self.message)
def __getitem__(self, i):
# compatibility with SWIG bindings

View File

@ -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), '<lasso.XmlSchemaInvalidFragmentError(17): An XML tree does not respect at least an XML schema of its namespaces.>')