Fixed bugs, added tests, etc.

This commit is contained in:
Jeremy Fincher 2007-10-23 05:19:09 +00:00 committed by James Vega
parent 9a43f04248
commit 1979f5ad35
2 changed files with 8 additions and 9 deletions

View File

@ -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):
"""[<channel>] <stat expression>
@ -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)

View File

@ -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: