Added PluginDocumentation to test to make sure all commands have documentation.

This commit is contained in:
Jeremy Fincher 2003-09-06 06:23:03 +00:00
parent 7023b25223
commit 74d3b7820f
26 changed files with 162 additions and 27 deletions

View File

@ -97,7 +97,10 @@ class BadWords(callbacks.Privmsg):
self.regexp = re.compile(r'\b('+'|'.join(self.badwords)+r')\b', re.I) self.regexp = re.compile(r'\b('+'|'.join(self.badwords)+r')\b', re.I)
def addbadword(self, irc, msg, args): def addbadword(self, irc, msg, args):
"<word>" """<word>
Adds <word> to the list of words the bot isn't to say.
"""
if ircdb.checkCapability(msg.prefix, 'admin'): if ircdb.checkCapability(msg.prefix, 'admin'):
word = privmsgs.getArgs(args) word = privmsgs.getArgs(args)
self.badwords.add(word) self.badwords.add(word)
@ -109,7 +112,10 @@ class BadWords(callbacks.Privmsg):
return return
def addbadwords(self, irc, msg, args): def addbadwords(self, irc, msg, args):
"<word> [<word> ...]" """<word> [<word> ...]
Adds all <word>s to the list of words the bot isn't to say.
"""
if ircdb.checkCapability(msg.prefix, 'admin'): if ircdb.checkCapability(msg.prefix, 'admin'):
words = privmsgs.getArgs(args).split() words = privmsgs.getArgs(args).split()
for word in words: for word in words:
@ -122,7 +128,10 @@ class BadWords(callbacks.Privmsg):
return return
def removebadword(self, irc, msg, args): def removebadword(self, irc, msg, args):
"<word>" """<word>
Removes <word> from the list of words the bot isn't to say.
"""
if ircdb.checkCapability(msg.prefix, 'admin'): if ircdb.checkCapability(msg.prefix, 'admin'):
word = privmsgs.getArgs(args) word = privmsgs.getArgs(args)
self.badwords.remove(word) self.badwords.remove(word)
@ -134,7 +143,10 @@ class BadWords(callbacks.Privmsg):
return return
def removebadwords(self, irc, msg, args): def removebadwords(self, irc, msg, args):
"<word> [<word> ...]" """<word> [<word> ...]
Removes all <word>s from the list of words the bot isn't to say.
"""
if ircdb.checkCapability(msg.prefix, 'admin'): if ircdb.checkCapability(msg.prefix, 'admin'):
words = privmsgs.getArgs(args).split() words = privmsgs.getArgs(args).split()
for word in words: for word in words:

View File

@ -249,7 +249,10 @@ buildings = {
class OSU(callbacks.Privmsg): class OSU(callbacks.Privmsg):
threaded = True threaded = True
def osuemail(self, irc, msg, args): def osuemail(self, irc, msg, args):
"""<first name> <middle initial> <last name>""" """<first name> <middle initial> <last name>
Returns possible email address matches for the given name.
"""
s = '.'.join(args) s = '.'.join(args)
url = 'http://www.ohio-state.edu/cgi-bin/inquiry2.cgi?keyword=%s' % s url = 'http://www.ohio-state.edu/cgi-bin/inquiry2.cgi?keyword=%s' % s
try: try:
@ -270,7 +273,11 @@ class OSU(callbacks.Privmsg):
irc.error(msg, debug.exnToString(e)) irc.error(msg, debug.exnToString(e))
def osubuilding(self, irc, msg, args): def osubuilding(self, irc, msg, args):
"""<building abbreviation>""" """<building abbreviation>
Returns the address and full name of an OSU building based on its
standard two-letter abbreviation.
"""
building = privmsgs.getArgs(args) building = privmsgs.getArgs(args)
try: try:
irc.reply(msg, buildings[building.upper()]) irc.reply(msg, buildings[building.upper()])

View File

@ -102,6 +102,7 @@ nicks += [msg.nick for msg in msgs if msg.nick]
def getMsgs(command): def getMsgs(command):
return [msg for msg in msgs if msg.command == command] return [msg for msg in msgs if msg.command == command]
class PluginTestCase(unittest.TestCase): class PluginTestCase(unittest.TestCase):
"""Subclass this to write a test case for a plugin. See test_FunCommands """Subclass this to write a test case for a plugin. See test_FunCommands
for an example. for an example.
@ -240,6 +241,26 @@ class ChannelPluginTestCase(PluginTestCase):
prefix=self.prefix)) prefix=self.prefix))
class PluginDocumentation:
def testAllCommandsHaveHelp(self):
for cb in self.irc.callbacks:
if hasattr(cb, 'isCommand'):
for attr in cb.__class__.__dict__:
if cb.isCommand(attr):
self.failUnless(getattr(cb, attr).__doc__,
'%s has no help' % attr)
def testAllCommandsHaveMorehelp(self):
for cb in self.irc.callbacks:
if hasattr(cb, 'isCommand'):
for attr in cb.__class__.__dict__:
if cb.isCommand(attr):
command = getattr(cb, attr)
helps = command.__doc__
self.failUnless(helps and len(helps.splitlines()) >= 3,
'%s has no morehelp' % attr)
if __name__ == '__main__': if __name__ == '__main__':
world.testing = True world.testing = True
if len(sys.argv) > 1: if len(sys.argv) > 1:

View File

@ -31,7 +31,7 @@
from test import * from test import *
class AdminCommandsTestCase(PluginTestCase): class AdminCommandsTestCase(PluginTestCase, PluginDocumentation):
plugins = ('AdminCommands', 'MiscCommands') plugins = ('AdminCommands', 'MiscCommands')
def testSetprefixchar(self): def testSetprefixchar(self):
self.assertNotError('setprefixchar $') self.assertNotError('setprefixchar $')

View File

@ -64,7 +64,7 @@ class FunctionsTest(unittest.TestCase):
self.assertEqual(Alias.findBiggestDollar('$10 bar $1'), 10) self.assertEqual(Alias.findBiggestDollar('$10 bar $1'), 10)
class AliasTestCase(PluginTestCase): class AliasTestCase(PluginTestCase, PluginDocumentation):
plugins = ('Alias', 'FunCommands', 'Utilities') plugins = ('Alias', 'FunCommands', 'Utilities')
def testSimpleAlias(self): def testSimpleAlias(self):
pi = '3.1456926535897932384626433832795028841971693' pi = '3.1456926535897932384626433832795028841971693'
@ -89,6 +89,11 @@ class AliasTestCase(PluginTestCase):
def testNonCanonicalName(self): def testNonCanonicalName(self):
self.assertError('alias FOO foo') self.assertError('alias FOO foo')
## def testNotCannotNestRaised(self):
## self.assertNotError('alias punish "lart $channel $1"')
## self.assertNotError('punish #foo bugs')
## self.assertNoResponse('blah blah blah', 2)

View File

@ -31,7 +31,7 @@
from test import * from test import *
class BabelFishTestCase(PluginTestCase): class BabelFishTestCase(PluginTestCase, PluginDocumentation):
plugins = ('Babelfish',) plugins = ('Babelfish',)
def testTranslate(self): def testTranslate(self):
self.assertResponse('translate en sp food', self.assertResponse('translate en sp food',

View File

@ -31,7 +31,7 @@
from test import * from test import *
class BadWordsTestCase(PluginTestCase): class BadWordsTestCase(PluginTestCase, PluginDocumentation):
plugins = ('BadWords', 'Utilities') plugins = ('BadWords', 'Utilities')
badwords = ('shit', 'ass') badwords = ('shit', 'ass')
def _test(self): def _test(self):

View File

@ -31,7 +31,7 @@
from test import * from test import *
class ChannelDBTestCase(ChannelPluginTestCase): class ChannelDBTestCase(ChannelPluginTestCase, PluginDocumentation):
plugins = ('ChannelDB',) plugins = ('ChannelDB',)
def test(self): def test(self):
self.assertNotError('channelstats') self.assertNotError('channelstats')

View File

@ -31,7 +31,7 @@
from test import * from test import *
class DictTestCase(PluginTestCase): class DictTestCase(PluginTestCase, PluginDocumentation):
plugins = ('Dict', 'MiscCommands') plugins = ('Dict', 'MiscCommands')
def testHelps(self): def testHelps(self):
self.assertNotError('list Dict') self.assertNotError('list Dict')

View File

@ -31,7 +31,7 @@
from test import * from test import *
class FactoidsTestCase(ChannelPluginTestCase): class FactoidsTestCase(ChannelPluginTestCase, PluginDocumentation):
plugins = ('Factoids',) plugins = ('Factoids',)
def testRandomfactoid(self): def testRandomfactoid(self):
self.assertError('randomfactoid') self.assertError('randomfactoid')

View File

@ -35,7 +35,7 @@ import re
import utils import utils
class FunCommandsTest(PluginTestCase): class FunCommandsTest(PluginTestCase, PluginDocumentation):
plugins = ('FunCommands',) plugins = ('FunCommands',)
def testNoErrors(self): def testNoErrors(self):
self.assertNotError('netstats') self.assertNotError('netstats')

View File

@ -31,7 +31,7 @@
from test import * from test import *
class TestFunDB(PluginTestCase): class TestFunDB(PluginTestCase, PluginDocumentation):
plugins = ('FunDB',) plugins = ('FunDB',)
def testDbAdd(self): def testDbAdd(self):

View File

@ -33,7 +33,7 @@ from test import *
import utils import utils
class GameknotTestCase(PluginTestCase): class GameknotTestCase(PluginTestCase, PluginDocumentation):
plugins = ('Gameknot',) plugins = ('Gameknot',)
def testGkstats(self): def testGkstats(self):
self.assertNotError('gkstats jemfinch') self.assertNotError('gkstats jemfinch')

View File

@ -31,7 +31,7 @@
from test import * from test import *
class HttpTest(PluginTestCase): class HttpTest(PluginTestCase, PluginDocumentation):
plugins = ('Http',) plugins = ('Http',)
def testDeepthought(self): def testDeepthought(self):
self.assertNotError('deepthought') self.assertNotError('deepthought')

View File

@ -31,7 +31,7 @@
from test import * from test import *
class IMDBTestCase(PluginTestCase): class IMDBTestCase(PluginTestCase, PluginDocumentation):
plugins = ('IMDB',) plugins = ('IMDB',)
def testImdb(self): def testImdb(self):
self.assertNotError('imdb die hard') self.assertNotError('imdb die hard')

View File

@ -31,7 +31,7 @@
from test import * from test import *
class MiscCommandsTestCase(PluginTestCase): class MiscCommandsTestCase(PluginTestCase, PluginDocumentation):
plugins = ('MiscCommands',) plugins = ('MiscCommands',)
def testHelp(self): def testHelp(self):
self.assertNotError('help list') self.assertNotError('help list')

View File

@ -33,7 +33,7 @@ from test import *
import base64 import base64
class MoobotTestCase(PluginTestCase): class MoobotTestCase(PluginTestCase, PluginDocumentation):
plugins = ('Moobot',) plugins = ('Moobot',)
def testMorse(self): def testMorse(self):
self.assertResponse('unmorse [morse jemfinch]', 'JEMFINCH') self.assertResponse('unmorse [morse jemfinch]', 'JEMFINCH')

View File

@ -31,7 +31,7 @@
from test import * from test import *
class OSUTestCase(PluginTestCase): class OSUTestCase(PluginTestCase, PluginDocumentation):
plugins = ('OSU',) plugins = ('OSU',)
def testOsuemail(self): def testOsuemail(self):
self.assertResponse('osuemail jeremiah fincher', 'fincher.8@osu.edu') self.assertResponse('osuemail jeremiah fincher', 'fincher.8@osu.edu')

View File

@ -33,7 +33,7 @@ from test import *
import conf import conf
class OwnerCommandsTestCase(PluginTestCase): class OwnerCommandsTestCase(PluginTestCase, PluginDocumentation):
plugins = ('OwnerCommands',) plugins = ('OwnerCommands',)
def testEval(self): def testEval(self):
conf.allowEval = True conf.allowEval = True

View File

@ -31,7 +31,7 @@
from test import * from test import *
class QuotesTestCase(PluginTestCase): class QuotesTestCase(PluginTestCase, PluginDocumentation):
plugins = ('Quotes',) plugins = ('Quotes',)
def test(self): def test(self):
self.assertRegexp('numquotes #foo', '0') self.assertRegexp('numquotes #foo', '0')

View File

@ -31,7 +31,7 @@
from test import * from test import *
class RSSTestCase(PluginTestCase): class RSSTestCase(PluginTestCase, PluginDocumentation):
plugins = ('RSS',) plugins = ('RSS',)
def testRssinfo(self): def testRssinfo(self):
self.assertNotError('rssinfo http://slashdot.org/slashdot.rss') self.assertNotError('rssinfo http://slashdot.org/slashdot.rss')

49
test/test_Topic.py Normal file
View File

@ -0,0 +1,49 @@
#!/usr/bin/env python
###
# Copyright (c) 2002, Jeremiah Fincher
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice,
# this list of conditions, and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions, and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of the author of this software nor the name of
# contributors to this software may be used to endorse or promote products
# derived from this software without specific prior written consent.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
###
from test import *
class TopicTestCase(PluginTestCase, PluginDocumentation):
plugins = ('Topic', 'AdminCommands')
def testAddtopic(self):
_ = self.getMsg('join #foo')
_ = self.getMsg(' ') # Get the WHO.
m = self.getMsg('addtopic #foo foo')
self.assertEqual(m.command, 'TOPIC')
self.assertEqual(m.args[0], '#foo')
self.assertEqual(m.args[1], 'foo (test)')
m = self.getMsg('addtopic #foo bar')
self.assertEqual(m.command, 'TOPIC')
self.assertEqual(m.args[0], '#foo')
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:

View File

@ -67,7 +67,7 @@ http://lambda.weblogs.com/xml/rss.xml
""".strip().splitlines() """.strip().splitlines()
class URLSnarferTestCase(ChannelPluginTestCase): class URLSnarferTestCase(ChannelPluginTestCase, PluginDocumentation):
plugins = ('URLSnarfer',) plugins = ('URLSnarfer',)
def test(self): def test(self):
counter = 0 counter = 0

View File

@ -31,7 +31,7 @@
from test import * from test import *
class UnixTestCase(PluginTestCase): class UnixTestCase(PluginTestCase, PluginDocumentation):
plugins = ('Unix',) plugins = ('Unix',)
def testSpell(self): def testSpell(self):
self.assertRegexp('spell Strike', 'correctly') self.assertRegexp('spell Strike', 'correctly')

41
test/test_UserCommands.py Normal file
View File

@ -0,0 +1,41 @@
#!/usr/bin/env python
###
# Copyright (c) 2002, Jeremiah Fincher
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice,
# this list of conditions, and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions, and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of the author of this software nor the name of
# contributors to this software may be used to endorse or promote products
# derived from this software without specific prior written consent.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
###
from test import *
class UserCommandsTestCase(PluginTestCase, PluginDocumentation):
plugins = ('UserCommands',)
## def testRegister(self):
## self.assertNotError('register foo bar')
## self.assertError('register foo baz')
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:

View File

@ -31,7 +31,7 @@
from test import * from test import *
class UtilitiesTestCase(PluginTestCase): class UtilitiesTestCase(PluginTestCase, PluginDocumentation):
plugins = ('Utilities', 'FunCommands') plugins = ('Utilities', 'FunCommands')
def testIgnore(self): def testIgnore(self):
self.assertNoResponse('ignore foo bar baz', 1) self.assertNoResponse('ignore foo bar baz', 1)