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