3 Commits

Author SHA1 Message Date
kolo 106ca058be new tests 2025-04-27 14:11:01 +03:00
kolo b5ddfb3b35 new tests 2025-04-27 13:28:11 +03:00
kolo 61e4502e41 work, fix etc. 2025-04-26 22:23:35 +03:00
12 changed files with 124 additions and 161 deletions
+4 -102
View File
@@ -176,9 +176,9 @@ class App(BaseApp)
#### \_\_init\_\_ #### \_\_init\_\_
```python ```python
def __init__(prompt: str = '[italic dim bold]What do you want to do?\n', def __init__(prompt: str = 'What do you want to do?',
initial_message: str = '\nArgenta\n', initial_message: str = 'Argenta',
farewell_message: str = '\nSee you\n', farewell_message: str = 'See you',
exit_command: Command = Command('Q', 'Exit command'), exit_command: Command = Command('Q', 'Exit command'),
system_router_title: str | None = 'System points:', system_router_title: str | None = 'System points:',
ignore_command_register: bool = True, ignore_command_register: bool = True,
@@ -218,8 +218,7 @@ Configures and manages all aspects of the behavior and presentation of the user
#### set\_description\_message\_pattern #### set\_description\_message\_pattern
```python ```python
def set_description_message_pattern( def set_description_message_pattern(pattern: Callable[[str, str], str]) -> None
pattern: Callable[[str, str], str]) -> None
``` ```
Public. Sets the output pattern of the available commands Public. Sets the output pattern of the available commands
@@ -334,22 +333,6 @@ Public. Sets the handler for exit command when entering a command
--- ---
<a id="argenta.app.models.App.run_polling"></a>
#### run\_polling
```python
def run_polling() -> None
```
Private. Starts the user input processing cycle
**Returns**:
`None`
---
<a id="argenta.app.models.App.include_router"></a> <a id="argenta.app.models.App.include_router"></a>
#### include\_router #### include\_router
@@ -494,26 +477,6 @@ Public. The static dividing line
--- ---
<a id="argenta.app.dividing_line.models.StaticDividingLine.get_full_static_line"></a>
#### 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
---
<a id="argenta.app.dividing_line.models.DynamicDividingLine"></a> <a id="argenta.app.dividing_line.models.DynamicDividingLine"></a>
## DynamicDividingLine Objects ## DynamicDividingLine Objects
@@ -542,27 +505,6 @@ Public. The dynamic dividing line
--- ---
<a id="argenta.app.dividing_line.models.DynamicDividingLine.get_full_dynamic_line"></a>
#### 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
---
<a id="argenta.app.exceptions"></a> <a id="argenta.app.exceptions"></a>
# `.app.exceptions` # `.app.exceptions`
@@ -1233,46 +1175,6 @@ Public. Registers handler for invalid input flag
--- ---
<a id="argenta.router.entity.Router.input_command_handler"></a>
#### 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`
---
<a id="argenta.router.entity.Router.set_command_register_ignore"></a>
#### 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`
---
<a id="argenta.router.entity.Router.get_triggers"></a> <a id="argenta.router.entity.Router.get_triggers"></a>
#### get\_triggers #### get\_triggers
+5 -12
View File
@@ -1,13 +1,6 @@
from argenta.command.flag.defaults import PredefinedFlags from argenta.app import App
from argenta.command.models import InputCommand
router = Router() app = App()
flag = PredefinedFlags.SHORT_HELP app._all_registered_triggers_in_lower = ['fr', 'Tre', 'Pre']
print(app._is_unknown_command(InputCommand('fr')))
@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()
+2 -2
View File
@@ -9,14 +9,14 @@ work_router: Router = Router(title='Work points:')
console = Console() console = Console()
@work_router.command(Command('get', 'Get Help', aliases=['help', 'Get_help'])) '''@work_router.command(Command('get', 'Get Help', aliases=['help', 'Get_help']))
def command_help(): def command_help():
pass pass
@work_router.command(Command('run', 'Run All')) @work_router.command(Command('run', 'Run All'))
def command_start_solving(): def command_start_solving():
pass pass'''
+1 -1
View File
@@ -1,6 +1,6 @@
[project] [project]
name = "argenta" name = "argenta"
version = "1.0.0-alpha1" version = "1.0.0-alpha2"
description = "Python library for creating TUI" description = "Python library for creating TUI"
authors = [{ name = "kolo", email = "kolo.is.main@gmail.com" }] authors = [{ name = "kolo", email = "kolo.is.main@gmail.com" }]
requires-python = ">=3.11, <4.0" requires-python = ">=3.11, <4.0"
-8
View File
@@ -1,8 +0,0 @@
class NoRegisteredHandlersException(Exception):
"""
The router has no registered handlers
"""
def __init__(self, router_name) -> None:
self.router_name = router_name
def __str__(self):
return f"No Registered Handlers Found For '{self.router_name}'"
+4 -17
View File
@@ -15,7 +15,6 @@ from argenta.command.exceptions import (UnprocessedInputFlagException,
RepeatedInputFlagsException, RepeatedInputFlagsException,
EmptyInputCommandException, EmptyInputCommandException,
BaseInputCommandException) BaseInputCommandException)
from argenta.app.exceptions import NoRegisteredHandlersException
from argenta.app.registered_routers.entity import RegisteredRouters from argenta.app.registered_routers.entity import RegisteredRouters
@@ -184,11 +183,6 @@ class BaseApp:
else: else:
if input_command_trigger in self._all_registered_triggers_in_default_case: if input_command_trigger in self._all_registered_triggers_in_default_case:
return False return False
with redirect_stdout(io.StringIO()) as f:
self._unknown_command_handler(command)
res: str = f.getvalue()
self._print_framed_text(res)
return True return True
@@ -208,16 +202,6 @@ class BaseApp:
self._empty_input_command_handler() self._empty_input_command_handler()
def _validate_included_routers(self) -> None:
"""
Private. Validates included routers
:return: None
"""
for router in self._registered_routers:
if not router.get_command_handlers():
raise NoRegisteredHandlersException(router.get_name())
def _setup_system_router(self) -> None: def _setup_system_router(self) -> None:
""" """
Private. Sets up system router Private. Sets up system router
@@ -259,7 +243,6 @@ class BaseApp:
""" """
self._setup_default_view() self._setup_default_view()
self._setup_system_router() self._setup_system_router()
self._validate_included_routers()
for router_entity in self._registered_routers: for router_entity in self._registered_routers:
self._all_registered_triggers_in_default_case.extend(router_entity.get_triggers()) self._all_registered_triggers_in_default_case.extend(router_entity.get_triggers())
@@ -351,6 +334,10 @@ class App(BaseApp):
return return
if self._is_unknown_command(input_command): if self._is_unknown_command(input_command):
with redirect_stdout(io.StringIO()) as f:
self._unknown_command_handler(input_command)
res: str = f.getvalue()
self._print_framed_text(res)
continue continue
with redirect_stdout(io.StringIO()) as f: with redirect_stdout(io.StringIO()) as f:
+1 -1
View File
@@ -1,4 +1,4 @@
__all__ = ["Router"] __all__ = ["Router"]
from src.argenta.router.entity import Router from argenta.router.entity import Router
+3 -3
View File
@@ -49,14 +49,14 @@ class CommandHandlers:
""" """
self.command_handlers = command_handlers if command_handlers else [] self.command_handlers = command_handlers if command_handlers else []
def get_command_handlers(self) -> list[CommandHandler]: def get_handlers(self) -> list[CommandHandler]:
""" """
Private. Returns the list of CommandHandlers Private. Returns the list of CommandHandlers
:return: the list of CommandHandlers as list[CommandHandler] :return: the list of CommandHandlers as list[CommandHandler]
""" """
return self.command_handlers return self.command_handlers
def add_command_handler(self, command_handler: CommandHandler) -> None: def add_handler(self, command_handler: CommandHandler) -> None:
""" """
Private. Adds a CommandHandler to the list of CommandHandlers Private. Adds a CommandHandler to the list of CommandHandlers
:param command_handler: CommandHandler to be added :param command_handler: CommandHandler to be added
@@ -64,7 +64,7 @@ class CommandHandlers:
""" """
self.command_handlers.append(command_handler) self.command_handlers.append(command_handler)
def add_command_handlers(self, *command_handlers: CommandHandler) -> None: def add_handlers(self, *command_handlers: CommandHandler) -> None:
""" """
Private. Extend a many CommandHandler to the list of CommandHandlers Private. Extend a many CommandHandler to the list of CommandHandlers
:param command_handlers: many CommandHandler to be added :param command_handlers: many CommandHandler to be added
+9 -9
View File
@@ -1,13 +1,13 @@
from typing import Callable from typing import Callable
from inspect import getfullargspec from inspect import getfullargspec
from src.argenta.command import Command from argenta.command import Command
from src.argenta.command.models import InputCommand from argenta.command.models import InputCommand
from src.argenta.router.command_handler.entity import CommandHandlers, CommandHandler from argenta.router.command_handler.entity import CommandHandlers, CommandHandler
from src.argenta.command.flag.models import Flag, Flags, InputFlags from argenta.command.flag.models import Flag, Flags, InputFlags
from src.argenta.router.exceptions import (RepeatedFlagNameException, from argenta.router.exceptions import (RepeatedFlagNameException,
TooManyTransferredArgsException, TooManyTransferredArgsException,
RequiredArgumentNotPassedException, RequiredArgumentNotPassedException,
TriggerContainSpacesException) TriggerContainSpacesException)
class Router: class Router:
@@ -35,7 +35,7 @@ class Router:
def command_decorator(func): def command_decorator(func):
Router._validate_func_args(command, func) Router._validate_func_args(command, func)
self._command_handlers.add_command_handler(CommandHandler(func, command)) self._command_handlers.add_handler(CommandHandler(func, command))
def wrapper(*args, **kwargs): def wrapper(*args, **kwargs):
return func(*args, **kwargs) return func(*args, **kwargs)
+73
View File
@@ -0,0 +1,73 @@
from argenta.command.models import InputCommand, Command
from 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.set_unknown_command_handler(lambda command: None)
app._all_registered_triggers_in_lower = ['fr', 'tr', 'de']
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 = ['fr', 'tr', 'de']
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']
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']
self.assertEqual(app._is_unknown_command(InputCommand('tW')), False)
+16
View File
@@ -31,3 +31,19 @@ class TestInputCommand(unittest.TestCase):
command = Command('some', flags=Flags(Flag('test'), Flag('more'))) command = Command('some', flags=Flags(Flag('test'), Flag('more')))
self.assertEqual(command.validate_input_flag(InputFlag('more')), True) 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)
+6 -6
View File
@@ -1,10 +1,10 @@
from argenta.command.flag import InputFlags, InputFlag, Flag, Flags from argenta.command.flag import InputFlags, InputFlag, Flag, Flags
from src.argenta.router import Router from argenta.router import Router
from src.argenta.command import Command from argenta.command import Command
from src.argenta.router.exceptions import (TriggerContainSpacesException, from argenta.router.exceptions import (TriggerContainSpacesException,
RepeatedFlagNameException, RepeatedFlagNameException,
TooManyTransferredArgsException, TooManyTransferredArgsException,
RequiredArgumentNotPassedException) RequiredArgumentNotPassedException)
import unittest import unittest
import re import re