mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-12-24 03:33:11 +01:00
Added PluginDocumentation to test to make sure all commands have documentation.
This commit is contained in:
parent
7023b25223
commit
74d3b7820f
@ -97,7 +97,10 @@ class BadWords(callbacks.Privmsg):
|
||||
self.regexp = re.compile(r'\b('+'|'.join(self.badwords)+r')\b', re.I)
|
||||
|
||||
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'):
|
||||
word = privmsgs.getArgs(args)
|
||||
self.badwords.add(word)
|
||||
@ -109,7 +112,10 @@ class BadWords(callbacks.Privmsg):
|
||||
return
|
||||
|
||||
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'):
|
||||
words = privmsgs.getArgs(args).split()
|
||||
for word in words:
|
||||
@ -122,7 +128,10 @@ class BadWords(callbacks.Privmsg):
|
||||
return
|
||||
|
||||
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'):
|
||||
word = privmsgs.getArgs(args)
|
||||
self.badwords.remove(word)
|
||||
@ -134,7 +143,10 @@ class BadWords(callbacks.Privmsg):
|
||||
return
|
||||
|
||||
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'):
|
||||
words = privmsgs.getArgs(args).split()
|
||||
for word in words:
|
||||
|
@ -249,7 +249,10 @@ buildings = {
|
||||
class OSU(callbacks.Privmsg):
|
||||
threaded = True
|
||||
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)
|
||||
url = 'http://www.ohio-state.edu/cgi-bin/inquiry2.cgi?keyword=%s' % s
|
||||
try:
|
||||
@ -270,7 +273,11 @@ class OSU(callbacks.Privmsg):
|
||||
irc.error(msg, debug.exnToString(e))
|
||||
|
||||
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)
|
||||
try:
|
||||
irc.reply(msg, buildings[building.upper()])
|
||||
|
21
test/test.py
21
test/test.py
@ -102,6 +102,7 @@ nicks += [msg.nick for msg in msgs if msg.nick]
|
||||
def getMsgs(command):
|
||||
return [msg for msg in msgs if msg.command == command]
|
||||
|
||||
|
||||
class PluginTestCase(unittest.TestCase):
|
||||
"""Subclass this to write a test case for a plugin. See test_FunCommands
|
||||
for an example.
|
||||
@ -240,6 +241,26 @@ class ChannelPluginTestCase(PluginTestCase):
|
||||
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__':
|
||||
world.testing = True
|
||||
if len(sys.argv) > 1:
|
||||
|
@ -31,7 +31,7 @@
|
||||
|
||||
from test import *
|
||||
|
||||
class AdminCommandsTestCase(PluginTestCase):
|
||||
class AdminCommandsTestCase(PluginTestCase, PluginDocumentation):
|
||||
plugins = ('AdminCommands', 'MiscCommands')
|
||||
def testSetprefixchar(self):
|
||||
self.assertNotError('setprefixchar $')
|
||||
|
@ -64,7 +64,7 @@ class FunctionsTest(unittest.TestCase):
|
||||
self.assertEqual(Alias.findBiggestDollar('$10 bar $1'), 10)
|
||||
|
||||
|
||||
class AliasTestCase(PluginTestCase):
|
||||
class AliasTestCase(PluginTestCase, PluginDocumentation):
|
||||
plugins = ('Alias', 'FunCommands', 'Utilities')
|
||||
def testSimpleAlias(self):
|
||||
pi = '3.1456926535897932384626433832795028841971693'
|
||||
@ -89,6 +89,11 @@ class AliasTestCase(PluginTestCase):
|
||||
|
||||
def testNonCanonicalName(self):
|
||||
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)
|
||||
|
||||
|
||||
|
||||
|
@ -31,7 +31,7 @@
|
||||
|
||||
from test import *
|
||||
|
||||
class BabelFishTestCase(PluginTestCase):
|
||||
class BabelFishTestCase(PluginTestCase, PluginDocumentation):
|
||||
plugins = ('Babelfish',)
|
||||
def testTranslate(self):
|
||||
self.assertResponse('translate en sp food',
|
||||
|
@ -31,7 +31,7 @@
|
||||
|
||||
from test import *
|
||||
|
||||
class BadWordsTestCase(PluginTestCase):
|
||||
class BadWordsTestCase(PluginTestCase, PluginDocumentation):
|
||||
plugins = ('BadWords', 'Utilities')
|
||||
badwords = ('shit', 'ass')
|
||||
def _test(self):
|
||||
|
@ -31,7 +31,7 @@
|
||||
|
||||
from test import *
|
||||
|
||||
class ChannelDBTestCase(ChannelPluginTestCase):
|
||||
class ChannelDBTestCase(ChannelPluginTestCase, PluginDocumentation):
|
||||
plugins = ('ChannelDB',)
|
||||
def test(self):
|
||||
self.assertNotError('channelstats')
|
||||
|
@ -31,7 +31,7 @@
|
||||
|
||||
from test import *
|
||||
|
||||
class DictTestCase(PluginTestCase):
|
||||
class DictTestCase(PluginTestCase, PluginDocumentation):
|
||||
plugins = ('Dict', 'MiscCommands')
|
||||
def testHelps(self):
|
||||
self.assertNotError('list Dict')
|
||||
|
@ -31,7 +31,7 @@
|
||||
|
||||
from test import *
|
||||
|
||||
class FactoidsTestCase(ChannelPluginTestCase):
|
||||
class FactoidsTestCase(ChannelPluginTestCase, PluginDocumentation):
|
||||
plugins = ('Factoids',)
|
||||
def testRandomfactoid(self):
|
||||
self.assertError('randomfactoid')
|
||||
|
@ -35,7 +35,7 @@ import re
|
||||
|
||||
import utils
|
||||
|
||||
class FunCommandsTest(PluginTestCase):
|
||||
class FunCommandsTest(PluginTestCase, PluginDocumentation):
|
||||
plugins = ('FunCommands',)
|
||||
def testNoErrors(self):
|
||||
self.assertNotError('netstats')
|
||||
|
@ -31,7 +31,7 @@
|
||||
|
||||
from test import *
|
||||
|
||||
class TestFunDB(PluginTestCase):
|
||||
class TestFunDB(PluginTestCase, PluginDocumentation):
|
||||
plugins = ('FunDB',)
|
||||
|
||||
def testDbAdd(self):
|
||||
|
@ -33,7 +33,7 @@ from test import *
|
||||
|
||||
import utils
|
||||
|
||||
class GameknotTestCase(PluginTestCase):
|
||||
class GameknotTestCase(PluginTestCase, PluginDocumentation):
|
||||
plugins = ('Gameknot',)
|
||||
def testGkstats(self):
|
||||
self.assertNotError('gkstats jemfinch')
|
||||
|
@ -31,7 +31,7 @@
|
||||
|
||||
from test import *
|
||||
|
||||
class HttpTest(PluginTestCase):
|
||||
class HttpTest(PluginTestCase, PluginDocumentation):
|
||||
plugins = ('Http',)
|
||||
def testDeepthought(self):
|
||||
self.assertNotError('deepthought')
|
||||
|
@ -31,7 +31,7 @@
|
||||
|
||||
from test import *
|
||||
|
||||
class IMDBTestCase(PluginTestCase):
|
||||
class IMDBTestCase(PluginTestCase, PluginDocumentation):
|
||||
plugins = ('IMDB',)
|
||||
def testImdb(self):
|
||||
self.assertNotError('imdb die hard')
|
||||
|
@ -31,7 +31,7 @@
|
||||
|
||||
from test import *
|
||||
|
||||
class MiscCommandsTestCase(PluginTestCase):
|
||||
class MiscCommandsTestCase(PluginTestCase, PluginDocumentation):
|
||||
plugins = ('MiscCommands',)
|
||||
def testHelp(self):
|
||||
self.assertNotError('help list')
|
||||
|
@ -33,7 +33,7 @@ from test import *
|
||||
|
||||
import base64
|
||||
|
||||
class MoobotTestCase(PluginTestCase):
|
||||
class MoobotTestCase(PluginTestCase, PluginDocumentation):
|
||||
plugins = ('Moobot',)
|
||||
def testMorse(self):
|
||||
self.assertResponse('unmorse [morse jemfinch]', 'JEMFINCH')
|
||||
|
@ -31,7 +31,7 @@
|
||||
|
||||
from test import *
|
||||
|
||||
class OSUTestCase(PluginTestCase):
|
||||
class OSUTestCase(PluginTestCase, PluginDocumentation):
|
||||
plugins = ('OSU',)
|
||||
def testOsuemail(self):
|
||||
self.assertResponse('osuemail jeremiah fincher', 'fincher.8@osu.edu')
|
||||
|
@ -33,7 +33,7 @@ from test import *
|
||||
|
||||
import conf
|
||||
|
||||
class OwnerCommandsTestCase(PluginTestCase):
|
||||
class OwnerCommandsTestCase(PluginTestCase, PluginDocumentation):
|
||||
plugins = ('OwnerCommands',)
|
||||
def testEval(self):
|
||||
conf.allowEval = True
|
||||
|
@ -31,7 +31,7 @@
|
||||
|
||||
from test import *
|
||||
|
||||
class QuotesTestCase(PluginTestCase):
|
||||
class QuotesTestCase(PluginTestCase, PluginDocumentation):
|
||||
plugins = ('Quotes',)
|
||||
def test(self):
|
||||
self.assertRegexp('numquotes #foo', '0')
|
||||
|
@ -31,7 +31,7 @@
|
||||
|
||||
from test import *
|
||||
|
||||
class RSSTestCase(PluginTestCase):
|
||||
class RSSTestCase(PluginTestCase, PluginDocumentation):
|
||||
plugins = ('RSS',)
|
||||
def testRssinfo(self):
|
||||
self.assertNotError('rssinfo http://slashdot.org/slashdot.rss')
|
||||
|
49
test/test_Topic.py
Normal file
49
test/test_Topic.py
Normal 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:
|
||||
|
@ -67,7 +67,7 @@ http://lambda.weblogs.com/xml/rss.xml
|
||||
""".strip().splitlines()
|
||||
|
||||
|
||||
class URLSnarferTestCase(ChannelPluginTestCase):
|
||||
class URLSnarferTestCase(ChannelPluginTestCase, PluginDocumentation):
|
||||
plugins = ('URLSnarfer',)
|
||||
def test(self):
|
||||
counter = 0
|
||||
|
@ -31,7 +31,7 @@
|
||||
|
||||
from test import *
|
||||
|
||||
class UnixTestCase(PluginTestCase):
|
||||
class UnixTestCase(PluginTestCase, PluginDocumentation):
|
||||
plugins = ('Unix',)
|
||||
def testSpell(self):
|
||||
self.assertRegexp('spell Strike', 'correctly')
|
||||
|
41
test/test_UserCommands.py
Normal file
41
test/test_UserCommands.py
Normal 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:
|
||||
|
@ -31,7 +31,7 @@
|
||||
|
||||
from test import *
|
||||
|
||||
class UtilitiesTestCase(PluginTestCase):
|
||||
class UtilitiesTestCase(PluginTestCase, PluginDocumentation):
|
||||
plugins = ('Utilities', 'FunCommands')
|
||||
def testIgnore(self):
|
||||
self.assertNoResponse('ignore foo bar baz', 1)
|
||||
|
Loading…
Reference in New Issue
Block a user