Skip to content

Commit c5d2302

Browse files
authored
Fixed bug that caused every system.exit call to return a non zero error code (#3)
1 parent d0e9891 commit c5d2302

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

LICENSE

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,3 +672,8 @@ may consider it more useful to permit linking proprietary applications with
672672
the library. If this is what you want to do, use the GNU Lesser General
673673
Public License instead of this License. But first, please read
674674
<https://www.gnu.org/licenses/why-not-lgpl.html>.
675+
676+
677+
678+
679+
:

simple_python_app/generic_application.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@ def start(self, argv: List[str] | None = None) -> int:
598598
return 0
599599
except SystemExit as e:
600600
ret = e.code
601-
if ret is int:
601+
if isinstance(ret, int):
602602
return ret
603603
except BaseException as e:
604604
logm.exception(e)

tests/test_cli.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Copyright (C) 2024 twyleg
2+
# fmt: off
3+
import argparse
4+
from pathlib import Path
5+
6+
from simple_python_app.generic_application import GenericApplication
7+
8+
from fixtures import print_tmp_path, valid_custom_logging_config, project_dir
9+
10+
#
11+
# General naming convention for unit tests:
12+
# test_INITIALSTATE_ACTION_EXPECTATION
13+
#
14+
15+
16+
FILE_DIR = Path(__file__).parent
17+
18+
19+
class BaseTestApplication(GenericApplication):
20+
def __init__(self, **kwargs):
21+
super().__init__(
22+
application_name="test_application",
23+
version="0.0.1",
24+
logging_init_default_logging_enabled=False, # Caution: This is necessary because otherwise log init will
25+
logging_init_custom_logging_enabled=False, # remove pytest handler and caplog won't work.
26+
application_config_init_enabled=False,
27+
**kwargs
28+
)
29+
30+
def run(self, argparser: argparse.ArgumentParser) -> None:
31+
pass
32+
33+
34+
class TestCli:
35+
def test_NoArgument_Started_SuccessfullReturnCode(self, caplog, project_dir):
36+
test_app = BaseTestApplication()
37+
assert test_app.start([]) == 0
38+
39+
def test_PrintVersion_Started_VersionPrintedSuccessfullReturnCode(self, caplog, project_dir):
40+
test_app = BaseTestApplication()
41+
assert test_app.start(["--version"]) == 0

0 commit comments

Comments
 (0)