mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-12-23 19:22:45 +01:00
Utilities: add 'sample' command, a basic interface to random.sample()
Also add tests for it.
This commit is contained in:
parent
9d7287a436
commit
6381266cfd
@ -1,7 +1,7 @@
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: Supybot-fr\n"
|
||||
"POT-Creation-Date: 2010-10-20 09:39+CEST\n"
|
||||
"POT-Creation-Date: 2011-02-20 11:27+CET\n"
|
||||
"PO-Revision-Date: \n"
|
||||
"Last-Translator: Valentin Lorentz <progval@gmail.com>\n"
|
||||
"Language-Team: Supybot-fr <progval@gmail.com>\n"
|
||||
@ -71,7 +71,7 @@ msgstr ""
|
||||
msgid ""
|
||||
"<arg> [<arg> ...]\n"
|
||||
"\n"
|
||||
" Shuffles the arguments given it.\n"
|
||||
" Shuffles the arguments given.\n"
|
||||
" "
|
||||
msgstr ""
|
||||
"<argument> [<argument> ...]\n"
|
||||
@ -80,6 +80,17 @@ msgstr ""
|
||||
|
||||
#: plugin.py:109
|
||||
msgid ""
|
||||
"<num> <arg> [<arg> ...]\n"
|
||||
"\n"
|
||||
" Randomly chooses <num> items out of the arguments given.\n"
|
||||
" "
|
||||
msgstr ""
|
||||
"<nombre> <argument> [<argument> ...]\n"
|
||||
"\n"
|
||||
"Choisi de façon aléatoire un certain <nombre> d'<argument>s."
|
||||
|
||||
#: plugin.py:122
|
||||
msgid ""
|
||||
"<command> <text>\n"
|
||||
"\n"
|
||||
" Tokenizes <text> and calls <command> with the resulting arguments.\n"
|
||||
|
@ -5,7 +5,7 @@
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: PACKAGE VERSION\n"
|
||||
"POT-Creation-Date: 2010-10-20 09:39+CEST\n"
|
||||
"POT-Creation-Date: 2011-02-20 11:27+CET\n"
|
||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||
@ -66,13 +66,22 @@ msgstr ""
|
||||
msgid ""
|
||||
"<arg> [<arg> ...]\n"
|
||||
"\n"
|
||||
" Shuffles the arguments given it.\n"
|
||||
" Shuffles the arguments given.\n"
|
||||
" "
|
||||
msgstr ""
|
||||
|
||||
#: plugin.py:109
|
||||
#, docstring
|
||||
msgid ""
|
||||
"<num> <arg> [<arg> ...]\n"
|
||||
"\n"
|
||||
" Randomly chooses <num> items out of the arguments given.\n"
|
||||
" "
|
||||
msgstr ""
|
||||
|
||||
#: plugin.py:122
|
||||
#, docstring
|
||||
msgid ""
|
||||
"<command> <text>\n"
|
||||
"\n"
|
||||
" Tokenizes <text> and calls <command> with the resulting arguments.\n"
|
||||
|
@ -98,12 +98,25 @@ class Utilities(callbacks.Plugin):
|
||||
def shuffle(self, irc, msg, args, things):
|
||||
"""<arg> [<arg> ...]
|
||||
|
||||
Shuffles the arguments given it.
|
||||
Shuffles the arguments given.
|
||||
"""
|
||||
random.shuffle(things)
|
||||
irc.reply(' '.join(things))
|
||||
shuffle = wrap(shuffle, [many('anything')])
|
||||
|
||||
@internationalizeDocstring
|
||||
def sample(self, irc, msg, args, num, things):
|
||||
"""<num> <arg> [<arg> ...]
|
||||
|
||||
Randomly chooses <num> items out of the arguments given.
|
||||
"""
|
||||
try:
|
||||
samp = random.sample(things, num)
|
||||
irc.reply(' '.join(samp))
|
||||
except ValueError, e:
|
||||
irc.error('%s' % (e,))
|
||||
sample = wrap(sample, ['positiveInt', many('anything')])
|
||||
|
||||
@internationalizeDocstring
|
||||
def apply(self, irc, msg, args, command, rest):
|
||||
"""<command> <text>
|
||||
|
@ -59,4 +59,10 @@ class UtilitiesTestCase(PluginTestCase):
|
||||
def testShuffle(self):
|
||||
self.assertResponse('shuffle a', 'a')
|
||||
|
||||
def testSample(self):
|
||||
self.assertResponse('sample 1 a', 'a')
|
||||
self.assertError('sample moo')
|
||||
self.assertError('sample 5 moo')
|
||||
self.assertRegexp('sample 2 a b c', '^[a-c] [a-c]$')
|
||||
|
||||
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:
|
||||
|
Loading…
Reference in New Issue
Block a user