Skip to content

Commit 0371d0b

Browse files
authored
Merge pull request #2530 from sopel-irc/more-calc-tests
calc: improve help output, test coverage (now 100%)
2 parents 5de26c1 + 5854e8a commit 0371d0b

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

sopel/builtins/calc.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,27 @@
1212

1313

1414
@plugin.command('c', 'calc')
15+
@plugin.example('.c', 'Nothing to calculate.')
16+
@plugin.example('.c foo * bar', "Can't process expression: Node type 'Name' is not supported.")
17+
@plugin.example('.c 10 / 0', 'Division by zero is not supported in this universe.')
18+
@plugin.example('.c 10\\2', 'Invalid syntax')
19+
@plugin.example('.c (10**1000000)**2',
20+
"Error running calculation: "
21+
"ValueError('Pow expression too complex to calculate.')")
22+
@plugin.example('.c (10**100000)**2 * (10**100000)**2',
23+
"Error running calculation: "
24+
"ValueError('Value is too large to be handled in limited time and memory.')")
1525
@plugin.example('.c 5 + 3', '8')
1626
@plugin.example('.c 0.9*10', '9')
1727
@plugin.example('.c 10*0.9', '9')
18-
@plugin.example('.c 2*(1+2)*3', '18')
19-
@plugin.example('.c 2**10', '1024')
20-
@plugin.example('.c 5 // 2', '2')
21-
@plugin.example('.c 5 / 2', '2.5')
28+
@plugin.example('.c 0.5**2', '0.25')
29+
@plugin.example('.c 3**0', '1')
30+
@plugin.example('.c 0 * 5', '0')
31+
@plugin.example('.c 5**5', '3125')
32+
@plugin.example('.c 2*(1+2)*3', '18', user_help=True)
33+
@plugin.example('.c 2**10', '1024', user_help=True)
34+
@plugin.example('.c 5 // 2', '2', user_help=True)
35+
@plugin.example('.c 5 / 2', '2.5', user_help=True)
2236
@plugin.output_prefix('[calc] ')
2337
def c(bot, trigger):
2438
"""Evaluate some calculation."""
@@ -39,5 +53,8 @@ def c(bot, trigger):
3953
except SyntaxError:
4054
bot.reply('Invalid syntax')
4155
return
56+
except ValueError as err:
57+
bot.reply("Error running calculation: %r" % err)
58+
return
4259

4360
bot.say(result)

0 commit comments

Comments
 (0)