Fixed all tests for this plugin.

This commit is contained in:
Jeremy Fincher 2004-01-31 21:10:23 +00:00
parent 55c392fae3
commit 8e1b96885a
2 changed files with 45 additions and 37 deletions

View File

@ -50,7 +50,7 @@ import callbacks
conf.registerPlugin('WordStats') conf.registerPlugin('WordStats')
conf.registerChannelValue(conf.supybot.plugins.WordStats, conf.registerChannelValue(conf.supybot.plugins.WordStats,
'wordstatsRankingDisplay', 'rankingDisplay',
registry.PositiveInteger(3, """Determines the maximum number of top users registry.PositiveInteger(3, """Determines the maximum number of top users
to show for a given wordstat when someone requests the wordstats for a to show for a given wordstat when someone requests the wordstats for a
particular word.""")) particular word."""))
@ -220,7 +220,7 @@ class WordStats(callbacks.Privmsg, plugins.ChannelDBHandler):
else: else:
# It's a word, not a user # It's a word, not a user
word = arg1 word = arg1
numUsers = self.registryValue('wordstatsRankingDisplay', numUsers = self.registryValue('rankingDisplay',
msg.args[0]) msg.args[0])
cursor.execute("""SELECT word_stats.count, cursor.execute("""SELECT word_stats.count,
word_stats.user_id word_stats.user_id

View File

@ -39,7 +39,7 @@ except ImportError:
sqlite = None sqlite = None
if sqlite is not None: if sqlite is not None:
class ChannelDBTestCase(ChannelPluginTestCase): class WordStatsTestCase(ChannelPluginTestCase):
plugins = ('WordStats', 'User') plugins = ('WordStats', 'User')
def setUp(self): def setUp(self):
ChannelPluginTestCase.setUp(self) ChannelPluginTestCase.setUp(self)
@ -54,16 +54,16 @@ if sqlite is not None:
def testWordStatsNoArgs(self): def testWordStatsNoArgs(self):
self.assertResponse('wordstats', 'I am not currently keeping any ' self.assertResponse('wordstats', 'I am not currently keeping any '
'word stats.') 'word stats.')
self.assertNotError('addword lol') self.assertNotError('add lol')
self.assertResponse('wordstats', 'Currently keeping stats for: ' self.assertResponse('wordstats', 'Currently keeping stats for: '
'\'lol\'') '\'lol\'')
def testWordStatsUser(self): def testWordStatsUser(self):
self.assertNotError('addword lol') self.assertNotError('add lol')
self.irc.feedMsg(ircmsgs.privmsg(self.channel, 'lol', self.irc.feedMsg(ircmsgs.privmsg(self.channel, 'lol',
prefix=self.prefix)) prefix=self.prefix))
self.assertResponse('wordstats foo', '\'lol\': 2') self.assertResponse('wordstats foo', '\'lol\': 2')
self.assertNotError('addword moo') self.assertNotError('add moo')
self.irc.feedMsg(ircmsgs.privmsg(self.channel, 'moo', self.irc.feedMsg(ircmsgs.privmsg(self.channel, 'moo',
prefix=self.prefix)) prefix=self.prefix))
self.assertResponse('wordstats foo', '\'lol\': 2 and \'moo\': 2') self.assertResponse('wordstats foo', '\'lol\': 2 and \'moo\': 2')
@ -79,7 +79,7 @@ if sqlite is not None:
prefix=userPrefix2)) prefix=userPrefix2))
_ = self.irc.takeMsg() _ = self.irc.takeMsg()
_ = self.irc.takeMsg() _ = self.irc.takeMsg()
self.assertNotError('addword lol') self.assertNotError('add lol')
self.assertRegexp('wordstats lol', 'foo: 1') self.assertRegexp('wordstats lol', 'foo: 1')
for i in range(5): for i in range(5):
self.irc.feedMsg(ircmsgs.privmsg(self.channel, 'lol', self.irc.feedMsg(ircmsgs.privmsg(self.channel, 'lol',
@ -95,14 +95,18 @@ if sqlite is not None:
# Check for the extra-swanky stuff too # Check for the extra-swanky stuff too
# (note: to do so we must make sure they don't appear in the list, # (note: to do so we must make sure they don't appear in the list,
# so we'll tweak the config) # so we'll tweak the config)
self.assertNotError('channeldb config wordstats-top-n 2') try:
self.assertRegexp('wordstats lol', orig = conf.supybot.plugins.WordStats.rankingDisplay()
'total.*19 \'lol\'s.*%s: 10.*%s: 5.*' conf.supybot.plugins.WordStats.rankingDisplay.setValue(2)
'ranked 3 out of 3 \'lol\'ers' % \ self.assertRegexp('wordstats lol',
(userNick2, userNick1)) 'total.*19 \'lol\'s.*%s: 10.*%s: 5.*'
'ranked 3 out of 3 \'lol\'ers' % \
(userNick2, userNick1))
finally:
conf.supybot.plugins.WordStats.rankingDisplay.setValue(orig)
def testWordStatsUserWord(self): def testWordStatsUserWord(self):
self.assertNotError('addword lol') self.assertNotError('add lol')
self.assertResponse('wordstats foo lol', self.assertResponse('wordstats foo lol',
'foo has said \'lol\' 1 time.') 'foo has said \'lol\' 1 time.')
self.irc.feedMsg(ircmsgs.privmsg(self.channel, 'lol', self.irc.feedMsg(ircmsgs.privmsg(self.channel, 'lol',
@ -120,7 +124,7 @@ if sqlite is not None:
self.assertResponse('wordstats foo lol', self.assertResponse('wordstats foo lol',
'foo has said \'lol\' 7 times.') 'foo has said \'lol\' 7 times.')
# Check and make sure it handles two words in one message # Check and make sure it handles two words in one message
self.assertNotError('addword heh') self.assertNotError('add heh')
self.irc.feedMsg(ircmsgs.privmsg(self.channel, 'lol heh', self.irc.feedMsg(ircmsgs.privmsg(self.channel, 'lol heh',
prefix=self.prefix)) prefix=self.prefix))
self.assertResponse('wordstats foo lol', self.assertResponse('wordstats foo lol',
@ -136,30 +140,34 @@ if sqlite is not None:
'foo has said \'heh\' 4 times.') 'foo has said \'heh\' 4 times.')
def testAddword(self): def testAddword(self):
self.assertError('addword lol!') self.assertError('add lol!')
self.assertNotError('addword lolz0r') self.assertNotError('add lolz0r')
def testWordStatsTopN(self): def testWordStatsRankingDisplay(self):
self.assertNotError('addword lol') self.assertNotError('add lol')
self.assertNotError('channeldb config wordstats-top-n 5') try:
# Create 10 users and have them each send a different number of orig = conf.supybot.plugins.WordStats.rankingDisplay()
# 'lol's to the channel conf.supybot.plugins.WordStats.rankingDisplay.setValue(5)
users = [] # Create 10 users and have them each send a different number of
for i in range(10): # 'lol's to the channel
users.append(('foo%s!bar@baz' % i, 'foo%s' % i)) users = []
self.irc.feedMsg(ircmsgs.privmsg(self.irc.nick, for i in range(10):
'register %s bar' % \ users.append(('foo%s!bar@baz' % i, 'foo%s' % i))
users[i][1], self.irc.feedMsg(ircmsgs.privmsg(self.irc.nick,
prefix=users[i][0])) 'register %s bar' % \
_ = self.irc.takeMsg() users[i][1],
for i in range(10):
for j in range(i):
self.irc.feedMsg(ircmsgs.privmsg(self.channel, 'lol',
prefix=users[i][0])) prefix=users[i][0]))
# Make sure it shows the top 5 _ = self.irc.takeMsg()
self.assertRegexp('wordstats lol', for i in range(10):
'Top 5 \'lol\'ers.*foo9: 9.*foo8: 8.*' for j in range(i):
'foo7: 7.*foo6: 6.*foo5: 5') self.irc.feedMsg(ircmsgs.privmsg(self.channel, 'lol',
prefix=users[i][0]))
# Make sure it shows the top 5
self.assertRegexp('wordstats lol',
'Top 5 \'lol\'ers.*foo9: 9.*foo8: 8.*'
'foo7: 7.*foo6: 6.*foo5: 5')
finally:
conf.supybot.plugins.WordStats.rankingDisplay.setValue(orig)
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: # vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: