Skip to content

Commit 24db1cc

Browse files
committed
calc: test even more edge cases
These additional cases (and a new error handler) cover as much of the `tools.calculation` submodule as possible using the example decorator. Further coverage of `tools.calculation` would require real unit tests of the sort one finds in this project's `test/` directory.
1 parent b7537ff commit 24db1cc

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

sopel/modules/calc.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,19 @@
1616
@plugin.example('.c foo * bar', "Can't process expression: Node type 'Name' is not supported.")
1717
@plugin.example('.c 10 / 0', 'Division by zero is not supported in this universe.')
1818
@plugin.example('.c 10\\2', 'Invalid syntax')
19+
@plugin.example('.c (10**1000000)**2',
20+
"Couldn't run the calculation: "
21+
"ValueError('Pow expression too complex to calculate.')")
22+
@plugin.example('.c (10**100000)**2 * (10**100000)**2',
23+
"Couldn't run the calculation: "
24+
"ValueError('Value is too large to be handled in limited time and memory.')")
1925
@plugin.example('.c 5 + 3', '8')
2026
@plugin.example('.c 0.9*10', '9')
2127
@plugin.example('.c 10*0.9', '9')
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')
2232
@plugin.example('.c 2*(1+2)*3', '18', user_help=True)
2333
@plugin.example('.c 2**10', '1024', user_help=True)
2434
@plugin.example('.c 5 // 2', '2', user_help=True)
@@ -43,5 +53,8 @@ def c(bot, trigger):
4353
except SyntaxError:
4454
bot.reply('Invalid syntax')
4555
return
56+
except ValueError as err:
57+
bot.reply("Couldn't run the calculation: %r" % err)
58+
return
4659

4760
bot.say(result)

0 commit comments

Comments
 (0)