From 1b8d655738b4e4138784af931c9c875d3530f128 Mon Sep 17 00:00:00 2001 From: Jeremy Fincher Date: Tue, 2 Dec 2003 18:37:39 +0000 Subject: [PATCH] Added help strings to lookups. --- plugins/Lookup.py | 12 +++++++++++- test/test_Lookup.py | 1 + test/testsupport.py | 3 ++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/plugins/Lookup.py b/plugins/Lookup.py index 497cbf869..9d8ac7dfa 100644 --- a/plugins/Lookup.py +++ b/plugins/Lookup.py @@ -49,7 +49,6 @@ import utils import privmsgs import callbacks - def configure(onStart, afterConnect, advanced): # This will be called by setup.py to configure this module. onStart and # afterConnect are both lists. Append to onStart the commands you would @@ -157,8 +156,19 @@ class Lookup(callbacks.Privmsg): def f(self, irc, msg, args): args.insert(0, name) self._lookup(irc, msg, args) + db = getDb() + cursor = db.cursor() + cursor.execute("""SELECT COUNT(*) FROM %s""" % name) + rows = cursor.fetchone()[0] + docstring = """[] + + If is given, looks up in the %s database. Otherwise, + returns a random key: value pair from the database. There are + %s in the database. + """ % (name, utils.nItems(rows, name)) f = types.FunctionType(f.func_code, f.func_globals, f.func_name, closure=f.func_closure) + f.__doc__ = docstring setattr(self.__class__, name, f) def _lookup(self, irc, msg, args): diff --git a/test/test_Lookup.py b/test/test_Lookup.py index 18d018b91..0915a2f5c 100644 --- a/test/test_Lookup.py +++ b/test/test_Lookup.py @@ -64,6 +64,7 @@ if sqlite: self.assertResponse('test your mom', 'my mom') self.assertError('test something not in there') self.assertResponse('test foo:bar', 'baz') + self.assertHelp('help test') self.assertNotError('lookup remove test') try: original = conf.replyWhenNotCommand diff --git a/test/testsupport.py b/test/testsupport.py index 058cfaf16..839cbb259 100644 --- a/test/testsupport.py +++ b/test/testsupport.py @@ -193,7 +193,8 @@ class PluginTestCase(unittest.TestCase): m = self._feedMsg(query) if m is None: raise TimeoutError, query - self.failUnless(lastGetHelp in m.args[1]) + self.failUnless(lastGetHelp in m.args[1], + '%s is not the help (%s)' % (m.args[1], lastGetHelp)) def assertNoResponse(self, query, timeout=None): m = self._feedMsg(query, timeout)