|
1 | 1 | import pytest
|
2 | 2 |
|
| 3 | +from python_cli_template import __version__ |
3 | 4 | from python_cli_template.cli import main
|
4 | 5 |
|
5 | 6 |
|
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() |
8 | 23 | captured = capsys.readouterr()
|
9 | 24 | assert captured.out == "Hello, World!\n"
|
10 | 25 |
|
11 | 26 |
|
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"]) |
14 | 29 | captured = capsys.readouterr()
|
15 | 30 | assert captured.out == "Hello, world!\n"
|
16 | 31 |
|
17 | 32 |
|
18 |
| -def test_invalid(capsys): |
| 33 | +def test_invalid(capsys: pytest.LogCaptureFixture) -> None: |
19 | 34 | with pytest.raises(SystemExit) as exception:
|
20 | 35 | main(["--invalid"])
|
| 36 | + captured = capsys.readouterr() |
21 | 37 | assert exception.type is SystemExit
|
| 38 | + assert "error: unrecognized arguments: --invalid" in captured.err |
0 commit comments