diff --git a/plugins/BadWords.py b/plugins/BadWords.py index 15712158b..c6fdba2a0 100644 --- a/plugins/BadWords.py +++ b/plugins/BadWords.py @@ -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): - "" + """ + + Adds 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): - " [ ...]" + """ [ ...] + + Adds all 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): - "" + """ + + Removes 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): - " [ ...]" + """ [ ...] + + Removes all 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: diff --git a/plugins/OSU.py b/plugins/OSU.py index c5be22874..b1176a289 100644 --- a/plugins/OSU.py +++ b/plugins/OSU.py @@ -249,7 +249,10 @@ buildings = { class OSU(callbacks.Privmsg): threaded = True def osuemail(self, irc, msg, args): - """ """ + """ + + 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): - """""" + """ + + 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()]) diff --git a/test/test.py b/test/test.py index ce8e60c35..06a80e645 100755 --- a/test/test.py +++ b/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: diff --git a/test/test_AdminCommands.py b/test/test_AdminCommands.py index 2c184ff2f..8f5c380a2 100644 --- a/test/test_AdminCommands.py +++ b/test/test_AdminCommands.py @@ -31,7 +31,7 @@ from test import * -class AdminCommandsTestCase(PluginTestCase): +class AdminCommandsTestCase(PluginTestCase, PluginDocumentation): plugins = ('AdminCommands', 'MiscCommands') def testSetprefixchar(self): self.assertNotError('setprefixchar $') diff --git a/test/test_Alias.py b/test/test_Alias.py index 61091f4ca..5665ef90a 100644 --- a/test/test_Alias.py +++ b/test/test_Alias.py @@ -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) diff --git a/test/test_Babelfish.py b/test/test_Babelfish.py index 62ff80e43..e0edd60db 100644 --- a/test/test_Babelfish.py +++ b/test/test_Babelfish.py @@ -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', diff --git a/test/test_BadWords.py b/test/test_BadWords.py index f2f586f57..5f2b18847 100644 --- a/test/test_BadWords.py +++ b/test/test_BadWords.py @@ -31,7 +31,7 @@ from test import * -class BadWordsTestCase(PluginTestCase): +class BadWordsTestCase(PluginTestCase, PluginDocumentation): plugins = ('BadWords', 'Utilities') badwords = ('shit', 'ass') def _test(self): diff --git a/test/test_ChannelDB.py b/test/test_ChannelDB.py index a1d344547..a9b76349f 100644 --- a/test/test_ChannelDB.py +++ b/test/test_ChannelDB.py @@ -31,7 +31,7 @@ from test import * -class ChannelDBTestCase(ChannelPluginTestCase): +class ChannelDBTestCase(ChannelPluginTestCase, PluginDocumentation): plugins = ('ChannelDB',) def test(self): self.assertNotError('channelstats') diff --git a/test/test_Dict.py b/test/test_Dict.py index 91458942c..c844f69fa 100644 --- a/test/test_Dict.py +++ b/test/test_Dict.py @@ -31,7 +31,7 @@ from test import * -class DictTestCase(PluginTestCase): +class DictTestCase(PluginTestCase, PluginDocumentation): plugins = ('Dict', 'MiscCommands') def testHelps(self): self.assertNotError('list Dict') diff --git a/test/test_Factoids.py b/test/test_Factoids.py index c17afe33a..0c50a0c86 100644 --- a/test/test_Factoids.py +++ b/test/test_Factoids.py @@ -31,7 +31,7 @@ from test import * -class FactoidsTestCase(ChannelPluginTestCase): +class FactoidsTestCase(ChannelPluginTestCase, PluginDocumentation): plugins = ('Factoids',) def testRandomfactoid(self): self.assertError('randomfactoid') diff --git a/test/test_FunCommands.py b/test/test_FunCommands.py index 54f42f381..8bac0c0f0 100644 --- a/test/test_FunCommands.py +++ b/test/test_FunCommands.py @@ -35,7 +35,7 @@ import re import utils -class FunCommandsTest(PluginTestCase): +class FunCommandsTest(PluginTestCase, PluginDocumentation): plugins = ('FunCommands',) def testNoErrors(self): self.assertNotError('netstats') diff --git a/test/test_FunDB.py b/test/test_FunDB.py index eda2ab955..0c7064a42 100644 --- a/test/test_FunDB.py +++ b/test/test_FunDB.py @@ -31,7 +31,7 @@ from test import * -class TestFunDB(PluginTestCase): +class TestFunDB(PluginTestCase, PluginDocumentation): plugins = ('FunDB',) def testDbAdd(self): diff --git a/test/test_Gameknot.py b/test/test_Gameknot.py index 00cee4252..0b3847948 100644 --- a/test/test_Gameknot.py +++ b/test/test_Gameknot.py @@ -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') diff --git a/test/test_Http.py b/test/test_Http.py index a351523a3..db91f9d46 100644 --- a/test/test_Http.py +++ b/test/test_Http.py @@ -31,7 +31,7 @@ from test import * -class HttpTest(PluginTestCase): +class HttpTest(PluginTestCase, PluginDocumentation): plugins = ('Http',) def testDeepthought(self): self.assertNotError('deepthought') diff --git a/test/test_IMDB.py b/test/test_IMDB.py index 6a512b5bb..4495ed8d6 100644 --- a/test/test_IMDB.py +++ b/test/test_IMDB.py @@ -31,7 +31,7 @@ from test import * -class IMDBTestCase(PluginTestCase): +class IMDBTestCase(PluginTestCase, PluginDocumentation): plugins = ('IMDB',) def testImdb(self): self.assertNotError('imdb die hard') diff --git a/test/test_MiscCommands.py b/test/test_MiscCommands.py index 278a8f564..ee8658b4f 100644 --- a/test/test_MiscCommands.py +++ b/test/test_MiscCommands.py @@ -31,7 +31,7 @@ from test import * -class MiscCommandsTestCase(PluginTestCase): +class MiscCommandsTestCase(PluginTestCase, PluginDocumentation): plugins = ('MiscCommands',) def testHelp(self): self.assertNotError('help list') diff --git a/test/test_Moobot.py b/test/test_Moobot.py index cc41ecf5d..37a4695aa 100644 --- a/test/test_Moobot.py +++ b/test/test_Moobot.py @@ -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') diff --git a/test/test_OSU.py b/test/test_OSU.py index 5edfc06a9..83f15cd5f 100644 --- a/test/test_OSU.py +++ b/test/test_OSU.py @@ -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') diff --git a/test/test_OwnerCommands.py b/test/test_OwnerCommands.py index f25fcd63e..ae21e0623 100644 --- a/test/test_OwnerCommands.py +++ b/test/test_OwnerCommands.py @@ -33,7 +33,7 @@ from test import * import conf -class OwnerCommandsTestCase(PluginTestCase): +class OwnerCommandsTestCase(PluginTestCase, PluginDocumentation): plugins = ('OwnerCommands',) def testEval(self): conf.allowEval = True diff --git a/test/test_Quotes.py b/test/test_Quotes.py index 845e95d5a..62f2c88a5 100644 --- a/test/test_Quotes.py +++ b/test/test_Quotes.py @@ -31,7 +31,7 @@ from test import * -class QuotesTestCase(PluginTestCase): +class QuotesTestCase(PluginTestCase, PluginDocumentation): plugins = ('Quotes',) def test(self): self.assertRegexp('numquotes #foo', '0') diff --git a/test/test_RSS.py b/test/test_RSS.py index f2700728e..294932c6f 100644 --- a/test/test_RSS.py +++ b/test/test_RSS.py @@ -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') diff --git a/test/test_Topic.py b/test/test_Topic.py new file mode 100644 index 000000000..bf9a3bf7c --- /dev/null +++ b/test/test_Topic.py @@ -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: + diff --git a/test/test_URLSnarfer.py b/test/test_URLSnarfer.py index 400712880..a199fce65 100644 --- a/test/test_URLSnarfer.py +++ b/test/test_URLSnarfer.py @@ -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 diff --git a/test/test_Unix.py b/test/test_Unix.py index 2ca07d836..967c73cb5 100644 --- a/test/test_Unix.py +++ b/test/test_Unix.py @@ -31,7 +31,7 @@ from test import * -class UnixTestCase(PluginTestCase): +class UnixTestCase(PluginTestCase, PluginDocumentation): plugins = ('Unix',) def testSpell(self): self.assertRegexp('spell Strike', 'correctly') diff --git a/test/test_UserCommands.py b/test/test_UserCommands.py new file mode 100644 index 000000000..c0cddd276 --- /dev/null +++ b/test/test_UserCommands.py @@ -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: + diff --git a/test/test_Utilities.py b/test/test_Utilities.py index c7562a45b..f7c4529bd 100644 --- a/test/test_Utilities.py +++ b/test/test_Utilities.py @@ -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)