Skip to content

Commit

Permalink
fix: better main test
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremad committed Nov 22, 2023
1 parent 06b9ccc commit 42e78ea
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
5 changes: 3 additions & 2 deletions py_loop/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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)
Expand All @@ -59,3 +59,4 @@ def main(args: ArgsList = None) -> None:
total_time=args_ns.total_time,
)
looper.loop()
return looper
7 changes: 4 additions & 3 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 42e78ea

Please sign in to comment.