From 8914543d352acd76dad9169a9f2ebf17f2ceef7d Mon Sep 17 00:00:00 2001 From: Jeremy Fincher Date: Thu, 23 Oct 2003 04:21:40 +0000 Subject: [PATCH] Made optional in convert. --- plugins/Math.py | 10 +++++++--- test/test_Math.py | 1 + 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/plugins/Math.py b/plugins/Math.py index 01ce0fb20..153ba87b3 100644 --- a/plugins/Math.py +++ b/plugins/Math.py @@ -212,13 +212,17 @@ class Math(callbacks.Privmsg): if isinstance(v, unum.Unum): _convertEnv[k.lower()] = v def convert(self, irc, msg, args): - """ to + """[] to Converts the first number of to the . Valid units expressions include the standard Python math operators applied to valid - units. + units. If isn't given, it defaults to 1. """ - (n, unit1, to, unit2) = privmsgs.getArgs(args, needed=4) + if args and args[0].isdigit(): + n = args.pop(0) + else: + n = 1 + (unit1, to, unit2) = privmsgs.getArgs(args, needed=3) if to != 'to': raise callbacks.ArgumentError try: diff --git a/test/test_Math.py b/test/test_Math.py index 564a279e9..a9150bef7 100644 --- a/test/test_Math.py +++ b/test/test_Math.py @@ -62,6 +62,7 @@ class MathTestCase(PluginTestCase, PluginDocumentation): def testConvert(self): self.assertResponse('convert 1 m to cm', '100.0 cm') + self.assertResponse('convert m to cm', '100.0 cm') self.assertResponse('convert 1 M to cm', '100.0 cm') self.assertResponse('convert 1 m to CM', '100.0 cm') self.assertResponse('convert 1 m to cM', '100.0 cm')