diff --git a/argenta/app/entity.py b/argenta/app/entity.py index b9c5e98..a43dbb6 100644 --- a/argenta/app/entity.py +++ b/argenta/app/entity.py @@ -50,7 +50,7 @@ class App: self._invalid_input_flags_handler: Callable[[str], None] = lambda raw_command: print_func(f'Incorrect flag syntax: "{raw_command}"') self._repeated_input_flags_handler: Callable[[str], None] = lambda raw_command: print_func(f'Repeated input flags: "{raw_command}"') self._empty_input_command_handler: Callable[[], None] = lambda: print_func(f'Empty input command') - self._unknown_command_handler: Callable[[Command], None] = lambda command: print_func(f"Unknown command: {command.get_string_entity()}") + self._unknown_command_handler: Callable[[Command], None] = lambda command: print_func(f"Unknown command: {command.get_trigger()}") def start_polling(self) -> None: @@ -100,7 +100,9 @@ class App: self.print_func(self.prompt) continue - self._check_command_for_exit_command(input_command.get_trigger()) + is_exit = self._is_exit_command(input_command.get_trigger()) + if is_exit: + return self.print_func(self.line_separate) is_unknown_command: bool = self._check_is_command_unknown(input_command) @@ -212,15 +214,16 @@ class App: raise RepeatedCommandInDifferentRoutersException() - def _check_command_for_exit_command(self, command: str): + def _is_exit_command(self, command: str): if command.lower() == self.exit_command.lower(): if self.ignore_exit_command_register: self.print_func(self.farewell_message) - exit(0) + return True else: if command == self.exit_command: self.print_func(self.farewell_message) - exit(0) + return True + return False def _check_is_command_unknown(self, command: Command): diff --git a/argenta/command/flag/entity.py b/argenta/command/flag/entity.py index d59e824..bd598a0 100644 --- a/argenta/command/flag/entity.py +++ b/argenta/command/flag/entity.py @@ -28,8 +28,8 @@ class Flag: self._flag_value = value def validate_input_flag_value(self, input_flag_value: str | None): - if input_flag_value is None: - if self.possible_flag_values is False: + if self.possible_flag_values is False: + if input_flag_value is None: return True else: return False diff --git a/mock/local_test.py b/mock/local_test.py index 3f2b16e..a648f2f 100644 --- a/mock/local_test.py +++ b/mock/local_test.py @@ -1,3 +1,38 @@ -from typing import cast, Literal +import _io +from io import StringIO +from unittest.mock import patch, MagicMock +import io +from argenta.app import App +from argenta.command import Command +from argenta.router import Router + + +def run_shell(): + router = Router() + + @router.command(Command('test')) + def test(): + print('loh ibanu') + + app = App() + app.include_router(router) + + app.start_polling() + + +@patch("builtins.input", side_effect=["test", "q"]) +@patch("sys.stdout", new_callable=io.StringIO) +def test_run_shell_output(mock_stdout: _io.StringIO, magick_mock: MagicMock): + run_shell() + output = mock_stdout.getvalue() + + assert "loh ibanu" in output + return magick_mock + + +res = test_run_shell_output() +print(res) +print(type(res)) + +print("✅ Тест вывода пройден!") -print(cast(Literal['-', '--', '---'], '----')) \ No newline at end of file diff --git a/tests/system_tests/__init__.py b/tests/system_tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/system_tests/test_system.py b/tests/system_tests/test_system.py new file mode 100644 index 0000000..2e9a859 --- /dev/null +++ b/tests/system_tests/test_system.py @@ -0,0 +1,30 @@ +import _io +from unittest.mock import patch, MagicMock +import unittest +import io + +from argenta.app import App +from argenta.command import Command +from argenta.router import Router + + + +class TestSystem(unittest.TestCase): + @patch("builtins.input", side_effect=["test", "q"]) + @patch("sys.stdout", new_callable=io.StringIO) + def test_run_shell_output(self, mock_stdout: _io.StringIO, magick_mock: MagicMock): + router = Router() + + @router.command(Command('test')) + def test(): + print('test command') + + app = App() + app.include_router(router) + app.start_polling() + + output = mock_stdout.getvalue() + + self.assertIn('test command', output) + + diff --git a/tests/unit_tests/__init__.py b/tests/unit_tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_app.py b/tests/unit_tests/test_app.py similarity index 100% rename from tests/test_app.py rename to tests/unit_tests/test_app.py diff --git a/tests/test_command.py b/tests/unit_tests/test_command.py similarity index 100% rename from tests/test_command.py rename to tests/unit_tests/test_command.py diff --git a/tests/test_flag.py b/tests/unit_tests/test_flag.py similarity index 100% rename from tests/test_flag.py rename to tests/unit_tests/test_flag.py diff --git a/tests/test_flagsgroup.py b/tests/unit_tests/test_flagsgroup.py similarity index 100% rename from tests/test_flagsgroup.py rename to tests/unit_tests/test_flagsgroup.py diff --git a/tests/test_router.py b/tests/unit_tests/test_router.py similarity index 100% rename from tests/test_router.py rename to tests/unit_tests/test_router.py