We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 7282ab5 commit cdbbbd2Copy full SHA for cdbbbd2
python/README.md
@@ -0,0 +1,3 @@
1
+# Python Snippets
2
+
3
+- [Testing with argparse](./testing_cli_argparse)
python/testing_cli_argparse/__pycache__/script.cpython-38.pyc
574 Bytes
python/testing_cli_argparse/script.py
@@ -0,0 +1,17 @@
+import argparse
+from typing import Optional
+from typing import Sequence
4
5
6
+def main(argv: Optional[Sequence[str]] = None) -> int:
7
8
+ parser = argparse.ArgumentParser()
9
+ parser.add_argument("first")
10
11
+ args = parser.parse_args(argv)
12
13
+ return 0 if args.first == "foo" else 1
14
15
16
+if __name__ == "__main__":
17
+ exit(main())
python/testing_cli_argparse/test.py
@@ -0,0 +1,9 @@
+from script import main
+def test_main() -> None:
+ assert main(["foo"]) == 0, "Expected foo to return 0"
+ assert main(["bar"]) == 1, "Expected bar to return 1"
+test_main()
0 commit comments