From 61e4502e4134d15ed01f07d962def83701c0bb18 Mon Sep 17 00:00:00 2001 From: kolo Date: Sat, 26 Apr 2025 22:23:35 +0300 Subject: [PATCH] work, fix etc. --- README.md | 97 -------------------------------- mock/local_test.py | 17 ++---- src/argenta/router/__init__.py | 2 +- src/argenta/router/entity.py | 16 +++--- tests/unit_tests/test_app.py | 54 ++++++++++++++++++ tests/unit_tests/test_command.py | 16 ++++++ 6 files changed, 84 insertions(+), 118 deletions(-) create mode 100644 tests/unit_tests/test_app.py diff --git a/README.md b/README.md index 2c0ce86..9f1c152 100644 --- a/README.md +++ b/README.md @@ -334,22 +334,6 @@ Public. Sets the handler for exit command when entering a command --- - - -#### run\_polling - -```python -def run_polling() -> None -``` - -Private. Starts the user input processing cycle - -**Returns**: - -`None` - ---- - #### include\_router @@ -494,26 +478,6 @@ Public. The static dividing line --- - - -#### get\_full\_static\_line - -```python -def get_full_static_line(is_override: bool) -> str -``` - -Private. Returns the full line of the dividing line - -**Arguments**: - -- `is_override`: has the default text layout been redefined - -**Returns**: - -full line of dividing line as str - ---- - ## DynamicDividingLine Objects @@ -542,27 +506,6 @@ Public. The dynamic dividing line --- - - -#### get\_full\_dynamic\_line - -```python -def get_full_dynamic_line(length: int, is_override: bool) -> str -``` - -Private. Returns the full line of the dividing line - -**Arguments**: - -- `length`: the length of the dividing line -- `is_override`: has the default text layout been redefined - -**Returns**: - -full line of dividing line as str - ---- - # `.app.exceptions` @@ -1233,46 +1176,6 @@ Public. Registers handler for invalid input flag --- - - -#### input\_command\_handler - -```python -def input_command_handler(input_command: InputCommand) -> None -``` - -Private. One handler for all input commands - -**Arguments**: - -- `input_command`: input command as InputCommand - -**Returns**: - -`None` - ---- - - - -#### set\_command\_register\_ignore - -```python -def set_command_register_ignore(_: bool) -> None -``` - -Private. Sets the router behavior on the input commands register - -**Arguments**: - -- `_`: is command register ignore - -**Returns**: - -`None` - ---- - #### get\_triggers diff --git a/mock/local_test.py b/mock/local_test.py index d61b2e8..14b4be4 100644 --- a/mock/local_test.py +++ b/mock/local_test.py @@ -1,13 +1,6 @@ -from argenta.command.flag.defaults import PredefinedFlags +from argenta.app import App +from argenta.command.models import InputCommand -router = Router() -flag = PredefinedFlags.SHORT_HELP - -@router.command(Command('test', flags=flag)) -def test(args: InputFlags): - print(f'help for {args.get_flag('h').get_name()} flag') - -app = App(override_system_messages=True, - print_func=print) -app.include_router(router) -app.run_polling() \ No newline at end of file +app = App() +app._all_registered_triggers_in_lower = ['fr', 'Tre', 'Pre'] +print(app._is_unknown_command(InputCommand('fr'))) \ No newline at end of file diff --git a/src/argenta/router/__init__.py b/src/argenta/router/__init__.py index cb253db..75d05bc 100644 --- a/src/argenta/router/__init__.py +++ b/src/argenta/router/__init__.py @@ -1,4 +1,4 @@ __all__ = ["Router"] -from src.argenta.router.entity import Router \ No newline at end of file +from argenta.router.entity import Router \ No newline at end of file diff --git a/src/argenta/router/entity.py b/src/argenta/router/entity.py index 7cb3e23..fc43b8d 100644 --- a/src/argenta/router/entity.py +++ b/src/argenta/router/entity.py @@ -1,13 +1,13 @@ from typing import Callable from inspect import getfullargspec -from src.argenta.command import Command -from src.argenta.command.models import InputCommand -from src.argenta.router.command_handler.entity import CommandHandlers, CommandHandler -from src.argenta.command.flag.models import Flag, Flags, InputFlags -from src.argenta.router.exceptions import (RepeatedFlagNameException, - TooManyTransferredArgsException, - RequiredArgumentNotPassedException, - TriggerContainSpacesException) +from argenta.command import Command +from argenta.command.models import InputCommand +from argenta.router.command_handler.entity import CommandHandlers, CommandHandler +from argenta.command.flag.models import Flag, Flags, InputFlags +from argenta.router.exceptions import (RepeatedFlagNameException, + TooManyTransferredArgsException, + RequiredArgumentNotPassedException, + TriggerContainSpacesException) class Router: diff --git a/tests/unit_tests/test_app.py b/tests/unit_tests/test_app.py new file mode 100644 index 0000000..1b7b607 --- /dev/null +++ b/tests/unit_tests/test_app.py @@ -0,0 +1,54 @@ +from argenta.command.models import InputCommand, Command +from src.argenta.app import App + +import unittest + + +class MyTestCase(unittest.TestCase): + def test_is_exit_command1(self): + app = App() + self.assertEqual(app._is_exit_command(InputCommand('q')), True) + + def test_is_exit_command5(self): + app = App() + self.assertEqual(app._is_exit_command(InputCommand('Q')), True) + + def test_is_exit_command2(self): + app = App(ignore_command_register=False) + self.assertEqual(app._is_exit_command(InputCommand('q')), False) + + def test_is_exit_command3(self): + app = App(exit_command=Command('quit')) + self.assertEqual(app._is_exit_command(InputCommand('quit')), True) + + def test_is_exit_command4(self): + app = App(exit_command=Command('quit')) + self.assertEqual(app._is_exit_command(InputCommand('qUIt')), True) + + def test_is_exit_command6(self): + app = App(ignore_command_register=False, + exit_command=Command('quit')) + self.assertEqual(app._is_exit_command(InputCommand('qUIt')), False) + + def test_is_unknown_command1(self): + app = App() + app._all_registered_triggers_in_lower = ['fr', 'tr', 'de'] + self.assertEqual(app._is_unknown_command(InputCommand('fr')), False) + + + + + + + + + + + + + + + + + + diff --git a/tests/unit_tests/test_command.py b/tests/unit_tests/test_command.py index 4bde140..2587c0c 100644 --- a/tests/unit_tests/test_command.py +++ b/tests/unit_tests/test_command.py @@ -31,3 +31,19 @@ class TestInputCommand(unittest.TestCase): command = Command('some', flags=Flags(Flag('test'), Flag('more'))) self.assertEqual(command.validate_input_flag(InputFlag('more')), True) + def test_validate_incorrect_input_flag1(self): + command = Command('some', flags=Flags(Flag('test'))) + self.assertEqual(command.validate_input_flag(InputFlag('more')), False) + + def test_validate_incorrect_input_flag2(self): + command = Command('some', flags=Flags(Flag('test'), Flag('more'))) + self.assertEqual(command.validate_input_flag(InputFlag('case')), False) + + def test_validate_incorrect_input_flag3(self): + command = Command('some') + self.assertEqual(command.validate_input_flag(InputFlag('case')), False) + + def test_isinstance_parse_correct_raw_command(self): + cmd = InputCommand.parse('ssh --host 192.168.0.3') + self.assertIsInstance(cmd, InputCommand) +