Skip to content

Commit 298aa9e

Browse files
refactor(cli): update version and tests
1 parent 70d5d34 commit 298aa9e

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

src/python_cli_template/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def main(argv: list[str] = None) -> None:
1111
"--version",
1212
"-v",
1313
action="version",
14-
version=f"%(prog)s {__version__}",
14+
version=__version__,
1515
)
1616

1717
parser.add_argument(
Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,38 @@
11
import pytest
22

3+
from python_cli_template import __version__
34
from python_cli_template.cli import main
45

56

6-
def test_hello(capsys):
7-
assert main() is None
7+
def test_version(capsys: pytest.LogCaptureFixture) -> None:
8+
with pytest.raises(SystemExit):
9+
main(["--version"])
10+
captured = capsys.readouterr()
11+
assert captured.out == __version__ + "\n"
12+
13+
14+
def test_help(capsys: pytest.LogCaptureFixture) -> None:
15+
with pytest.raises(SystemExit):
16+
main(["--help"])
17+
captured = capsys.readouterr()
18+
assert "Python CLI Template" in captured.out
19+
20+
21+
def test_hello(capsys: pytest.LogCaptureFixture) -> None:
22+
main()
823
captured = capsys.readouterr()
924
assert captured.out == "Hello, World!\n"
1025

1126

12-
def test_hello_world(capsys):
13-
assert main(["--name", "world"]) is None
27+
def test_hello_world(capsys: pytest.LogCaptureFixture) -> None:
28+
main(["--name", "world"])
1429
captured = capsys.readouterr()
1530
assert captured.out == "Hello, world!\n"
1631

1732

18-
def test_invalid(capsys):
33+
def test_invalid(capsys: pytest.LogCaptureFixture) -> None:
1934
with pytest.raises(SystemExit) as exception:
2035
main(["--invalid"])
36+
captured = capsys.readouterr()
2137
assert exception.type is SystemExit
38+
assert "error: unrecognized arguments: --invalid" in captured.err

0 commit comments

Comments
 (0)