From c8e0729be8a75656988bb2a74697dc01e9c3c087 Mon Sep 17 00:00:00 2001 From: kolo Date: Tue, 27 May 2025 14:19:54 +0300 Subject: [PATCH] fix bugs --- metrics_tests/get_time_of_pre_cycle_setup.py | 36 +++----------------- mock/local_test.py | 18 ++++++++-- pyproject.toml | 2 +- src/argenta/app/models.py | 2 +- tests/unit_tests/test_app.py | 10 +++--- 5 files changed, 28 insertions(+), 40 deletions(-) diff --git a/metrics_tests/get_time_of_pre_cycle_setup.py b/metrics_tests/get_time_of_pre_cycle_setup.py index c12c901..439093c 100644 --- a/metrics_tests/get_time_of_pre_cycle_setup.py +++ b/metrics_tests/get_time_of_pre_cycle_setup.py @@ -8,10 +8,10 @@ from argenta.app import App class TimeOfPreCycleSetup: @staticmethod - def ten_thousands_commands_with_two_aliases(): + def commands_with_two_aliases(num_of_commands: int): router = Router() - for i in range(10000): + for i in range(num_of_commands): @router.command(Command(f'cmd{i}', aliases=[f'cdr{i}', f'prt{i}'])) def handler(response: Response): pass @@ -22,38 +22,10 @@ class TimeOfPreCycleSetup: return get_time_of_pre_cycle_setup(app) @staticmethod - def ten_thousands_commands_with_one_aliases(): + def commands_with_one_aliases(num_of_commands: int): router = Router() - for i in range(10000): - @router.command(Command(f'cmd{i}', aliases=[f'prt{i}'])) - def handler(response: Response): - pass - - app = App() - app.include_router(router) - - return get_time_of_pre_cycle_setup(app) - - @staticmethod - def one_hundred_thousands_commands_with_two_aliases(): - router = Router() - - for i in range(100000): - @router.command(Command(f'cmd{i}', aliases=[f'cdr{i}', f'prt{i}'])) - def handler(response: Response): - pass - - app = App() - app.include_router(router) - - return get_time_of_pre_cycle_setup(app) - - @staticmethod - def one_hundred_thousands_commands_with_one_aliases(): - router = Router() - - for i in range(100000): + for i in range(num_of_commands): @router.command(Command(f'cmd{i}', aliases=[f'cdr{i}'])) def handler(response: Response): pass diff --git a/mock/local_test.py b/mock/local_test.py index 18ac57c..95fcef8 100644 --- a/mock/local_test.py +++ b/mock/local_test.py @@ -1,4 +1,18 @@ -from metrics_tests.get_time_of_pre_cycle_setup import TimeOfPreCycleSetup +from argenta.app import App +from argenta.command import Command +from argenta.orchestrator import Orchestrator +from argenta.router import Router -print(TimeOfPreCycleSetup.one_hundred_thousands_commands_with_two_aliases()) +router = Router() +orchestrator = Orchestrator() + +@router.command(Command('test')) +def test(response): + print('test command') + +app = App(ignore_command_register=True, + override_system_messages=True, + print_func=print) +app.include_router(router) +orchestrator.start_polling(app) \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 755b6ba..2064854 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "argenta" -version = "1.0.6" +version = "1.0.7" description = "Python library for building modular CLI applications" authors = [{ name = "kolo", email = "kolo.is.main@gmail.com" }] requires-python = ">=3.8" diff --git a/src/argenta/app/models.py b/src/argenta/app/models.py index af75658..65920fb 100644 --- a/src/argenta/app/models.py +++ b/src/argenta/app/models.py @@ -415,7 +415,7 @@ class App(BaseApp): self._print_framed_text(res) continue - processing_router = self._current_matching_triggers_with_routers[input_command.get_trigger()] + processing_router = self._current_matching_triggers_with_routers[input_command.get_trigger().lower()] if processing_router.disable_redirect_stdout: if isinstance(self._dividing_line, StaticDividingLine): diff --git a/tests/unit_tests/test_app.py b/tests/unit_tests/test_app.py index db0b00d..a0eb7bf 100644 --- a/tests/unit_tests/test_app.py +++ b/tests/unit_tests/test_app.py @@ -3,6 +3,8 @@ from argenta.app import App import unittest +from argenta.router import Router + class MyTestCase(unittest.TestCase): def test_is_exit_command1(self): @@ -33,25 +35,25 @@ class MyTestCase(unittest.TestCase): def test_is_unknown_command1(self): app = App() app.set_unknown_command_handler(lambda command: None) - app._all_registered_triggers_in_lower_case = ['fr', 'tr', 'de'] + app._current_matching_triggers_with_routers = {'fr': Router(), 'tr': Router(), 'de': Router()} self.assertEqual(app._is_unknown_command(InputCommand('fr')), False) def test_is_unknown_command2(self): app = App() app.set_unknown_command_handler(lambda command: None) - app._all_registered_triggers_in_lower_case = ['fr', 'tr', 'de'] + app._current_matching_triggers_with_routers = {'fr': Router(), 'tr': Router(), 'de': Router()} self.assertEqual(app._is_unknown_command(InputCommand('cr')), True) def test_is_unknown_command3(self): app = App(ignore_command_register=False) app.set_unknown_command_handler(lambda command: None) - app._all_registered_triggers_in_default_case = ['Pr', 'tW', 'deQW'] + app._current_matching_triggers_with_routers = {'Pr': Router(), 'tW': Router(), 'deQW': Router()} self.assertEqual(app._is_unknown_command(InputCommand('pr')), True) def test_is_unknown_command4(self): app = App(ignore_command_register=False) app.set_unknown_command_handler(lambda command: None) - app._all_registered_triggers_in_default_case = ['Pr', 'tW', 'deQW'] + app._current_matching_triggers_with_routers = {'Pr': Router(), 'tW': Router(), 'deQW': Router()} self.assertEqual(app._is_unknown_command(InputCommand('tW')), False)