From 1979f5ad35f914548c125de32f27c79183dfa1b3 Mon Sep 17 00:00:00 2001 From: Jeremy Fincher Date: Tue, 23 Oct 2007 05:19:09 +0000 Subject: [PATCH] Fixed bugs, added tests, etc. --- plugins/ChannelStats/plugin.py | 14 ++++++-------- plugins/ChannelStats/test.py | 3 ++- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/plugins/ChannelStats/plugin.py b/plugins/ChannelStats/plugin.py index 4dc30fb03..89c4ef066 100644 --- a/plugins/ChannelStats/plugin.py +++ b/plugins/ChannelStats/plugin.py @@ -28,6 +28,7 @@ ### import re +import math import types import supybot.log as log @@ -274,6 +275,7 @@ class ChannelStats(callbacks.Plugin): stats = wrap(stats, ['channeldb', additional('something')]) _env = {'__builtins__': types.ModuleType('__builtins__')} + _env.update(math.__dict__) def rank(self, irc, msg, args, channel, expr): """[] @@ -288,11 +290,9 @@ class ChannelStats(callbacks.Plugin): if expr != expr.translate(utils.str.chars, '_[]'): irc.error('There\'s really no reason why you should have ' 'underscores or brackets in your mathematical ' - 'expression. Please remove them.') - return + 'expression. Please remove them.', Raise=True) if 'lambda' in expr: - irc.error('You can\'t use lambda in this command.') - return + irc.error('You can\'t use lambda in this command.', Raise=True) expr = expr.lower() users = [] for ((c, id), stats) in self.db.items(): @@ -305,12 +305,10 @@ class ChannelStats(callbacks.Plugin): except ZeroDivisionError: v = float('inf') except NameError, e: - irc.error('You referenced an invalid stat variable:', - str(e).split()[1], Raise=True) + irc.errorInvalid('stat variable', str(e).split()[1]) except Exception, e: irc.error(utils.exnToString(e), Raise=True) - else: - users.append((v, ircdb.users.getUser(id).name)) + users.append((v, ircdb.users.getUser(id).name)) users.sort() users.reverse() s = utils.str.commaAndify(['#%s %s (%.3g)' % (i, u, v) diff --git a/plugins/ChannelStats/test.py b/plugins/ChannelStats/test.py index dbef82d55..20dade708 100644 --- a/plugins/ChannelStats/test.py +++ b/plugins/ChannelStats/test.py @@ -83,8 +83,9 @@ class ChannelStatsTestCase(ChannelPluginTestCase): self.assertNotError('channelstats stats %s' % self.nick) self.assertNotError('channelstats stats %s' % self.nick.upper()) self.assertNotError('channelstats stats') - self.assertNotError('channelstats rank chars / msgs') + self.assertNotError('channelstats rank kicks/kicked') # Tests inf + self.assertNotError('channelstats rank log(msgs)') # vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: