mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-19 08:59:27 +01:00
Have exnToString handle exceptions whose str representation is empty.
This commit is contained in:
parent
040888405c
commit
58b3268bdd
@ -537,7 +537,11 @@ def safeEval(s, namespace={'True': True, 'False': False, 'None': None}):
|
|||||||
|
|
||||||
def exnToString(e):
|
def exnToString(e):
|
||||||
"""Turns a simple exception instance into a string (better than str(e))"""
|
"""Turns a simple exception instance into a string (better than str(e))"""
|
||||||
return '%s: %s' % (e.__class__.__name__, e)
|
strE = str(e)
|
||||||
|
if strE:
|
||||||
|
return '%s: %s' % (e.__class__.__name__, strE)
|
||||||
|
else:
|
||||||
|
return e.__class__.__name__
|
||||||
|
|
||||||
class IterableMap(object):
|
class IterableMap(object):
|
||||||
"""Define .iteritems() in a class and subclass this to get the other iters.
|
"""Define .iteritems() in a class and subclass this to get the other iters.
|
||||||
|
@ -33,6 +33,16 @@ import sets
|
|||||||
import supybot.utils as utils
|
import supybot.utils as utils
|
||||||
|
|
||||||
class UtilsTest(SupyTestCase):
|
class UtilsTest(SupyTestCase):
|
||||||
|
def testExnToString(self):
|
||||||
|
try:
|
||||||
|
raise KeyError, 1
|
||||||
|
except Exception, e:
|
||||||
|
self.assertEqual(utils.exnToString(e), 'KeyError: 1')
|
||||||
|
try:
|
||||||
|
raise EOFError
|
||||||
|
except Exception, e:
|
||||||
|
self.assertEqual(utils.exnToString(e), 'EOFError')
|
||||||
|
|
||||||
def testMatchCase(self):
|
def testMatchCase(self):
|
||||||
f = utils.matchCase
|
f = utils.matchCase
|
||||||
self.assertEqual('bar', f('foo', 'bar'))
|
self.assertEqual('bar', f('foo', 'bar'))
|
||||||
|
Loading…
Reference in New Issue
Block a user