From 42e78eaa3a2354798e8491de12b9fdd3b0915fc3 Mon Sep 17 00:00:00 2001 From: Jeremy Tellaa Date: Wed, 22 Nov 2023 14:12:37 +0100 Subject: [PATCH] fix: better main test --- py_loop/main.py | 5 +++-- tests/test_main.py | 7 ++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/py_loop/main.py b/py_loop/main.py index e299b24..fae62d8 100755 --- a/py_loop/main.py +++ b/py_loop/main.py @@ -9,7 +9,7 @@ ArgsList = Optional[List[str]] -def main(args: ArgsList = None) -> None: +def main(args: ArgsList = None) -> Optional[Looper]: parser = argparse.ArgumentParser() parser.add_argument( "cmd", @@ -46,7 +46,7 @@ def main(args: ArgsList = None) -> None: args_ns = parser.parse_args(args=args) if args_ns.version: ui.info_1(Looper.version()) - return + return None if not args_ns.cmd or not args_ns.cmd[0]: ui.error("no command provided") sys.exit(1) @@ -59,3 +59,4 @@ def main(args: ArgsList = None) -> None: total_time=args_ns.total_time, ) looper.loop() + return looper diff --git a/tests/test_main.py b/tests/test_main.py index b912026..0a8b347 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -13,6 +13,7 @@ def test_no_cmd() -> None: assert e.value.code == 1 -def test_cmd() -> None: - looper_main.main(["ls", "--max-tries", "1"]) - looper_main.main(["--max-tries", "1", "ls"]) +def test_parsing() -> None: + looper = looper_main.main(["--max-tries", "7", "ls"]) + assert looper is not None + assert looper.max_tries == 7