Someone forgot to convert the testsuite when FunDB.num was switched to

FunDB.stats. Took care of that and updated to use the registry.
This commit is contained in:
James Vega 2004-01-21 02:19:26 +00:00
parent 75b6da806e
commit 7336a4c9ad
2 changed files with 36 additions and 37 deletions

View File

@ -45,6 +45,8 @@ import string
import os.path
from itertools import imap
import registry
import conf
import ircdb
import utils
@ -53,7 +55,6 @@ import ircmsgs
import ircutils
import privmsgs
import callbacks
import configurable
try:
import sqlite
@ -83,27 +84,25 @@ tableCreateStatements = {
added_by TEXT
)""",),
}
conf.registerPlugin('FunDB')
conf.registerChannelValue(conf.supybot.plugins.FunDB, 'showIds',
registry.Boolean(True, """Determine whether the bot will show the id of an
excuse/insult/praise/lart."""))
class FunDB(callbacks.Privmsg, configurable.Mixin, plugins.ChannelDBHandler):
class FunDB(callbacks.Privmsg, plugins.ChannelDBHandler):
"""
Contains the 'fun' commands that require a database. Currently includes
database-backed commands for crossword puzzle solving, anagram searching,
larting, praising, excusing, and insulting.
"""
configurables = configurable.Dictionary(
[('show-ids', configurable.BoolType, False,
"""Determines whether the bot will show the id of an
excuse/insult/praise/lart.""")]
)
_tables = sets.Set(['lart', 'insult', 'excuse', 'praise'])
def __init__(self):
callbacks.Privmsg.__init__(self)
configurable.Mixin.__init__(self)
plugins.ChannelDBHandler.__init__(self)
def die(self):
callbacks.Privmsg.die(self)
configurable.Mixin.die(self)
plugins.ChannelDBHandler.die(self)
def makeDb(self, dbfilename, replace=False):
@ -346,7 +345,7 @@ class FunDB(callbacks.Privmsg, configurable.Mixin, plugins.ChannelDBHandler):
nick = re.sub(r'\bme\b', msg.nick, nick)
nick = re.sub(r'\bmy\b', '%s\'s' % msg.nick, nick)
insult = insult.replace('$who', nick)
showid = self.configurables.get('show-ids', channel)
showid = self.registryValue('showIds', channel)
irc.reply(self._formatResponse(insult, id, showid), to=nick)
def excuse(self, irc, msg, args):
@ -380,7 +379,7 @@ class FunDB(callbacks.Privmsg, configurable.Mixin, plugins.ChannelDBHandler):
irc.error('There are currently no available excuses.')
else:
(id, excuse) = cursor.fetchone()
showid = self.configurables.get('show-ids', channel)
showid = self.registryValue('showIds', channel)
irc.reply(self._formatResponse(excuse, id, showid))
def lart(self, irc, msg, args):
@ -435,7 +434,7 @@ class FunDB(callbacks.Privmsg, configurable.Mixin, plugins.ChannelDBHandler):
if reason:
s = '%s for %s' % (s, reason)
s = s.rstrip('.')
showid = self.configurables.get('show-ids', channel)
showid = self.registryValue('showIds', channel)
irc.reply(self._formatResponse(s, id, showid), action=True)
def praise(self, irc, msg, args):
@ -489,7 +488,7 @@ class FunDB(callbacks.Privmsg, configurable.Mixin, plugins.ChannelDBHandler):
if reason:
s = '%s for %s' % (s, reason)
s = s.rstrip('.')
showid = self.configurables.get('show-ids', channel)
showid = self.registryValue('showIds', channel)
irc.reply(self._formatResponse(s, id, showid), action=True)
Class = FunDB

View File

@ -51,7 +51,7 @@ if sqlite is not None:
_ = self.irc.takeMsg()
#ircdb.users.getUser('t3st').addCapability('admin')
ircdb.users.getUser('t3st').addCapability('#test.op')
self.assertNotError('fundb config #test show-ids on')
conf.supybot.plugins.FunDB.showIds.setValue(True)
def testAdd(self):
self.assertError('add l4rt foo')
@ -69,7 +69,7 @@ if sqlite is not None:
'(#1)\x01')
self.assertResponse('lart jemfinch',
'\x01ACTION jabs jemfinch (#1)\x01')
self.assertRegexp('num lart', 'currently 1 lart')
self.assertRegexp('stats lart', 'currently 1 lart')
self.assertNotError('add lart shoots $who')
self.assertHelp('lart 1')
self.assertResponse('lart 1 jemfinch',
@ -79,11 +79,11 @@ if sqlite is not None:
'(#2)\x01')
self.assertNotRegexp('lart %s' % self.irc.nick, self.irc.nick)
self.assertNotError('remove lart 1')
self.assertRegexp('num lart', 'currently 1 lart')
self.assertRegexp('stats lart', 'currently 1 lart')
self.assertResponse('lart jemfinch',
'\x01ACTION shoots jemfinch (#2)\x01')
self.assertNotError('remove lart 2')
self.assertRegexp('num lart', 'currently 0')
self.assertRegexp('stats lart', 'currently 0')
self.assertError('lart jemfinch')
def testLartAndPraiseRemoveTrailingPeriods(self):
@ -126,23 +126,23 @@ if sqlite is not None:
self.assertNotError('add excuse Power failure')
self.assertResponse('excuse', 'Power failure (#1)')
self.assertError('excuse a few random words')
self.assertRegexp('num excuse', r'currently 1 excuse')
self.assertRegexp('stats excuse', r'currently 1 excuse')
self.assertNotError('add excuse /pub/lunch')
self.assertResponse('excuse 1', 'Power failure (#1)')
self.assertNotError('remove excuse 1')
self.assertRegexp('num excuse', r'currently 1 excuse')
self.assertRegexp('stats excuse', r'currently 1 excuse')
self.assertResponse('excuse', '/pub/lunch (#2)')
self.assertNotError('remove excuse 2')
self.assertRegexp('num excuse', r'currently 0')
self.assertRegexp('stats excuse', r'currently 0')
self.assertError('excuse')
def testInsult(self):
self.assertNotError('add insult Fatty McFatty')
self.assertResponse('insult jemfinch',
'jemfinch: Fatty McFatty (#1)')
self.assertRegexp('num insult', r'currently 1')
self.assertRegexp('stats insult', r'currently 1')
self.assertNotError('remove insult 1')
self.assertRegexp('num insult', 'currently 0')
self.assertRegexp('stats insult', 'currently 0')
self.assertError('insult jemfinch')
def testPraise(self):
@ -153,7 +153,7 @@ if sqlite is not None:
'(#1)\x01')
self.assertResponse('praise jemfinch',
'\x01ACTION pets jemfinch (#1)\x01')
self.assertRegexp('num praise', r'currently 1')
self.assertRegexp('stats praise', r'currently 1')
self.assertNotError('add praise gives $who a cookie')
self.assertHelp('praise 1')
self.assertResponse('praise 1 jemfinch',
@ -162,11 +162,11 @@ if sqlite is not None:
'\x01ACTION gives jemfinch a cookie for being '
'him (#2)\x01')
self.assertNotError('remove praise 1')
self.assertRegexp('num praise', r'currently 1')
self.assertRegexp('stats praise', r'currently 1')
self.assertResponse('praise jemfinch',
'\x01ACTION gives jemfinch a cookie (#2)\x01')
self.assertNotError('remove praise 2')
self.assertRegexp('num praise', r'currently 0')
self.assertRegexp('stats praise', r'currently 0')
self.assertError('praise jemfinch')
def testInfo(self):
@ -176,20 +176,20 @@ if sqlite is not None:
self.assertError('info fake 1')
def testGet(self):
self.assertError('get fake 1')
self.assertError('get lart foo')
self.assertError('fundb get fake 1')
self.assertError('fundb get lart foo')
self.assertNotError('add praise pets $who')
self.assertResponse('get praise 1', 'pets $who')
self.assertResponse('fundb get praise 1', 'pets $who')
self.assertNotError('remove praise 1')
self.assertError('get praise 1')
self.assertError('fundb get praise 1')
def testNum(self):
self.assertError('num fake')
self.assertError('num 1')
self.assertRegexp('num praise', r'currently 0')
self.assertRegexp('num lart', r'currently 0')
self.assertRegexp('num excuse', r'currently 0')
self.assertRegexp('num insult', r'currently 0')
def testStats(self):
self.assertError('stats fake')
self.assertError('stats 1')
self.assertRegexp('stats praise', r'currently 0')
self.assertRegexp('stats lart', r'currently 0')
self.assertRegexp('stats excuse', r'currently 0')
self.assertRegexp('stats insult', r'currently 0')
def testChange(self):
self.assertNotError('add praise teaches $who perl')
@ -201,7 +201,7 @@ if sqlite is not None:
def testConfig(self):
self.assertNotError('add praise teaches $who perl')
self.assertRegexp('praise jemfinch', r'\(#1\)')
self.assertNotError('fundb config show-ids off')
conf.supybot.plugins.FunDB.showIds.setValue(False)
self.assertNotRegexp('praise jemfinch', r'\(#1\)')
def testLartPraiseReasonPeriod(self):