From 8a0fc13f2399e08600e38ae6a3f6c4a6b916f4e8 Mon Sep 17 00:00:00 2001 From: MattHag <16444067+MattHag@users.noreply.github.com> Date: Mon, 23 Dec 2024 22:48:16 +0100 Subject: [PATCH] Test arg parse --- lib/solaar/gtk.py | 6 +++++- tests/solaar/test_gtk.py | 27 +++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 tests/solaar/test_gtk.py diff --git a/lib/solaar/gtk.py b/lib/solaar/gtk.py index c9ed6b0bbb..45357afa57 100755 --- a/lib/solaar/gtk.py +++ b/lib/solaar/gtk.py @@ -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" ) @@ -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: diff --git a/tests/solaar/test_gtk.py b/tests/solaar/test_gtk.py new file mode 100644 index 0000000000..60fea21314 --- /dev/null +++ b/tests/solaar/test_gtk.py @@ -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