From e4c9381f7b89ccfb3802818c8a24ac848d46bd13 Mon Sep 17 00:00:00 2001 From: James Vega Date: Mon, 13 Jun 2005 17:27:15 +0000 Subject: [PATCH] src/commands: Update first so that state.errored will not prevent the bot from responding when the first converter fails. --- src/commands.py | 4 ++++ test/test_commands.py | 18 +++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/commands.py b/src/commands.py index c33e639c7..e79dec373 100644 --- a/src/commands.py +++ b/src/commands.py @@ -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): diff --git a/test/test_commands.py b/test/test_commands.py index 61344645e..765b44aed 100644 --- a/test/test_commands.py +++ b/test/test_commands.py @@ -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): @@ -135,7 +147,7 @@ class GeneralContextTestCase(CommandsTestCase): self.assertState(spec, ['bar'], ['bar']) self.assertState(spec, ['baz'], ['baz']) self.assertError(spec, ['ba']) - + class ConverterTestCase(CommandsTestCase): def testUrlAllowsHttps(self): url = 'https://foo.bar/baz' @@ -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: