From 679167e6b712f278c731a0ba9a06e4779bb94512 Mon Sep 17 00:00:00 2001 From: Kyle Bowman Date: Sun, 24 Mar 2024 14:58:24 -0400 Subject: [PATCH] Add integration tests. --- tests/test_integration.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 tests/test_integration.py diff --git a/tests/test_integration.py b/tests/test_integration.py new file mode 100644 index 0000000..f75d4f7 --- /dev/null +++ b/tests/test_integration.py @@ -0,0 +1,30 @@ +from typing import Optional +from pathlib import Path + +from proto.infer import get_parser +from proto import command + +def fun(path: Optional[Path] = None): + if path is None: + contents = "mock stdin" + else: + with open(path, "r") as fp: + contents = fp.read() + return f"mock stdout: {contents}" + +def test_command_function(): + cmd = command(fun) + cmd.parse(args=[]) + assert fun(None) == cmd.run() + +def test_command_decorator(): + @command + def cow_says(sound: Optional[str]=None): + return sound if sound else "Moo!" + cow_says.parse(args=[]) + assert "Moo!" in cow_says.run() + +def test_parser_only(): + parser = get_parser(fun) + args = vars(parser.parse_args(args=[])) + assert "mock stdin" in fun(**args) \ No newline at end of file -- 2.39.5