File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -61,7 +61,7 @@ def cli() -> None:
6161 args = []
6262 if len (sys .argv ) > 1 :
6363 args = sys .argv [1 :]
64- run (args )
64+ sys . exit ( run (args ). returncode )
6565
6666
6767if __name__ == "__main__" :
Original file line number Diff line number Diff line change 22
33import os
44import re
5- from typing import TYPE_CHECKING
5+ import subprocess
6+ from unittest .mock import MagicMock , patch
67
7- from openapi_generator_cli import run
8+ import pytest
89
9- if TYPE_CHECKING :
10- import pytest
10+ from openapi_generator_cli import cli , run
11+
12+ RETURN_CODE = 23
1113
1214
1315def test_cli_version (capfd : pytest .CaptureFixture [str ]) -> None :
@@ -45,3 +47,16 @@ def test_invalid_arg(capfd: pytest.CaptureFixture[str]) -> None:
4547 "Found unexpected parameters: [--invalid-arg-404]"
4648 in captured .err .split (os .linesep )[0 ]
4749 )
50+
51+
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+
57+ with pytest .raises (SystemExit ) as exc_info :
58+ cli ()
59+
60+ assert exc_info .value .code == RETURN_CODE
61+
62+ run_mock .assert_called_once_with (["version" ])
You can’t perform that action at this time.
0 commit comments