File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -56,13 +56,11 @@ def run(args: list[str] | None = None) -> subprocess.CompletedProcess[bytes]:
5656 return subprocess .run (arguments , check = False ) # noqa: S603
5757
5858
59- def cli () -> None :
59+ def cli (argv : list [ str ] | None = None ) -> None :
6060 """Run the OpenAPI Generator CLI with the arguments provided on the command line."""
61- args = []
62- if len (sys .argv ) > 1 :
63- args = sys .argv [1 :]
61+ args = argv [1 :] if argv is not None and len (argv ) > 1 else []
6462 sys .exit (run (args ).returncode )
6563
6664
6765if __name__ == "__main__" :
68- cli ()
66+ cli (sys . argv )
Original file line number Diff line number Diff line change 22
33import os
44import re
5- import subprocess
6- from unittest .mock import MagicMock , patch
75
86import pytest
97
108from openapi_generator_cli import cli , run
119
12- RETURN_CODE = 23
13-
1410
1511def test_cli_version (capfd : pytest .CaptureFixture [str ]) -> None :
1612 result = run (args = ["version" ])
@@ -49,14 +45,14 @@ def test_invalid_arg(capfd: pytest.CaptureFixture[str]) -> None:
4945 )
5046
5147
52- @patch ("openapi_generator_cli.run" , autospec = True )
53- @patch ("sys.argv" , ["openapi-generator-cli" , "version" ])
54- def test_cli_exits_with_returncode (run_mock : MagicMock ) -> None :
55- run_mock .return_value = subprocess .CompletedProcess (args = [], returncode = RETURN_CODE )
56-
48+ def test_cli_invalid_arg (capfd : pytest .CaptureFixture [str ]) -> None :
5749 with pytest .raises (SystemExit ) as exc_info :
58- cli ()
59-
60- assert exc_info .value .code == RETURN_CODE
50+ cli (["openapi-generator-cli" , "--invalid-arg-404" ])
51+ assert exc_info .value .code == 1
6152
62- run_mock .assert_called_once_with (["version" ])
53+ captured = capfd .readouterr ()
54+ assert not captured .out
55+ assert (
56+ "Found unexpected parameters: [--invalid-arg-404]"
57+ in captured .err .split (os .linesep )[0 ]
58+ )
You can’t perform that action at this time.
0 commit comments