mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-23 11:09:23 +01:00
Improve some error handling and test some more uses
This commit is contained in:
parent
9ca2732b45
commit
66ec4ab4d7
@ -133,9 +133,15 @@ class Topic(callbacks.Privmsg, configurable.Mixin):
|
||||
itself.
|
||||
"""
|
||||
topics = self._splitTopic(irc.state.getTopic(channel), channel)
|
||||
num = len(topics)
|
||||
if num == 0 or num == 1:
|
||||
irc.error(msg, 'I cannot reorder 1 or fewer topics.')
|
||||
return
|
||||
if len(args) != num:
|
||||
irc.error(msg, 'All topic numbers must be specified.')
|
||||
return
|
||||
order = privmsgs.getArgs(args, required=num)
|
||||
if topics:
|
||||
num = len(topics)
|
||||
order = privmsgs.getArgs(args, required=num)
|
||||
for i,p in enumerate(order):
|
||||
try:
|
||||
p = int(p)
|
||||
@ -150,7 +156,7 @@ class Topic(callbacks.Privmsg, configurable.Mixin):
|
||||
irc.error(msg, 'The positions must be valid integers.')
|
||||
return
|
||||
if utils.sorted(order) != range(num):
|
||||
irc.error(msg, 'All topic numbers must be specified uniquely')
|
||||
irc.error(msg, 'Duplicate topic numbers cannot be specified.')
|
||||
return
|
||||
try:
|
||||
newtopics = [topics[i] for i in order]
|
||||
|
@ -90,7 +90,6 @@ class TopicTestCase(ChannelPluginTestCase, PluginDocumentation):
|
||||
_ = self.getMsg('topic add foo')
|
||||
_ = self.getMsg('topic add bar')
|
||||
_ = self.getMsg('topic add baz')
|
||||
self.assertHelp('topic reorder')
|
||||
self.assertRegexp('topic reorder 2 1 3', r'bar.*foo.*baz')
|
||||
self.assertRegexp('topic reorder 3 -2 1', r'baz.*foo.*bar')
|
||||
self.assertError('topic reorder 0 1 2')
|
||||
@ -99,6 +98,11 @@ class TopicTestCase(ChannelPluginTestCase, PluginDocumentation):
|
||||
self.assertError('topic reorder 2 3 4')
|
||||
self.assertError('topic reorder 1 2 2')
|
||||
self.assertError('topic reorder 1 1 2 3')
|
||||
_ = self.getMsg('topic remove 1')
|
||||
_ = self.getMsg('topic remove 1')
|
||||
self.assertError('topic reorder 1')
|
||||
_ = self.getMsg('topic remove 1')
|
||||
self.assertError('topic reorder 0')
|
||||
|
||||
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user