new model - Response

This commit is contained in:
2025-04-28 02:21:34 +03:00
parent e076dbf84f
commit eb43806da6
14 changed files with 158 additions and 180 deletions
+5 -6
View File
@@ -1,8 +1,7 @@
#from mock.mock_app.handlers.routers import work_router from mock.mock_app.handlers.routers import work_router
from argenta.app import App from argenta.app import App
from argenta.app.defaults import PredefinedMessages from argenta.app.defaults import PredefinedMessages
from argenta.app.dividing_line import DynamicDividingLine
from argenta.app.autocompleter import AutoCompleter from argenta.app.autocompleter import AutoCompleter
from argenta.orchestrator import Orchestrator from argenta.orchestrator import Orchestrator
from argenta.orchestrator.argparser import ArgParser from argenta.orchestrator.argparser import ArgParser
@@ -10,16 +9,16 @@ from argenta.orchestrator.argparser.arguments import BooleanArgument
arg_parser = ArgParser(processed_args=[BooleanArgument('repeat')]) arg_parser = ArgParser(processed_args=[BooleanArgument('repeat')])
app: App = App() app: App = App(autocompleter=AutoCompleter('.hist'))
orchestrator: Orchestrator = Orchestrator() orchestrator: Orchestrator = Orchestrator()
def main(): def main():
#app.include_router(work_router) app.include_router(work_router)
'''app.add_message_on_startup(PredefinedMessages.USAGE) app.add_message_on_startup(PredefinedMessages.USAGE)
app.add_message_on_startup(PredefinedMessages.AUTOCOMPLETE) app.add_message_on_startup(PredefinedMessages.AUTOCOMPLETE)
app.add_message_on_startup(PredefinedMessages.HELP)''' app.add_message_on_startup(PredefinedMessages.HELP)
orchestrator.start_polling(app) orchestrator.start_polling(app)
+2 -2
View File
@@ -1,4 +1,4 @@
from argenta.command.flag.models import InputFlag, Flag from argenta.command.flag.models import ValidInputFlag, Flag
class BaseInputCommandException(Exception): class BaseInputCommandException(Exception):
@@ -20,7 +20,7 @@ class RepeatedInputFlagsException(BaseInputCommandException):
""" """
Private. Raised when repeated input flags are detected Private. Raised when repeated input flags are detected
""" """
def __init__(self, flag: Flag | InputFlag): def __init__(self, flag: Flag | ValidInputFlag):
self.flag = flag self.flag = flag
def __str__(self): def __str__(self):
return ("Repeated Input Flags\n" return ("Repeated Input Flags\n"
+2 -2
View File
@@ -1,4 +1,4 @@
__all__ = ('InputFlags', 'InputFlag', 'Flag', 'Flags') __all__ = ('InputFlags', 'ValidInputFlag', 'Flag', 'Flags')
from argenta.command.flag.models import InputFlags, InputFlag, Flags, Flag from argenta.command.flag.models import InputFlags, ValidInputFlag, Flags, Flag
+23 -119
View File
@@ -38,37 +38,6 @@ class BaseFlag(ABC):
class InputFlag(BaseFlag):
def __init__(self, name: str,
prefix: Literal['-', '--', '---'] = '--',
value: str = None):
"""
Public. The entity of the flag of the entered command
:param name: the name of the input flag
:param prefix: the prefix of the input flag
:param value: the value of the input flag
:return: None
"""
super().__init__(name, prefix)
self._flag_value = value
def get_value(self) -> str | None:
"""
Public. Returns the value of the flag
:return: the value of the flag as str
"""
return self._flag_value
def set_value(self, value):
"""
Private. Sets the value of the flag
:param value: the fag value to set
:return: None
"""
self._flag_value = value
class Flag(BaseFlag): class Flag(BaseFlag):
def __init__(self, name: str, def __init__(self, name: str,
prefix: Literal['-', '--', '---'] = '--', prefix: Literal['-', '--', '---'] = '--',
@@ -114,105 +83,40 @@ class Flag(BaseFlag):
class BaseFlags(ABC): class ValidInputFlag(BaseFlag):
def __init__(self, name: str,
prefix: Literal['-', '--', '---'] = '--',
value: str = None):
""" """
Private. Base class for groups of flags Public. The entity of the flag of the entered command
""" :param name: the name of the input flag
__slots__ = ('_flags',) :param prefix: the prefix of the input flag
:param value: the value of the input flag
@abstractmethod
def get_flags(self):
"""
Public. Returns a list of flags
:return: list of flags
"""
pass
@abstractmethod
def add_flag(self, flag: Flag | InputFlag):
"""
Public. Adds a flag to the list of flags
:param flag: flag to add
:return: None :return: None
""" """
pass super().__init__(name, prefix)
self._flag_value = value
@abstractmethod def get_value(self) -> str | None:
def add_flags(self, flags: list[Flag] | list[InputFlag]):
""" """
Public. Adds a list of flags to the list of flags Public. Returns the value of the flag
:param flags: list of flags to add :return: the value of the flag as str
"""
return self._flag_value
def set_value(self, value):
"""
Private. Sets the value of the flag
:param value: the fag value to set
:return: None :return: None
""" """
pass self._flag_value = value
@abstractmethod
def get_flag(self, name: str):
"""
Public. Returns the flag entity by its name or None if not found
:param name: the name of the flag to get
:return: entity of the flag or None
"""
pass
def __iter__(self):
return iter(self._flags)
def __next__(self):
return next(iter(self))
def __getitem__(self, item):
return self._flags[item]
class Flags(BaseFlags, ABC): class UndefinedInputFlag(ValidInputFlag): pass
def __init__(self, *flags: Flag):
"""
Public. A model that combines the registered flags
:param flags: the flags that will be registered
:return: None
"""
self._flags = flags if flags else []
def get_flags(self) -> list[Flag]:
return self._flags
def add_flag(self, flag: Flag):
self._flags.append(flag)
def add_flags(self, flags: list[Flag]):
self._flags.extend(flags)
def get_flag(self, name: str) -> Flag | None:
if name in [flag.get_name() for flag in self._flags]:
return list(filter(lambda flag: flag.get_name() == name, self._flags))[0]
else:
return None
class InputFlags(BaseFlags, ABC): class InvalidValueInputFlag(ValidInputFlag): pass
def __init__(self, *flags: InputFlag):
"""
Public. A model that combines the input flags of the input command
:param flags: all input flags
:return: None
"""
self._flags = flags if flags else []
def get_flags(self) -> list[InputFlag]:
return self._flags
def add_flag(self, flag: InputFlag):
self._flags.append(flag)
def add_flags(self, flags: list[InputFlag]):
self._flags.extend(flags)
def get_flag(self, name: str) -> InputFlag | None:
if name in [flag.get_name() for flag in self._flags]:
return list(filter(lambda flag: flag.get_name() == name, self._flags))[0]
else:
return None
+69
View File
@@ -0,0 +1,69 @@
from argenta.command.flag import Flag, ValidInputFlag
class Flags:
def __init__(self, *flags: Flag):
"""
Public. A model that combines the registered flags
:param flags: the flags that will be registered
:return: None
"""
self._flags = flags if flags else []
def get_flags(self) -> list[Flag]:
"""
Public. Returns a list of flags
:return: list of flags
"""
return self._flags
def add_flag(self, flag: Flag):
"""
Public. Adds a flag to the list of flags
:param flag: flag to add
:return: None
"""
self._flags.append(flag)
def add_flags(self, flags: list[Flag]):
"""
Public. Adds a list of flags to the list of flags
:param flags: list of flags to add
:return: None
"""
self._flags.extend(flags)
def get_flag(self, name: str) -> Flag | None:
"""
Public. Returns the flag entity by its name or None if not found
:param name: the name of the flag to get
:return: entity of the flag or None
"""
if name in [flag.get_name() for flag in self._flags]:
return list(filter(lambda flag: flag.get_name() == name, self._flags))[0]
else:
return None
def __iter__(self):
return iter(self._flags)
def __next__(self):
return next(iter(self))
def __getitem__(self, item):
return self._flags[item]
class ValidInputFlags(ValidInputFlag):
pass
class UndefinedInputFlags(ValidInputFlags):
pass
class InvalidValueInputFlags(ValidInputFlags):
pass
+5 -5
View File
@@ -1,4 +1,4 @@
from argenta.command.flag.models import Flag, InputFlag, Flags, InputFlags from argenta.command.flag.models import Flag, ValidInputFlag, Flags, InputFlags
from argenta.command.exceptions import (UnprocessedInputFlagException, from argenta.command.exceptions import (UnprocessedInputFlagException,
RepeatedInputFlagsException, RepeatedInputFlagsException,
EmptyInputCommandException) EmptyInputCommandException)
@@ -55,7 +55,7 @@ class Command(BaseCommand):
""" """
return self._aliases return self._aliases
def validate_input_flag(self, flag: InputFlag) -> bool: def validate_input_flag(self, flag: ValidInputFlag) -> bool:
""" """
Private. Validates the input flag Private. Validates the input flag
:param flag: input flag for validation :param flag: input flag for validation
@@ -87,7 +87,7 @@ class Command(BaseCommand):
class InputCommand(BaseCommand, Generic[InputCommandType]): class InputCommand(BaseCommand, Generic[InputCommandType]):
def __init__(self, trigger: str, def __init__(self, trigger: str,
input_flags: InputFlag | InputFlags = None): input_flags: ValidInputFlag | InputFlags = None):
""" """
Private. The model of the input command, after parsing Private. The model of the input command, after parsing
:param trigger:the trigger of the command :param trigger:the trigger of the command
@@ -95,7 +95,7 @@ class InputCommand(BaseCommand, Generic[InputCommandType]):
:return: None :return: None
""" """
super().__init__(trigger) super().__init__(trigger)
self._input_flags: InputFlags = input_flags if isinstance(input_flags, InputFlags) else InputFlags(input_flags) if isinstance(input_flags, InputFlag) else InputFlags() self._input_flags: InputFlags = input_flags if isinstance(input_flags, InputFlags) else InputFlags(input_flags) if isinstance(input_flags, ValidInputFlag) else InputFlags()
def _set_input_flags(self, input_flags: InputFlags) -> None: def _set_input_flags(self, input_flags: InputFlags) -> None:
""" """
@@ -144,7 +144,7 @@ class InputCommand(BaseCommand, Generic[InputCommandType]):
if not list_of_tokens[k+1].startswith('-'): if not list_of_tokens[k+1].startswith('-'):
continue continue
input_flag = InputFlag(name=current_flag_name[current_flag_name.rfind('-')+1:], input_flag = ValidInputFlag(name=current_flag_name[current_flag_name.rfind('-') + 1:],
prefix=cast(Literal['-', '--', '---'], prefix=cast(Literal['-', '--', '---'],
current_flag_name[:current_flag_name.rfind('-')+1]), current_flag_name[:current_flag_name.rfind('-')+1]),
value=current_flag_value) value=current_flag_value)
View File
+13
View File
@@ -0,0 +1,13 @@
from argenta.command.flags.models import ValidInputFlags, UndefinedInputFlags, InvalidValueInputFlags
from argenta.response.status import Status
class Response:
def __init__(self, status: Status,
valid_flags: ValidInputFlags = None,
undefined_flags: UndefinedInputFlags = None,
invalid_value_flags: InvalidValueInputFlags = None):
self.status = status
self.valid_flags = valid_flags
self.undefined_flags = undefined_flags
self.invalid_value_flags = invalid_value_flags
+6
View File
@@ -0,0 +1,6 @@
from enum import Enum
class Status(Enum):
SUCCESSFUL = 200
UNSUCCESSFUL = 400
+4 -17
View File
@@ -3,7 +3,8 @@ from inspect import getfullargspec
from argenta.command import Command from argenta.command import Command
from argenta.command.models import InputCommand from argenta.command.models import InputCommand
from argenta.router.command_handler.entity import CommandHandlers, CommandHandler from argenta.router.command_handler.entity import CommandHandlers, CommandHandler
from argenta.command.flag.models import Flag, Flags, InputFlags from argenta.command.flag.models import Flag
from argenta.command.flags.models import Flags
from argenta.router.exceptions import (RepeatedFlagNameException, from argenta.router.exceptions import (RepeatedFlagNameException,
TooManyTransferredArgsException, TooManyTransferredArgsException,
RequiredArgumentNotPassedException, RequiredArgumentNotPassedException,
@@ -22,7 +23,6 @@ class Router:
self._command_handlers: CommandHandlers = CommandHandlers() self._command_handlers: CommandHandlers = CommandHandlers()
self._ignore_command_register: bool = False self._ignore_command_register: bool = False
self._not_valid_flag_handler: Callable[[Flag], None] = lambda flag: print(f"Undefined or incorrect input flag: {flag.get_string_entity()}{(' '+flag.get_value()) if flag.get_value() else ''}")
def command(self, command: Command) -> Callable: def command(self, command: Command) -> Callable:
@@ -44,15 +44,6 @@ class Router:
return command_decorator return command_decorator
def set_invalid_input_flag_handler(self, func: Callable[[Flag], None]) -> None:
"""
Public. Registers handler for invalid input flag
:param func: registered handler
:return: None
"""
self._not_valid_flag_handler = func
def finds_appropriate_handler(self, input_command: InputCommand) -> None: def finds_appropriate_handler(self, input_command: InputCommand) -> None:
""" """
Private. Finds the appropriate handler for given input command and passes control to it Private. Finds the appropriate handler for given input command and passes control to it
@@ -136,15 +127,11 @@ class Router:
:param func: entity of the handler func :param func: entity of the handler func
:return: None if func is valid else raise exception :return: None if func is valid else raise exception
""" """
registered_args = command.get_registered_flags()
transferred_args = getfullargspec(func).args transferred_args = getfullargspec(func).args
if registered_args.get_flags() and transferred_args: if len(transferred_args) > 1:
if len(transferred_args) != 1:
raise TooManyTransferredArgsException() raise TooManyTransferredArgsException()
elif registered_args.get_flags() and not transferred_args: elif len(transferred_args) == 0:
raise RequiredArgumentNotPassedException() raise RequiredArgumentNotPassedException()
elif not registered_args.get_flags() and transferred_args:
raise TooManyTransferredArgsException()
def set_command_register_ignore(self, _: bool) -> None: def set_command_register_ignore(self, _: bool) -> None:
+6 -6
View File
@@ -1,4 +1,4 @@
from argenta.command.flag import Flag, InputFlag, Flags from argenta.command.flag import Flag, ValidInputFlag, Flags
from argenta.command.models import InputCommand, Command from argenta.command.models import InputCommand, Command
from argenta.command.exceptions import (UnprocessedInputFlagException, from argenta.command.exceptions import (UnprocessedInputFlagException,
RepeatedInputFlagsException, RepeatedInputFlagsException,
@@ -25,23 +25,23 @@ class TestInputCommand(unittest.TestCase):
def test_validate_correct_input_flag1(self): def test_validate_correct_input_flag1(self):
command = Command('some', flags=Flag('test')) command = Command('some', flags=Flag('test'))
self.assertEqual(command.validate_input_flag(InputFlag('test')), True) self.assertEqual(command.validate_input_flag(ValidInputFlag('test')), True)
def test_validate_correct_input_flag2(self): def test_validate_correct_input_flag2(self):
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(ValidInputFlag('more')), True)
def test_validate_incorrect_input_flag1(self): def test_validate_incorrect_input_flag1(self):
command = Command('some', flags=Flags(Flag('test'))) command = Command('some', flags=Flags(Flag('test')))
self.assertEqual(command.validate_input_flag(InputFlag('more')), False) self.assertEqual(command.validate_input_flag(ValidInputFlag('more')), False)
def test_validate_incorrect_input_flag2(self): def test_validate_incorrect_input_flag2(self):
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('case')), False) self.assertEqual(command.validate_input_flag(ValidInputFlag('case')), False)
def test_validate_incorrect_input_flag3(self): def test_validate_incorrect_input_flag3(self):
command = Command('some') command = Command('some')
self.assertEqual(command.validate_input_flag(InputFlag('case')), False) self.assertEqual(command.validate_input_flag(ValidInputFlag('case')), False)
def test_isinstance_parse_correct_raw_command(self): def test_isinstance_parse_correct_raw_command(self):
cmd = InputCommand.parse('ssh --host 192.168.0.3') cmd = InputCommand.parse('ssh --host 192.168.0.3')
+8 -8
View File
@@ -1,4 +1,4 @@
from argenta.command.flag.models import Flag, InputFlag, InputFlags, Flags from argenta.command.flag.models import Flag, ValidInputFlag, InputFlags, Flags
import unittest import unittest
import re import re
@@ -28,11 +28,11 @@ class TestFlag(unittest.TestCase):
'--') '--')
def test_get_flag_value_without_set(self): def test_get_flag_value_without_set(self):
self.assertEqual(InputFlag(name='test').get_value(), self.assertEqual(ValidInputFlag(name='test').get_value(),
None) None)
def test_get_flag_value_with_set(self): def test_get_flag_value_with_set(self):
flag = InputFlag(name='test') flag = ValidInputFlag(name='test')
flag.set_value('example') flag.set_value('example')
self.assertEqual(flag.get_value(), 'example') self.assertEqual(flag.get_value(), 'example')
@@ -69,19 +69,19 @@ class TestFlag(unittest.TestCase):
self.assertEqual(flag.validate_input_flag_value('random value'), True) self.assertEqual(flag.validate_input_flag_value('random value'), True)
def test_get_input_flag1(self): def test_get_input_flag1(self):
flag = InputFlag(name='test') flag = ValidInputFlag(name='test')
input_flags = InputFlags(flag) input_flags = InputFlags(flag)
self.assertEqual(input_flags.get_flag('test'), flag) self.assertEqual(input_flags.get_flag('test'), flag)
def test_get_input_flag2(self): def test_get_input_flag2(self):
flag = InputFlag(name='test') flag = ValidInputFlag(name='test')
flag2 = InputFlag(name='some') flag2 = ValidInputFlag(name='some')
input_flags = InputFlags(flag, flag2) input_flags = InputFlags(flag, flag2)
self.assertEqual(input_flags.get_flag('some'), flag2) self.assertEqual(input_flags.get_flag('some'), flag2)
def test_get_undefined_input_flag(self): def test_get_undefined_input_flag(self):
flag = InputFlag(name='test') flag = ValidInputFlag(name='test')
flag2 = InputFlag(name='some') flag2 = ValidInputFlag(name='some')
input_flags = InputFlags(flag, flag2) input_flags = InputFlags(flag, flag2)
self.assertEqual(input_flags.get_flag('case'), None) self.assertEqual(input_flags.get_flag('case'), None)
+12 -12
View File
@@ -1,4 +1,4 @@
from argenta.command.flag import InputFlags, InputFlag, Flag, Flags from argenta.command.flag import InputFlags, ValidInputFlag, Flag, Flags
from argenta.router import Router from argenta.router import Router
from argenta.command import Command from argenta.command import Command
from argenta.router.exceptions import (TriggerContainSpacesException, from argenta.router.exceptions import (TriggerContainSpacesException,
@@ -27,66 +27,66 @@ class TestRouter(unittest.TestCase):
def test_validate_incorrect_input_flag1(self): def test_validate_incorrect_input_flag1(self):
router = Router() router = Router()
router.set_invalid_input_flag_handler(lambda flag: None) router.set_invalid_input_flag_handler(lambda flag: None)
self.assertEqual(router._validate_input_flags(Command('cmd'), InputFlags(InputFlag('ssh'))), False) self.assertEqual(router._validate_input_flags(Command('cmd'), InputFlags(ValidInputFlag('ssh'))), False)
def test_validate_incorrect_input_flag2(self): def test_validate_incorrect_input_flag2(self):
router = Router() router = Router()
router.set_invalid_input_flag_handler(lambda flag: None) router.set_invalid_input_flag_handler(lambda flag: None)
self.assertEqual(router._validate_input_flags(Command('cmd'), InputFlags(InputFlag('ssh', value='some'))), False) self.assertEqual(router._validate_input_flags(Command('cmd'), InputFlags(ValidInputFlag('ssh', value='some'))), False)
def test_validate_incorrect_input_flag3(self): def test_validate_incorrect_input_flag3(self):
router = Router() router = Router()
router.set_invalid_input_flag_handler(lambda flag: None) router.set_invalid_input_flag_handler(lambda flag: None)
command = Command('cmd', flags=Flag('port')) command = Command('cmd', flags=Flag('port'))
input_flags = InputFlags(InputFlag('ssh', value='some2')) input_flags = InputFlags(ValidInputFlag('ssh', value='some2'))
self.assertEqual(router._validate_input_flags(command, input_flags), False) self.assertEqual(router._validate_input_flags(command, input_flags), False)
def test_validate_incorrect_input_flag4(self): def test_validate_incorrect_input_flag4(self):
router = Router() router = Router()
router.set_invalid_input_flag_handler(lambda flag: None) router.set_invalid_input_flag_handler(lambda flag: None)
command = Command('cmd', flags=Flag('ssh', possible_values=False)) command = Command('cmd', flags=Flag('ssh', possible_values=False))
input_flags = InputFlags(InputFlag('ssh', value='some3')) input_flags = InputFlags(ValidInputFlag('ssh', value='some3'))
self.assertEqual(router._validate_input_flags(command, input_flags), False) self.assertEqual(router._validate_input_flags(command, input_flags), False)
def test_validate_incorrect_input_flag5(self): def test_validate_incorrect_input_flag5(self):
router = Router() router = Router()
router.set_invalid_input_flag_handler(lambda flag: None) router.set_invalid_input_flag_handler(lambda flag: None)
command = Command('cmd', flags=Flag('ssh', possible_values=re.compile(r'some[1-5]$'))) command = Command('cmd', flags=Flag('ssh', possible_values=re.compile(r'some[1-5]$')))
input_flags = InputFlags(InputFlag('ssh', value='some40')) input_flags = InputFlags(ValidInputFlag('ssh', value='some40'))
self.assertEqual(router._validate_input_flags(command, input_flags), False) self.assertEqual(router._validate_input_flags(command, input_flags), False)
def test_validate_incorrect_input_flag6(self): def test_validate_incorrect_input_flag6(self):
router = Router() router = Router()
router.set_invalid_input_flag_handler(lambda flag: None) router.set_invalid_input_flag_handler(lambda flag: None)
command = Command('cmd', flags=Flag('ssh', possible_values=['example'])) command = Command('cmd', flags=Flag('ssh', possible_values=['example']))
input_flags = InputFlags(InputFlag('ssh', value='example2')) input_flags = InputFlags(ValidInputFlag('ssh', value='example2'))
self.assertEqual(router._validate_input_flags(command, input_flags), False) self.assertEqual(router._validate_input_flags(command, input_flags), False)
def test_validate_incorrect_input_flag7(self): def test_validate_incorrect_input_flag7(self):
router = Router() router = Router()
router.set_invalid_input_flag_handler(lambda flag: None) router.set_invalid_input_flag_handler(lambda flag: None)
command = Command('cmd', flags=Flag('ssh', possible_values=['example'])) command = Command('cmd', flags=Flag('ssh', possible_values=['example']))
input_flags = InputFlags(InputFlag('ssh')) input_flags = InputFlags(ValidInputFlag('ssh'))
self.assertEqual(router._validate_input_flags(command, input_flags), False) self.assertEqual(router._validate_input_flags(command, input_flags), False)
def test_validate_correct_input_flag1(self): def test_validate_correct_input_flag1(self):
command = Command('cmd', flags=Flag('port')) command = Command('cmd', flags=Flag('port'))
input_flags = InputFlags(InputFlag('port', value='some2')) input_flags = InputFlags(ValidInputFlag('port', value='some2'))
self.assertEqual(Router()._validate_input_flags(command, input_flags), True) self.assertEqual(Router()._validate_input_flags(command, input_flags), True)
def test_validate_correct_input_flag2(self): def test_validate_correct_input_flag2(self):
command = Command('cmd', flags=Flag('port', possible_values=['some2', 'some3'])) command = Command('cmd', flags=Flag('port', possible_values=['some2', 'some3']))
input_flags = InputFlags(InputFlag('port', value='some2')) input_flags = InputFlags(ValidInputFlag('port', value='some2'))
self.assertEqual(Router()._validate_input_flags(command, input_flags), True) self.assertEqual(Router()._validate_input_flags(command, input_flags), True)
def test_validate_correct_input_flag3(self): def test_validate_correct_input_flag3(self):
command = Command('cmd', flags=Flag('ssh', possible_values=re.compile(r'more[1-5]$'))) command = Command('cmd', flags=Flag('ssh', possible_values=re.compile(r'more[1-5]$')))
input_flags = InputFlags(InputFlag('ssh', value='more5')) input_flags = InputFlags(ValidInputFlag('ssh', value='more5'))
self.assertEqual(Router()._validate_input_flags(command, input_flags), True) self.assertEqual(Router()._validate_input_flags(command, input_flags), True)
def test_validate_correct_input_flag4(self): def test_validate_correct_input_flag4(self):
command = Command('cmd', flags=Flag('ssh', possible_values=False)) command = Command('cmd', flags=Flag('ssh', possible_values=False))
input_flags = InputFlags(InputFlag('ssh')) input_flags = InputFlags(ValidInputFlag('ssh'))
self.assertEqual(Router()._validate_input_flags(command, input_flags), True) self.assertEqual(Router()._validate_input_flags(command, input_flags), True)
def test_validate_incorrect_func_args1(self): def test_validate_incorrect_func_args1(self):