Improve some error handling and test some more uses

This commit is contained in:
James Vega 2003-12-09 15:57:19 +00:00
parent 9ca2732b45
commit 66ec4ab4d7
2 changed files with 14 additions and 4 deletions

View File

@ -133,9 +133,15 @@ class Topic(callbacks.Privmsg, configurable.Mixin):
itself. itself.
""" """
topics = self._splitTopic(irc.state.getTopic(channel), channel) 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: if topics:
num = len(topics)
order = privmsgs.getArgs(args, required=num)
for i,p in enumerate(order): for i,p in enumerate(order):
try: try:
p = int(p) p = int(p)
@ -150,7 +156,7 @@ class Topic(callbacks.Privmsg, configurable.Mixin):
irc.error(msg, 'The positions must be valid integers.') irc.error(msg, 'The positions must be valid integers.')
return return
if utils.sorted(order) != range(num): 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 return
try: try:
newtopics = [topics[i] for i in order] newtopics = [topics[i] for i in order]

View File

@ -90,7 +90,6 @@ class TopicTestCase(ChannelPluginTestCase, PluginDocumentation):
_ = self.getMsg('topic add foo') _ = self.getMsg('topic add foo')
_ = self.getMsg('topic add bar') _ = self.getMsg('topic add bar')
_ = self.getMsg('topic add baz') _ = self.getMsg('topic add baz')
self.assertHelp('topic reorder')
self.assertRegexp('topic reorder 2 1 3', r'bar.*foo.*baz') self.assertRegexp('topic reorder 2 1 3', r'bar.*foo.*baz')
self.assertRegexp('topic reorder 3 -2 1', r'baz.*foo.*bar') self.assertRegexp('topic reorder 3 -2 1', r'baz.*foo.*bar')
self.assertError('topic reorder 0 1 2') 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 2 3 4')
self.assertError('topic reorder 1 2 2') self.assertError('topic reorder 1 2 2')
self.assertError('topic reorder 1 1 2 3') 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: # vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: