Skip to content

Commit 8687f51

Browse files
committed
Add tests
1 parent 0cd5155 commit 8687f51

2 files changed

Lines changed: 43 additions & 0 deletions

File tree

tests/__init__.py

Whitespace-only changes.

tests/test_cli.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
from __future__ import annotations
2+
3+
import re
4+
from typing import TYPE_CHECKING
5+
6+
from openapi_generator_cli import run
7+
8+
if TYPE_CHECKING:
9+
import pytest
10+
11+
12+
def test_cli_version(capfd: pytest.CaptureFixture[str]) -> None:
13+
result = run(args=["version"])
14+
assert result.returncode == 0
15+
16+
captured = capfd.readouterr()
17+
assert re.match(r"^\d+\.\d+\.\d+(?:-beta\d*)?$", captured.out.split("\n")[0])
18+
assert not captured.err
19+
20+
21+
def test_no_args(capfd: pytest.CaptureFixture[str]) -> None:
22+
result = run(args=[])
23+
assert result.returncode == 1
24+
25+
captured = capfd.readouterr()
26+
assert captured.out.split("\n")[0] in (
27+
# >=5.0.0
28+
"usage: openapi-generator-cli <command> [<args>]",
29+
# >=3.0.1,<5.0.0
30+
"The following generators are available:",
31+
# ==3.0.0
32+
"",
33+
)
34+
assert not captured.err
35+
36+
37+
def test_invalid_arg(capfd: pytest.CaptureFixture[str]) -> None:
38+
result = run(args=["--invalid-arg-404"])
39+
assert result.returncode == 1
40+
41+
captured = capfd.readouterr()
42+
assert not captured.out
43+
assert "Found unexpected parameters: [--invalid-arg-404]" in captured.err.split("\n")[0]

0 commit comments

Comments
 (0)