src/commands: Update first so that state.errored will not prevent the bot from responding when the first converter fails.

This commit is contained in:
James Vega 2005-06-13 17:27:15 +00:00
parent 35065b8fc5
commit e4c9381f7b
2 changed files with 21 additions and 1 deletions

View File

@ -757,15 +757,19 @@ class first(context):
self.specs = map(contextify, specs)
def __call__(self, irc, msg, args, state):
errored = False
for spec in self.specs:
try:
spec(irc, msg, args, state)
return
except Exception, e:
errored = state.errored
state.errored = False
continue
if hasattr(self, 'default'):
state.args.append(self.default)
else:
state.errored = errored
raise e
class reverse(context):

View File

@ -51,6 +51,18 @@ class CommandsTestCase(SupyTestCase):
self.assertRaises(callbacks.Error,
self.assertState, spec, given, given)
def assertStateErrored(self, spec, given, target='test', errored=True,
**kwargs):
msg = ircmsgs.privmsg(target, 'foo')
realIrc = getTestIrc()
realIrc.nick = 'test'
realIrc.state.supported['chantypes'] = '#'
irc = callbacks.SimpleProxy(realIrc, msg)
myspec = Spec(spec, **kwargs)
state = myspec(irc, msg, given)
self.assertEqual(state.errored, errored,
'Expected %r, got %r' % (errored, state.errored))
class GeneralContextTestCase(CommandsTestCase):
def testEmptySpec(self):
@ -153,5 +165,9 @@ class FirstTestCase(CommandsTestCase):
def testRepr(self):
self.failUnless(repr(first('int')))
def testFirstConverterFailsAndNotErroredState(self):
self.assertStateErrored([first('int', 'something')], ['words'],
errored=False)
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79: