mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-04-09 01:18:10 +02: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):
|
||||
"""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):
|
||||
"""Define .iteritems() in a class and subclass this to get the other iters.
|
||||
|
@ -33,6 +33,16 @@ import sets
|
||||
import supybot.utils as utils
|
||||
|
||||
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):
|
||||
f = utils.matchCase
|
||||
self.assertEqual('bar', f('foo', 'bar'))
|
||||
|
Loading…
x
Reference in New Issue
Block a user