MoobotFactoids: add check_same_thread=False to the sqlite3 connect calls, so it doesn't complain. (thanks malex!)

also fix up the code a bit so it doesn't fail the tests, and doesn't require presence of plain sqlite.
This commit is contained in:
Daniel Folkinshteyn 2010-08-02 17:48:51 -04:00
parent 3a181b6dd2
commit 9398025088
2 changed files with 6 additions and 7 deletions

View File

@ -107,11 +107,11 @@ class SqliteMoobotDB(object):
filename = plugins.makeChannelFilename(self.filename, channel) filename = plugins.makeChannelFilename(self.filename, channel)
if os.path.exists(filename): if os.path.exists(filename):
db = sqlite3.connect(filename) db = sqlite3.connect(filename, check_same_thread = False)
db.text_factory = str db.text_factory = str
self.dbs[channel] = db self.dbs[channel] = db
return db return db
db = sqlite3.connect(filename) db = sqlite3.connect(filename, check_same_thread = False)
db.text_factory = str db.text_factory = str
self.dbs[channel] = db self.dbs[channel] = db
cursor = db.cursor() cursor = db.cursor()
@ -281,7 +281,7 @@ class SqliteMoobotDB(object):
results = cursor.fetchall() results = cursor.fetchall()
return results return results
MoobotDB = plugins.DB('MoobotFactoids', {'sqlite': SqliteMoobotDB}) MoobotDB = plugins.DB('MoobotFactoids', {'sqlite3': SqliteMoobotDB})
class MoobotFactoids(callbacks.Plugin): class MoobotFactoids(callbacks.Plugin):
"""Add the help for "@help MoobotFactoids" here (assuming you don't implement a MoobotFactoids """Add the help for "@help MoobotFactoids" here (assuming you don't implement a MoobotFactoids

View File

@ -31,11 +31,10 @@
from supybot.test import * from supybot.test import *
#import supybot.plugin as plugin #import supybot.plugin as plugin
import supybot.ircutils as ircutils import supybot.ircutils as ircutils
try: try:
import sqlite import sqlite3
except ImportError: except ImportError:
sqlite = None from pysqlite2 import dbapi2 as sqlite3 # for python2.4
MF = plugin.loadPluginModule('MoobotFactoids') MF = plugin.loadPluginModule('MoobotFactoids')
MFconf = conf.supybot.plugins.MoobotFactoids MFconf = conf.supybot.plugins.MoobotFactoids
@ -223,7 +222,7 @@ class FactoidsTestCase(ChannelPluginTestCase):
self.assertRegexp('most authored', self.assertRegexp('most authored',
'Most prolific authors:.*moo.*(1).*boo.*(1)') 'Most prolific authors:.*moo.*(1).*boo.*(1)')
self.assertRegexp('most recent', self.assertRegexp('most recent',
"2 latest factoids:.*mogle.*moogle.*") "2 latest factoids:.*moogle.*mogle.*")
self.assertResponse('moogle', 'moo') self.assertResponse('moogle', 'moo')
self.assertRegexp('most popular', self.assertRegexp('most popular',
"Top 1 requested factoid:.*moogle.*(2)") "Top 1 requested factoid:.*moogle.*(2)")