Made this work on boxes that don't have sqlite.

This commit is contained in:
Jeremy Fincher 2004-08-19 17:10:24 +00:00
parent bfcff00380
commit 715bdcf6e3

View File

@ -31,84 +31,90 @@
from testsupport import *
import supybot.plugins.Infobot
confirms = supybot.plugins.Infobot.confirms
dunnos = supybot.plugins.Infobot.dunnos
ibot = conf.supybot.plugins.Infobot
try:
import sqlite
except ImportError:
sqlite = None
class InfobotTestCase(ChannelPluginTestCase):
plugins = ('Infobot',)
_endRe = re.compile(r'!|, \S+\.|\.')
def testIsSnarf(self):
learn = ibot.snarfUnaddressedDefinitions()
answer = ibot.answerUnaddressedQuestions()
try:
ibot.snarfUnaddressedDefinitions.setValue(True)
ibot.answerUnaddressedQuestions.setValue(True)
self.assertSnarfNoResponse('foo is at http://bar.com/', 2)
self.assertSnarfRegexp('foo?', r'foo.*is.*http://bar.com/')
self.assertSnarfNoResponse('foo is at http://baz.com/', 2)
self.assertSnarfNotRegexp('foo?', 'baz')
m = self.getMsg('bar is at http://foo.com/')
self.failUnless(self._endRe.sub('', m.args[1]) in confirms)
self.assertRegexp('bar?', r'bar.*is.*http://foo.com/')
finally:
ibot.snarfUnaddressedDefinitions.setValue(learn)
ibot.answerUnaddressedQuestions.setValue(answer)
if sqlite is not None:
import supybot.plugins.Infobot
confirms = supybot.plugins.Infobot.confirms
dunnos = supybot.plugins.Infobot.dunnos
ibot = conf.supybot.plugins.Infobot
def testAreSnarf(self):
learn = ibot.snarfUnaddressedDefinitions()
answer = ibot.answerUnaddressedQuestions()
try:
ibot.snarfUnaddressedDefinitions.setValue(True)
ibot.answerUnaddressedQuestions.setValue(True)
self.assertSnarfNoResponse('bars are dirty', 2)
self.assertSnarfRegexp('bars?', 'bars.*are.*dirty')
self.assertSnarfNoResponse('bars are not dirty', 2)
self.assertSnarfNotRegexp('bars?', 'not')
finally:
ibot.snarfUnaddressedDefinitions.setValue(learn)
ibot.answerUnaddressedQuestions.setValue(answer)
class InfobotTestCase(ChannelPluginTestCase):
plugins = ('Infobot',)
_endRe = re.compile(r'!|, \S+\.|\.')
def testIsSnarf(self):
learn = ibot.snarfUnaddressedDefinitions()
answer = ibot.answerUnaddressedQuestions()
try:
ibot.snarfUnaddressedDefinitions.setValue(True)
ibot.answerUnaddressedQuestions.setValue(True)
self.assertSnarfNoResponse('foo is at http://bar.com/', 2)
self.assertSnarfRegexp('foo?', r'foo.*is.*http://bar.com/')
self.assertSnarfNoResponse('foo is at http://baz.com/', 2)
self.assertSnarfNotRegexp('foo?', 'baz')
m = self.getMsg('bar is at http://foo.com/')
self.failUnless(self._endRe.sub('', m.args[1]) in confirms)
self.assertRegexp('bar?', r'bar.*is.*http://foo.com/')
finally:
ibot.snarfUnaddressedDefinitions.setValue(learn)
ibot.answerUnaddressedQuestions.setValue(answer)
def testIsResponses(self):
learn = ibot.snarfUnaddressedDefinitions()
answer = ibot.answerUnaddressedQuestions()
try:
ibot.snarfUnaddressedDefinitions.setValue(True)
ibot.answerUnaddressedQuestions.setValue(True)
self.assertSnarfNoResponse('foo is bar', 2)
self.assertSnarfRegexp('foo?', 'foo.*is.*bar')
self.assertSnarfNoResponse('when is foo?', 2)
self.assertSnarfNoResponse('why is foo?', 2)
self.assertSnarfNoResponse('why foo?', 2)
self.assertSnarfNoResponse('when is foo?', 2)
finally:
ibot.snarfUnaddressedDefinitions.setValue(learn)
ibot.answerUnaddressedQuestions.setValue(answer)
def testAreSnarf(self):
learn = ibot.snarfUnaddressedDefinitions()
answer = ibot.answerUnaddressedQuestions()
try:
ibot.snarfUnaddressedDefinitions.setValue(True)
ibot.answerUnaddressedQuestions.setValue(True)
self.assertSnarfNoResponse('bars are dirty', 2)
self.assertSnarfRegexp('bars?', 'bars.*are.*dirty')
self.assertSnarfNoResponse('bars are not dirty', 2)
self.assertSnarfNotRegexp('bars?', 'not')
finally:
ibot.snarfUnaddressedDefinitions.setValue(learn)
ibot.answerUnaddressedQuestions.setValue(answer)
def testAnswerUnaddressed(self):
answer = ibot.answerUnaddressedQuestions()
try:
ibot.answerUnaddressedQuestions.setValue(True)
self.assertSnarfNoResponse('foo is bar')
self.assertSnarfRegexp('foo?', 'bar')
ibot.answerUnaddressedQuestions.setValue(False)
self.assertSnarfNoResponse('foo?', 2)
finally:
ibot.answerUnaddressedQuestions.setValue(answer)
def testIsResponses(self):
learn = ibot.snarfUnaddressedDefinitions()
answer = ibot.answerUnaddressedQuestions()
try:
ibot.snarfUnaddressedDefinitions.setValue(True)
ibot.answerUnaddressedQuestions.setValue(True)
self.assertSnarfNoResponse('foo is bar', 2)
self.assertSnarfRegexp('foo?', 'foo.*is.*bar')
self.assertSnarfNoResponse('when is foo?', 2)
self.assertSnarfNoResponse('why is foo?', 2)
self.assertSnarfNoResponse('why foo?', 2)
self.assertSnarfNoResponse('when is foo?', 2)
finally:
ibot.snarfUnaddressedDefinitions.setValue(learn)
ibot.answerUnaddressedQuestions.setValue(answer)
def testReplaceFactoid(self):
answer = ibot.answerUnaddressedQuestions()
learn = ibot.snarfUnaddressedDefinitions()
try:
ibot.answerUnaddressedQuestions.setValue(True)
ibot.snarfUnaddressedDefinitions.setValue(True)
self.assertSnarfNoResponse('forums are good')
self.assertSnarfRegexp('forums?', 'good')
self.assertNotError('no, forums are evil')
self.assertSnarfRegexp('forums?', 'evil')
finally:
ibot.answerUnaddressedQuestions.setValue(answer)
ibot.snarfUnaddressedDefinitions.setValue(learn)
def testAnswerUnaddressed(self):
answer = ibot.answerUnaddressedQuestions()
try:
ibot.answerUnaddressedQuestions.setValue(True)
self.assertSnarfNoResponse('foo is bar')
self.assertSnarfRegexp('foo?', 'bar')
ibot.answerUnaddressedQuestions.setValue(False)
self.assertSnarfNoResponse('foo?', 2)
finally:
ibot.answerUnaddressedQuestions.setValue(answer)
def testReplaceFactoid(self):
answer = ibot.answerUnaddressedQuestions()
learn = ibot.snarfUnaddressedDefinitions()
try:
ibot.answerUnaddressedQuestions.setValue(True)
ibot.snarfUnaddressedDefinitions.setValue(True)
self.assertSnarfNoResponse('forums are good')
self.assertSnarfRegexp('forums?', 'good')
self.assertNotError('no, forums are evil')
self.assertSnarfRegexp('forums?', 'evil')
finally:
ibot.answerUnaddressedQuestions.setValue(answer)
ibot.snarfUnaddressedDefinitions.setValue(learn)
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: