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

View File

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