]> git.rocketbowman.com Git - proto.git/commitdiff
Add integration tests.
authorKyle Bowman <kyle+github@rocketbowman.com>
Sun, 24 Mar 2024 18:58:24 +0000 (14:58 -0400)
committerKyle Bowman <kyle+github@rocketbowman.com>
Sun, 24 Mar 2024 18:58:24 +0000 (14:58 -0400)
tests/test_integration.py [new file with mode: 0644]

diff --git a/tests/test_integration.py b/tests/test_integration.py
new file mode 100644 (file)
index 0000000..f75d4f7
--- /dev/null
@@ -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