Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

calc: improve help output, test coverage (now 100%) #2530

Merged
merged 3 commits into from
Nov 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions sopel/builtins/calc.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,27 @@


@plugin.command('c', 'calc')
@plugin.example('.c', 'Nothing to calculate.')
@plugin.example('.c foo * bar', "Can't process expression: Node type 'Name' is not supported.")
@plugin.example('.c 10 / 0', 'Division by zero is not supported in this universe.')
@plugin.example('.c 10\\2', 'Invalid syntax')
@plugin.example('.c (10**1000000)**2',
"Error running calculation: "
"ValueError('Pow expression too complex to calculate.')")
@plugin.example('.c (10**100000)**2 * (10**100000)**2',
"Error running calculation: "
"ValueError('Value is too large to be handled in limited time and memory.')")
@plugin.example('.c 5 + 3', '8')
@plugin.example('.c 0.9*10', '9')
@plugin.example('.c 10*0.9', '9')
@plugin.example('.c 2*(1+2)*3', '18')
@plugin.example('.c 2**10', '1024')
@plugin.example('.c 5 // 2', '2')
@plugin.example('.c 5 / 2', '2.5')
@plugin.example('.c 0.5**2', '0.25')
@plugin.example('.c 3**0', '1')
@plugin.example('.c 0 * 5', '0')
@plugin.example('.c 5**5', '3125')
@plugin.example('.c 2*(1+2)*3', '18', user_help=True)
@plugin.example('.c 2**10', '1024', user_help=True)
@plugin.example('.c 5 // 2', '2', user_help=True)
@plugin.example('.c 5 / 2', '2.5', user_help=True)
@plugin.output_prefix('[calc] ')
def c(bot, trigger):
"""Evaluate some calculation."""
Expand All @@ -39,5 +53,8 @@ def c(bot, trigger):
except SyntaxError:
bot.reply('Invalid syntax')
return
except ValueError as err:
bot.reply("Error running calculation: %r" % err)
return

bot.say(result)