mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-23 10:34:19 +01:00
Fixed some bugs and cleaned up the test suite.
This commit is contained in:
parent
084fe1854f
commit
c2f179cd0d
@ -67,6 +67,9 @@ class Topic(callbacks.Privmsg):
|
|||||||
topicSeparator = ' || '
|
topicSeparator = ' || '
|
||||||
topicFormatter = '%s (%s)'
|
topicFormatter = '%s (%s)'
|
||||||
topicUnformatter = re.compile('(.*) \((\S+)\)')
|
topicUnformatter = re.compile('(.*) \((\S+)\)')
|
||||||
|
def _splitTopic(self, topic):
|
||||||
|
return filter(None, topic.split(self.topicSeparator))
|
||||||
|
|
||||||
def add(self, irc, msg, args, channel):
|
def add(self, irc, msg, args, channel):
|
||||||
"""[<channel>] <topic>
|
"""[<channel>] <topic>
|
||||||
|
|
||||||
@ -99,10 +102,17 @@ class Topic(callbacks.Privmsg):
|
|||||||
message isn't sent in the channel itself.
|
message isn't sent in the channel itself.
|
||||||
"""
|
"""
|
||||||
newtopic = irc.state.getTopic(channel)
|
newtopic = irc.state.getTopic(channel)
|
||||||
topics = newtopic.split(self.topicSeparator)
|
topics = self._splitTopic(irc.state.getTopic(channel))
|
||||||
|
if len(topics) == 0 or len(topics) == 1:
|
||||||
|
irc.error(msg, 'I can\'t shuffle 1 or fewer topics.')
|
||||||
|
return
|
||||||
|
elif len(topics) == 2:
|
||||||
|
topics.reverse()
|
||||||
|
newtopic = self.topicSeparator.join(topics)
|
||||||
|
else:
|
||||||
random.shuffle(topics)
|
random.shuffle(topics)
|
||||||
newtopic = self.topicSeparator.join(topics)
|
newtopic = self.topicSeparator.join(topics)
|
||||||
while len(topics) > 1 and newtopic == irc.state.getTopic(channel):
|
while newtopic == irc.state.getTopic(channel):
|
||||||
random.shuffle(topics)
|
random.shuffle(topics)
|
||||||
newtopic = self.topicSeparator.join(topics)
|
newtopic = self.topicSeparator.join(topics)
|
||||||
irc.queueMsg(ircmsgs.topic(channel, newtopic))
|
irc.queueMsg(ircmsgs.topic(channel, newtopic))
|
||||||
@ -118,17 +128,22 @@ class Topic(callbacks.Privmsg):
|
|||||||
number = privmsgs.getArgs(args)
|
number = privmsgs.getArgs(args)
|
||||||
try:
|
try:
|
||||||
number = int(number)
|
number = int(number)
|
||||||
if number >= 0:
|
if number > 0:
|
||||||
number -= 1
|
number -= 1
|
||||||
|
elif number == 0:
|
||||||
|
irc.error(msg, 'That\'s not a valid topic number.')
|
||||||
|
return
|
||||||
except ValueError:
|
except ValueError:
|
||||||
irc.error(msg, 'The argument must be a valid integer.')
|
irc.error(msg, 'The argument must be a valid integer.')
|
||||||
return
|
return
|
||||||
topics = irc.state.getTopic(channel).split(self.topicSeparator)
|
topics = self._splitTopic(irc.state.getTopic(channel))
|
||||||
|
if topics:
|
||||||
try:
|
try:
|
||||||
irc.reply(msg, topics[number])
|
irc.reply(msg, topics[number])
|
||||||
except IndexError:
|
except IndexError:
|
||||||
irc.error(msg, 'That\'s not a valid topic.')
|
irc.error(msg, 'That\'s not a valid topic.')
|
||||||
return
|
else:
|
||||||
|
irc.error(msg, 'There are no topics to get.')
|
||||||
get = privmsgs.channel(get)
|
get = privmsgs.channel(get)
|
||||||
|
|
||||||
def change(self, irc, msg, args, channel):
|
def change(self, irc, msg, args, channel):
|
||||||
@ -143,8 +158,11 @@ class Topic(callbacks.Privmsg):
|
|||||||
(number, regexp) = privmsgs.getArgs(args, needed=2)
|
(number, regexp) = privmsgs.getArgs(args, needed=2)
|
||||||
try:
|
try:
|
||||||
number = int(number)
|
number = int(number)
|
||||||
if number >= 0:
|
if number > 0:
|
||||||
number -= 1
|
number -= 1
|
||||||
|
elif number == 0:
|
||||||
|
irc.error(msg, 'That\'s not a valid topic number.')
|
||||||
|
return
|
||||||
except ValueError:
|
except ValueError:
|
||||||
irc.error(msg, 'The <number> argument must be a number.')
|
irc.error(msg, 'The <number> argument must be a number.')
|
||||||
return
|
return
|
||||||
@ -156,7 +174,10 @@ class Topic(callbacks.Privmsg):
|
|||||||
except re.error, e:
|
except re.error, e:
|
||||||
irc.error(msg, debug.exnToString(e))
|
irc.error(msg, debug.exnToString(e))
|
||||||
return
|
return
|
||||||
topics = irc.state.getTopic(channel).split(self.topicSeparator)
|
topics = self._splitTopic(irc.state.getTopic(channel))
|
||||||
|
if not topics:
|
||||||
|
irc.error(msg, 'There are no topics to change.')
|
||||||
|
return
|
||||||
topic = topics.pop(number)
|
topic = topics.pop(number)
|
||||||
match = self.topicUnformatter.match(topic)
|
match = self.topicUnformatter.match(topic)
|
||||||
if match is None:
|
if match is None:
|
||||||
@ -190,12 +211,15 @@ class Topic(callbacks.Privmsg):
|
|||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
number = int(privmsgs.getArgs(args))
|
number = int(privmsgs.getArgs(args))
|
||||||
if number >= 0:
|
if number > 0:
|
||||||
number -= 1
|
number -= 1
|
||||||
|
elif number == 0:
|
||||||
|
irc.error(msg, 'That\'s not a valid topic number.')
|
||||||
|
return
|
||||||
except ValueError:
|
except ValueError:
|
||||||
irc.error(msg, 'The argument must be a number.')
|
irc.error(msg, 'The argument must be a number.')
|
||||||
return
|
return
|
||||||
topics = irc.state.getTopic(channel).split(self.topicSeparator)
|
topics = self._splitTopic(irc.state.getTopic(channel))
|
||||||
try:
|
try:
|
||||||
topic = topics.pop(number)
|
topic = topics.pop(number)
|
||||||
except IndexError:
|
except IndexError:
|
||||||
|
@ -31,33 +31,51 @@
|
|||||||
|
|
||||||
from test import *
|
from test import *
|
||||||
|
|
||||||
class TopicTestCase(PluginTestCase, PluginDocumentation):
|
class TopicTestCase(ChannelPluginTestCase, PluginDocumentation):
|
||||||
plugins = ('Topic', 'Admin')
|
plugins = ('Topic',)
|
||||||
def testAddtopic(self):
|
def testTopicRemove(self):
|
||||||
_ = self.getMsg('join #foo')
|
self.assertError('topic remove 1')
|
||||||
_ = self.getMsg(' ') # Get the WHO.
|
_ = self.getMsg('topic add foo')
|
||||||
m = self.getMsg('topic add #foo foo')
|
_ = self.getMsg('topic add bar')
|
||||||
self.assertEqual(m.command, 'TOPIC')
|
_ = self.getMsg('topic add baz')
|
||||||
self.assertEqual(m.args[0], '#foo')
|
self.assertError('topic remove 0')
|
||||||
self.assertEqual(m.args[1], 'foo (test)')
|
self.assertNotError('topic remove 3')
|
||||||
m = self.getMsg('topic add #foo bar')
|
self.assertNotError('topic remove 2')
|
||||||
self.assertEqual(m.command, 'TOPIC')
|
self.assertNotError('topic remove 1')
|
||||||
self.assertEqual(m.args[0], '#foo')
|
self.assertError('topic remove 1')
|
||||||
|
|
||||||
def testChangetopic(self):
|
def testTopicGet(self):
|
||||||
_ = self.getMsg('join #foo')
|
self.assertError('topic get 1')
|
||||||
_ = self.getMsg(' ')
|
_ = self.getMsg('topic add foo')
|
||||||
_ = self.getMsg('topic add #foo foo')
|
_ = self.getMsg('topic add bar')
|
||||||
_ = self.getMsg('topic add #foo bar')
|
_ = self.getMsg('topic add baz')
|
||||||
_ = self.getMsg('topic add #foo baz')
|
self.assertRegexp('topic get 1', '^foo')
|
||||||
self.assertRegexp('topic change #foo -1 s/baz/biff/',
|
self.assertRegexp('topic get 2', '^bar')
|
||||||
|
self.assertRegexp('topic get 3', '^baz')
|
||||||
|
self.assertError('topic get 0')
|
||||||
|
|
||||||
|
def testTopicAdd(self):
|
||||||
|
m = self.getMsg('topic add foo')
|
||||||
|
self.assertEqual(m.command, 'TOPIC')
|
||||||
|
self.assertEqual(m.args[0], self.channel)
|
||||||
|
self.assertEqual(m.args[1], 'foo (test)')
|
||||||
|
m = self.getMsg('topic add bar')
|
||||||
|
self.assertEqual(m.command, 'TOPIC')
|
||||||
|
self.assertEqual(m.args[0], self.channel)
|
||||||
|
|
||||||
|
def testTopicChange(self):
|
||||||
|
_ = self.getMsg('topic add foo')
|
||||||
|
_ = self.getMsg('topic add bar')
|
||||||
|
_ = self.getMsg('topic add baz')
|
||||||
|
self.assertRegexp('topic change -1 s/baz/biff/',
|
||||||
r'foo.*bar.*biff')
|
r'foo.*bar.*biff')
|
||||||
self.assertRegexp('topic change #foo 2 s/bar/baz/',
|
self.assertRegexp('topic change 2 s/bar/baz/',
|
||||||
r'foo.*baz.*biff')
|
r'foo.*baz.*biff')
|
||||||
self.assertRegexp('topic change #foo 1 s/foo/bar/',
|
self.assertRegexp('topic change 1 s/foo/bar/',
|
||||||
r'bar.*baz.*biff')
|
r'bar.*baz.*biff')
|
||||||
self.assertRegexp('topic change #foo -2 s/baz/bazz/',
|
self.assertRegexp('topic change -2 s/baz/bazz/',
|
||||||
r'bar.*bazz.*biff')
|
r'bar.*bazz.*biff')
|
||||||
|
self.assertError('topic change 0 s/baz/biff/')
|
||||||
|
|
||||||
|
|
||||||
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
||||||
|
Loading…
Reference in New Issue
Block a user