mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-23 02:49:27 +01:00
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:
parent
35065b8fc5
commit
e4c9381f7b
@ -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):
|
||||
|
@ -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:
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user