mirror of
https://github.com/koloideal/Argenta.git
synced 2026-06-10 10:05:28 +03:00
some fix
This commit is contained in:
@@ -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):
|
||||
|
||||
@@ -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
|
||||
|
||||
+37
-2
@@ -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['-', '--', '---'], '----'))
|
||||
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user