mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-12-24 11:42:52 +01:00
Moved base command to Math (from Fun) and added a test for no escaping ValueError.
This commit is contained in:
parent
626958bef9
commit
69aaea218f
@ -119,14 +119,6 @@ class Fun(callbacks.Privmsg):
|
||||
except ValueError:
|
||||
irc.error('That number doesn\'t map to an 8-bit character.')
|
||||
|
||||
def base(self, irc, msg, args):
|
||||
"""<base> <number>
|
||||
|
||||
Converts from base <base> the number <number>
|
||||
"""
|
||||
(base, number) = privmsgs.getArgs(args, required=2)
|
||||
irc.reply(str(long(number, int(base))))
|
||||
|
||||
def encode(self, irc, msg, args):
|
||||
"""<encoding> <text>
|
||||
|
||||
|
@ -69,6 +69,24 @@ class Math(callbacks.Privmsg):
|
||||
# Then we delete all square brackets, underscores, and whitespace, so no
|
||||
# one can do list comprehensions or call __...__ functions.
|
||||
###
|
||||
def base(self, irc, msg, args):
|
||||
"""<base> <number>
|
||||
|
||||
Converts from base <base> the number <number>
|
||||
"""
|
||||
(base, number) = privmsgs.getArgs(args, required=2)
|
||||
try:
|
||||
base = int(base)
|
||||
if not (2 <= base <= 36):
|
||||
raise ValueError
|
||||
except ValueError:
|
||||
irc.error('<base> must be a number between 2 and 36.')
|
||||
return
|
||||
try:
|
||||
irc.reply(str(long(number, int(base))))
|
||||
except ValueError:
|
||||
irc.error('Invalid <number> for base %s: %s' % (base, number))
|
||||
|
||||
_mathEnv = {'__builtins__': types.ModuleType('__builtins__'), 'i': 1j}
|
||||
_mathEnv.update(math.__dict__)
|
||||
_mathEnv.update(cmath.__dict__)
|
||||
|
@ -33,6 +33,9 @@ from testsupport import *
|
||||
|
||||
class MathTestCase(PluginTestCase, PluginDocumentation):
|
||||
plugins = ('Math',)
|
||||
def testBase(self):
|
||||
self.assertNotRegexp('base 56 asdflkj', 'ValueError')
|
||||
|
||||
def testCalc(self):
|
||||
self.assertResponse('calc 5*0.06', str(5*0.06))
|
||||
self.assertResponse('calc 2.0-7.0', str(2-7))
|
||||
|
Loading…
Reference in New Issue
Block a user