-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_cli.py
More file actions
38 lines (27 loc) · 1.1 KB
/
test_cli.py
File metadata and controls
38 lines (27 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import pytest
from python_cli_template import __version__
from python_cli_template.cli import main
def test_version(capsys: pytest.LogCaptureFixture) -> None:
with pytest.raises(SystemExit):
main(["--version"])
captured = capsys.readouterr()
assert captured.out == __version__ + "\n"
def test_help(capsys: pytest.LogCaptureFixture) -> None:
with pytest.raises(SystemExit):
main(["--help"])
captured = capsys.readouterr()
assert "Python CLI Template" in captured.out
def test_hello(capsys: pytest.LogCaptureFixture) -> None:
main()
captured = capsys.readouterr()
assert captured.out == "Hello, World!\n"
def test_hello_world(capsys: pytest.LogCaptureFixture) -> None:
main(["--name", "world"])
captured = capsys.readouterr()
assert captured.out == "Hello, world!\n"
def test_invalid(capsys: pytest.LogCaptureFixture) -> None:
with pytest.raises(SystemExit) as exception:
main(["--invalid"])
captured = capsys.readouterr()
assert exception.type is SystemExit
assert "error: unrecognized arguments: --invalid" in captured.err