This commit is contained in:
2025-05-27 14:19:54 +03:00
parent c2bbc5f15d
commit c8e0729be8
5 changed files with 28 additions and 40 deletions
+4 -32
View File
@@ -8,10 +8,10 @@ from argenta.app import App
class TimeOfPreCycleSetup: class TimeOfPreCycleSetup:
@staticmethod @staticmethod
def ten_thousands_commands_with_two_aliases(): def commands_with_two_aliases(num_of_commands: int):
router = Router() 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}'])) @router.command(Command(f'cmd{i}', aliases=[f'cdr{i}', f'prt{i}']))
def handler(response: Response): def handler(response: Response):
pass pass
@@ -22,38 +22,10 @@ class TimeOfPreCycleSetup:
return get_time_of_pre_cycle_setup(app) return get_time_of_pre_cycle_setup(app)
@staticmethod @staticmethod
def ten_thousands_commands_with_one_aliases(): def commands_with_one_aliases(num_of_commands: int):
router = Router() router = Router()
for i in range(10000): for i in range(num_of_commands):
@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):
@router.command(Command(f'cmd{i}', aliases=[f'cdr{i}'])) @router.command(Command(f'cmd{i}', aliases=[f'cdr{i}']))
def handler(response: Response): def handler(response: Response):
pass pass
+16 -2
View File
@@ -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)
+1 -1
View File
@@ -1,6 +1,6 @@
[project] [project]
name = "argenta" name = "argenta"
version = "1.0.6" version = "1.0.7"
description = "Python library for building modular CLI applications" description = "Python library for building modular CLI applications"
authors = [{ name = "kolo", email = "kolo.is.main@gmail.com" }] authors = [{ name = "kolo", email = "kolo.is.main@gmail.com" }]
requires-python = ">=3.8" requires-python = ">=3.8"
+1 -1
View File
@@ -415,7 +415,7 @@ class App(BaseApp):
self._print_framed_text(res) self._print_framed_text(res)
continue 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 processing_router.disable_redirect_stdout:
if isinstance(self._dividing_line, StaticDividingLine): if isinstance(self._dividing_line, StaticDividingLine):
+6 -4
View File
@@ -3,6 +3,8 @@ from argenta.app import App
import unittest import unittest
from argenta.router import Router
class MyTestCase(unittest.TestCase): class MyTestCase(unittest.TestCase):
def test_is_exit_command1(self): def test_is_exit_command1(self):
@@ -33,25 +35,25 @@ class MyTestCase(unittest.TestCase):
def test_is_unknown_command1(self): def test_is_unknown_command1(self):
app = App() app = App()
app.set_unknown_command_handler(lambda command: None) 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) self.assertEqual(app._is_unknown_command(InputCommand('fr')), False)
def test_is_unknown_command2(self): def test_is_unknown_command2(self):
app = App() app = App()
app.set_unknown_command_handler(lambda command: None) 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) self.assertEqual(app._is_unknown_command(InputCommand('cr')), True)
def test_is_unknown_command3(self): def test_is_unknown_command3(self):
app = App(ignore_command_register=False) app = App(ignore_command_register=False)
app.set_unknown_command_handler(lambda command: None) 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) self.assertEqual(app._is_unknown_command(InputCommand('pr')), True)
def test_is_unknown_command4(self): def test_is_unknown_command4(self):
app = App(ignore_command_register=False) app = App(ignore_command_register=False)
app.set_unknown_command_handler(lambda command: None) 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) self.assertEqual(app._is_unknown_command(InputCommand('tW')), False)