Skip to content

Commit

Permalink
Test arg parse
Browse files Browse the repository at this point in the history
  • Loading branch information
MattHag authored and pfps committed Jan 1, 2025
1 parent 41768d9 commit 8a0fc13
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/solaar/gtk.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def _require(module, os_package, gi=None, gi_package=None, gi_version=None):
temp = tempfile.NamedTemporaryFile(prefix="Solaar_", mode="w", delete=True)


def _parse_arguments():
def create_parser():
arg_parser = argparse.ArgumentParser(
prog=NAME.lower(), epilog="For more information see https://pwr-solaar.github.io/Solaar"
)
Expand Down Expand Up @@ -99,7 +99,11 @@ def _parse_arguments():
choices=cli.actions,
help="command-line action to perform (optional); append ' --help' to show args",
)
return arg_parser


def _parse_arguments():
arg_parser = create_parser()
args = arg_parser.parse_args()

if args.help_actions:
Expand Down
27 changes: 27 additions & 0 deletions tests/solaar/test_gtk.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from solaar.gtk import create_parser


def test_arg_parse():
parser = create_parser()
res = parser.parse_args([])

assert res.debug == 0
assert res.hidraw_path is None
assert res.restart_on_wake_up is False
assert res.window is None
assert res.battery_icons is None
assert res.tray_icon_size is None


def test_arg_parse_debug():
parser = create_parser()
res = parser.parse_args(["--debug"])

assert res.debug == 1


def test_arg_parse_version():
parser = create_parser()
res = parser.parse_args(["version"])

assert res

0 comments on commit 8a0fc13

Please sign in to comment.