Skip to content

Commit

Permalink
style: format code with Autopep8, Black, Go fmt, Gofumpt, isort and Y…
Browse files Browse the repository at this point in the history
…apf (#448)

This commit fixes the style issues introduced in de5a334 according to the output
from Autopep8, Black, Go fmt, Gofumpt, isort and Yapf.

Details: None

Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com>
  • Loading branch information
deepsource-autofix[bot] committed Nov 20, 2023
1 parent de5a334 commit 9c92fd6
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 66 deletions.
104 changes: 45 additions & 59 deletions src/python/code/gnoll/__main__.py
Original file line number Diff line number Diff line change
@@ -1,81 +1,68 @@
"""Roll some dice with GNOLL."""

import sys
import argparse
import sys

import gnoll


def parse_cmdline_args(args):
"""Extract values from the commandline
@param args - the arguments from the commandline (excluding the python3 call)
"""
p = argparse.ArgumentParser(
description=__doc__,
usage='python3 -m gnoll [options] EXPR',
add_help=False)
p = argparse.ArgumentParser(description=__doc__,
usage="python3 -m gnoll [options] EXPR",
add_help=False)

p.add_argument(
'EXPR',
nargs='+',
help='a dice expression to evaluate'
'(multiple arguments will be joined with spaces)'
"EXPR",
nargs="+",
help="a dice expression to evaluate"
"(multiple arguments will be joined with spaces)",
)

g = p.add_argument_group('main options')
g.add_argument(
'-h',
'--help',
action='help',
help='show this help message and exit'
)
g = p.add_argument_group("main options")
g.add_argument("-h",
"--help",
action="help",
help="show this help message and exit")
g.add_argument(
'-b',
'--breakdown',
action='store_true',
help='show a breakdown into individual dice'
"-b",
"--breakdown",
action="store_true",
help="show a breakdown into individual dice",
)
g.add_argument(
'-n',
'--times',
metavar='N',
"-n",
"--times",
metavar="N",
type=int,
default=1,
help='execute the entire expression N times'
)
g.add_argument(
'--no-builtins',
action='store_true',
help='disable built-in macros'
help="execute the entire expression N times",
)
g.add_argument("--no-builtins",
action="store_true",
help="disable built-in macros")

g = p.add_argument_group('debugging options')
g = p.add_argument_group("debugging options")
g.add_argument("-v",
"--verbose",
action="store_true",
help="enable verbosity")
g.add_argument(
'-v',
'--verbose',
action='store_true',
help='enable verbosity'
)
g.add_argument(
'--keep-temp-file',
action='store_true',
help="don't delete the created temporary file"
)
g.add_argument(
'--mock',
metavar='TYPE',
type=int,
help='mocking type'
)
g.add_argument(
'--mock-const',
metavar='N',
type=int,
default=3,
help='mocking constant'
"--keep-temp-file",
action="store_true",
help="don't delete the created temporary file",
)
g.add_argument("--mock", metavar="TYPE", type=int, help="mocking type")
g.add_argument("--mock-const",
metavar="N",
type=int,
default=3,
help="mocking constant")

a = p.parse_args(args)
a.EXPR = ' '.join(a.EXPR)
a.EXPR = " ".join(a.EXPR)
return a


Expand All @@ -88,11 +75,10 @@ def main(EXPR, times, no_builtins, **kwargs):
@param **kwargs - other key word arguments to be passed to gnoll.roll
"""
for _ in range(times):
_, [[result]], breakdown = gnoll.roll(
EXPR,
builtins=not no_builtins,
**kwargs)
yield (breakdown[0], '-->', result) if breakdown else (result,)
_, [[result]], breakdown = gnoll.roll(EXPR,
builtins=not no_builtins,
**kwargs)
yield (breakdown[0], "-->", result) if breakdown else (result, )


def main_with_args(args):
Expand All @@ -102,6 +88,6 @@ def main_with_args(args):
yield from main(**vars(parse_cmdline_args(args)))


if __name__ == '__main__':
if __name__ == "__main__":
for line in main_with_args(sys.argv[1:]):
print(*line)
13 changes: 6 additions & 7 deletions tests/python/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import gnoll.__main__


m = lambda *x: list(gnoll.__main__.main_with_args(x))


def test_cli():

[[r]] = m('1d4')
[[r]] = m("1d4")
assert isinstance(r, int)

[[(die1, die2), a, r]] = m('2d4', '--breakdown')
[[(die1, die2), a, r]] = m("2d4", "--breakdown")
assert all((isinstance(x, int) for x in [die1, die2, r]))
assert a == '-->'
assert a == "-->"

executions = m('4d6kh3', '+', '1', '--breakdown', '--times', '6', '--no-builtins')
executions = m("4d6kh3", "+", "1", "--breakdown", "--times", "6",
"--no-builtins")
assert len(executions) == 6
for (die1, die2, die3, die4), a, r in executions:
assert all((isinstance(x, int) for x in [die1, die2, die3, die4, r]))
assert a == '-->'
assert a == "-->"

0 comments on commit 9c92fd6

Please sign in to comment.