argenta 1.0.0b1__tar.gz → 1.0.0b2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. {argenta-1.0.0b1 → argenta-1.0.0b2}/PKG-INFO +3 -3
  2. {argenta-1.0.0b1 → argenta-1.0.0b2}/mock/local_test.py +8 -2
  3. {argenta-1.0.0b1 → argenta-1.0.0b2}/mock/mock_app/handlers/routers.py +1 -1
  4. {argenta-1.0.0b1 → argenta-1.0.0b2}/pyproject.toml +3 -3
  5. {argenta-1.0.0b1 → argenta-1.0.0b2}/src/argenta/app/models.py +2 -2
  6. {argenta-1.0.0b1 → argenta-1.0.0b2}/src/argenta/command/flag/models.py +6 -0
  7. {argenta-1.0.0b1 → argenta-1.0.0b2}/src/argenta/command/flags/models.py +12 -0
  8. {argenta-1.0.0b1 → argenta-1.0.0b2}/src/argenta/command/models.py +1 -1
  9. {argenta-1.0.0b1 → argenta-1.0.0b2}/src/argenta/response/entity.py +8 -1
  10. {argenta-1.0.0b1 → argenta-1.0.0b2}/src/argenta/router/entity.py +42 -26
  11. {argenta-1.0.0b1 → argenta-1.0.0b2}/tests/system_tests/test_system_handling_non_standard_behavior.py +44 -30
  12. {argenta-1.0.0b1 → argenta-1.0.0b2}/tests/system_tests/test_system_handling_normal_behavior.py +48 -33
  13. {argenta-1.0.0b1 → argenta-1.0.0b2}/tests/unit_tests/test_command.py +26 -12
  14. {argenta-1.0.0b1 → argenta-1.0.0b2}/tests/unit_tests/test_flag.py +2 -1
  15. {argenta-1.0.0b1 → argenta-1.0.0b2}/tests/unit_tests/test_router.py +34 -50
  16. {argenta-1.0.0b1 → argenta-1.0.0b2}/.github/workflows/ruff.yml +0 -0
  17. {argenta-1.0.0b1 → argenta-1.0.0b2}/.github/workflows/tests.yml +0 -0
  18. {argenta-1.0.0b1 → argenta-1.0.0b2}/.gitignore +0 -0
  19. {argenta-1.0.0b1 → argenta-1.0.0b2}/LICENSE +0 -0
  20. {argenta-1.0.0b1 → argenta-1.0.0b2}/README.md +0 -0
  21. {argenta-1.0.0b1 → argenta-1.0.0b2}/imgs/mock_app_preview1.png +0 -0
  22. {argenta-1.0.0b1 → argenta-1.0.0b2}/imgs/mock_app_preview2.png +0 -0
  23. {argenta-1.0.0b1 → argenta-1.0.0b2}/imgs/mock_app_preview3.png +0 -0
  24. {argenta-1.0.0b1 → argenta-1.0.0b2}/imgs/mock_app_preview4.png +0 -0
  25. {argenta-1.0.0b1 → argenta-1.0.0b2}/mock/__init__.py +0 -0
  26. {argenta-1.0.0b1 → argenta-1.0.0b2}/mock/default_mock_app/__init__.py +0 -0
  27. {argenta-1.0.0b1 → argenta-1.0.0b2}/mock/default_mock_app/main.py +0 -0
  28. {argenta-1.0.0b1 → argenta-1.0.0b2}/mock/mock_app/__init__.py +0 -0
  29. {argenta-1.0.0b1 → argenta-1.0.0b2}/mock/mock_app/handlers/__init__.py +0 -0
  30. {argenta-1.0.0b1 → argenta-1.0.0b2}/mock/mock_app/handlers/handlers_implementation/__init__.py +0 -0
  31. {argenta-1.0.0b1 → argenta-1.0.0b2}/mock/mock_app/handlers/handlers_implementation/help_command.py +0 -0
  32. {argenta-1.0.0b1 → argenta-1.0.0b2}/mock/mock_app/main.py +0 -0
  33. {argenta-1.0.0b1 → argenta-1.0.0b2}/src/__init__.py +0 -0
  34. {argenta-1.0.0b1 → argenta-1.0.0b2}/src/argenta/__init__.py +0 -0
  35. {argenta-1.0.0b1 → argenta-1.0.0b2}/src/argenta/app/__init__.py +0 -0
  36. {argenta-1.0.0b1 → argenta-1.0.0b2}/src/argenta/app/autocompleter/__init__.py +0 -0
  37. {argenta-1.0.0b1 → argenta-1.0.0b2}/src/argenta/app/autocompleter/entity.py +0 -0
  38. {argenta-1.0.0b1 → argenta-1.0.0b2}/src/argenta/app/defaults.py +0 -0
  39. {argenta-1.0.0b1 → argenta-1.0.0b2}/src/argenta/app/dividing_line/__init__.py +0 -0
  40. {argenta-1.0.0b1 → argenta-1.0.0b2}/src/argenta/app/dividing_line/models.py +0 -0
  41. {argenta-1.0.0b1 → argenta-1.0.0b2}/src/argenta/app/registered_routers/__init__.py +0 -0
  42. {argenta-1.0.0b1 → argenta-1.0.0b2}/src/argenta/app/registered_routers/entity.py +0 -0
  43. {argenta-1.0.0b1 → argenta-1.0.0b2}/src/argenta/command/__init__.py +0 -0
  44. {argenta-1.0.0b1 → argenta-1.0.0b2}/src/argenta/command/exceptions.py +0 -0
  45. {argenta-1.0.0b1 → argenta-1.0.0b2}/src/argenta/command/flag/__init__.py +0 -0
  46. {argenta-1.0.0b1 → argenta-1.0.0b2}/src/argenta/command/flag/defaults.py +0 -0
  47. {argenta-1.0.0b1 → argenta-1.0.0b2}/src/argenta/command/flags/__init__.py +0 -0
  48. {argenta-1.0.0b1 → argenta-1.0.0b2}/src/argenta/orchestrator/__init__.py +0 -0
  49. {argenta-1.0.0b1 → argenta-1.0.0b2}/src/argenta/orchestrator/argparser/__init__.py +0 -0
  50. {argenta-1.0.0b1 → argenta-1.0.0b2}/src/argenta/orchestrator/argparser/arguments/__init__.py +0 -0
  51. {argenta-1.0.0b1 → argenta-1.0.0b2}/src/argenta/orchestrator/argparser/arguments/models.py +0 -0
  52. {argenta-1.0.0b1 → argenta-1.0.0b2}/src/argenta/orchestrator/argparser/entity.py +0 -0
  53. {argenta-1.0.0b1 → argenta-1.0.0b2}/src/argenta/orchestrator/entity.py +0 -0
  54. {argenta-1.0.0b1 → argenta-1.0.0b2}/src/argenta/response/__init__.py +0 -0
  55. {argenta-1.0.0b1 → argenta-1.0.0b2}/src/argenta/response/status.py +0 -0
  56. {argenta-1.0.0b1 → argenta-1.0.0b2}/src/argenta/router/__init__.py +0 -0
  57. {argenta-1.0.0b1 → argenta-1.0.0b2}/src/argenta/router/command_handler/__init__.py +0 -0
  58. {argenta-1.0.0b1 → argenta-1.0.0b2}/src/argenta/router/command_handler/entity.py +0 -0
  59. {argenta-1.0.0b1 → argenta-1.0.0b2}/src/argenta/router/defaults.py +0 -0
  60. {argenta-1.0.0b1 → argenta-1.0.0b2}/src/argenta/router/exceptions.py +0 -0
  61. {argenta-1.0.0b1 → argenta-1.0.0b2}/tests/__init__.py +0 -0
  62. {argenta-1.0.0b1 → argenta-1.0.0b2}/tests/system_tests/__init__.py +0 -0
  63. {argenta-1.0.0b1 → argenta-1.0.0b2}/tests/unit_tests/__init__.py +0 -0
  64. {argenta-1.0.0b1 → argenta-1.0.0b2}/tests/unit_tests/test_app.py +0 -0
  65. {argenta-1.0.0b1 → argenta-1.0.0b2}/tests/unit_tests/test_dividing_line.py +0 -0
@@ -1,13 +1,13 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: argenta
3
- Version: 1.0.0b1
4
- Summary: Python library for creating TUI
3
+ Version: 1.0.0b2
4
+ Summary: Python library for building modular CLI applications
5
5
  Author-email: kolo <kolo.is.main@gmail.com>
6
6
  License: MIT
7
7
  License-File: LICENSE
8
8
  Requires-Python: <4.0,>=3.11
9
9
  Requires-Dist: art<7.0,>=6.4
10
- Requires-Dist: pyreadline3<4.0.0,>=3.5.4
10
+ Requires-Dist: pyreadline3>=3.5.4
11
11
  Requires-Dist: rich<15.0.0,>=14.0.0
12
12
  Description-Content-Type: text/markdown
13
13
 
@@ -11,7 +11,13 @@ from argenta.router import Router
11
11
  from argenta.orchestrator import Orchestrator
12
12
 
13
13
  from argenta.command.models import InputCommand
14
- from argenta.app.utils import most_similar_command
14
+ import inspect
15
15
 
16
16
 
17
- print(most_similar_command('case', ['case', 'tester', 'poster', 'caser']))
17
+ router = Router()
18
+
19
+
20
+ @router.command(Command('some'))
21
+ def handler(res: Response) -> Response:
22
+ pass
23
+
@@ -20,7 +20,7 @@ def command_help(response: Response):
20
20
  print(response.invalid_value_flags.get_flags())
21
21
 
22
22
 
23
- @work_router.command(Command('run', 'Run All'))
23
+ @work_router.command('run')
24
24
  def command_start_solving(response: Response):
25
25
  print(response.status)
26
26
  print(response.undefined_flags.get_flags())
@@ -1,7 +1,7 @@
1
1
  [project]
2
2
  name = "argenta"
3
- version = "1.0.0-beta1"
4
- description = "Python library for creating TUI"
3
+ version = "1.0.0-beta2"
4
+ description = "Python library for building modular CLI applications"
5
5
  authors = [{ name = "kolo", email = "kolo.is.main@gmail.com" }]
6
6
  requires-python = ">=3.11, <4.0"
7
7
  readme = "README.md"
@@ -9,7 +9,7 @@ license = { text = "MIT" }
9
9
  dependencies = [
10
10
  "rich (>=14.0.0,<15.0.0)",
11
11
  "art (>=6.4,<7.0)",
12
- "pyreadline3 (>=3.5.4,<4.0.0)",
12
+ "pyreadline3>=3.5.4",
13
13
  ]
14
14
 
15
15
  [dependency-groups]
@@ -238,7 +238,7 @@ class BaseApp:
238
238
  :return: None
239
239
  """
240
240
  self._prompt = '[italic dim bold]What do you want to do?\n'
241
- self._initial_message = f'\n[bold red]{text2art(self._initial_message, font="tarty1")}\n\n'
241
+ self._initial_message = f'\n[bold red]{text2art(self._initial_message, font="tarty1")}\n'
242
242
  self._farewell_message = (f'[bold red]\n{text2art(f"\n{self._farewell_message}\n", font="chanky")}[/bold red]\n'
243
243
  f'[red i]github.com/koloideal/Argenta[/red i] | [red bold i]made by kolo[/red bold i]\n')
244
244
  self._description_message_gen = lambda command, description: (f'[bold red]{escape("[" + command + "]")}[/bold red] '
@@ -282,7 +282,7 @@ class BaseApp:
282
282
  for message in self._messages_on_startup:
283
283
  self._print_func(message)
284
284
  if self._messages_on_startup:
285
- print('\n\n')
285
+ print('\n')
286
286
 
287
287
  if not self._repeat_command_groups_description:
288
288
  self._print_command_group_description()
@@ -36,6 +36,9 @@ class BaseFlag:
36
36
  """
37
37
  return self._prefix
38
38
 
39
+ def __eq__(self, other) -> bool:
40
+ return self.get_string_entity() == other.get_string_entity()
41
+
39
42
 
40
43
  class Flag(BaseFlag):
41
44
  def __init__(self, name: str,
@@ -110,3 +113,6 @@ class InputFlag(BaseFlag):
110
113
  """
111
114
  self._flag_value = value
112
115
 
116
+ def __eq__(self, other) -> bool:
117
+ return self.get_string_entity() == other.get_string_entity() and self.get_value() == other.get_value()
118
+
@@ -58,6 +58,18 @@ class BaseFlags(Generic[FlagType]):
58
58
  def __getitem__(self, item):
59
59
  return self._flags[item]
60
60
 
61
+ def __bool__(self):
62
+ return bool(self._flags)
63
+
64
+ def __eq__(self, other):
65
+ if len(self.get_flags()) != len(other.get_flags()):
66
+ return False
67
+ else:
68
+ for flag, other_flag in zip(self.get_flags(), other.get_flags()):
69
+ if not flag == other_flag:
70
+ return False
71
+ return True
72
+
61
73
 
62
74
  class Flags(BaseFlags[Flag]): pass
63
75
 
@@ -39,7 +39,7 @@ class Command(BaseCommand):
39
39
  """
40
40
  super().__init__(trigger)
41
41
  self._registered_flags: Flags = flags if isinstance(flags, Flags) else Flags(flags) if isinstance(flags, Flag) else Flags()
42
- self._description = f'Description for "{self._trigger}" command' if not description else description
42
+ self._description = f'Very useful command' if not description else description
43
43
  self._aliases = aliases if isinstance(aliases, list) else []
44
44
 
45
45
  def get_registered_flags(self) -> Flags:
@@ -1,8 +1,15 @@
1
- from argenta.command.flags.models import ValidInputFlags, UndefinedInputFlags, InvalidValueInputFlags
2
1
  from argenta.response.status import Status
2
+ from argenta.command.flags import (ValidInputFlags,
3
+ UndefinedInputFlags,
4
+ InvalidValueInputFlags)
3
5
 
4
6
 
5
7
  class Response:
8
+ __slots__ = ('status',
9
+ 'valid_flags',
10
+ 'undefined_flags',
11
+ 'invalid_value_flags')
12
+
6
13
  def __init__(self, status: Status = None,
7
14
  valid_flags: ValidInputFlags = ValidInputFlags(),
8
15
  undefined_flags: UndefinedInputFlags = UndefinedInputFlags(),
@@ -1,12 +1,15 @@
1
1
  from typing import Callable, Literal, Type
2
- from inspect import getfullargspec, get_annotations
2
+ from inspect import getfullargspec, get_annotations, getsourcefile, getsourcelines
3
3
  from rich.console import Console
4
4
 
5
5
  from argenta.command import Command
6
6
  from argenta.command.models import InputCommand
7
7
  from argenta.response import Response, Status
8
8
  from argenta.router.command_handler.entity import CommandHandlers, CommandHandler
9
- from argenta.command.flags.models import Flags, InputFlags, UndefinedInputFlags, ValidInputFlags, InvalidValueInputFlags
9
+ from argenta.command.flags.models import (Flags, InputFlags,
10
+ UndefinedInputFlags,
11
+ ValidInputFlags,
12
+ InvalidValueInputFlags)
10
13
  from argenta.router.exceptions import (RepeatedFlagNameException,
11
14
  TooManyTransferredArgsException,
12
15
  RequiredArgumentNotPassedException,
@@ -26,13 +29,15 @@ class Router:
26
29
  self._ignore_command_register: bool = False
27
30
 
28
31
 
29
- def command(self, command: Command) -> Callable:
32
+ def command(self, command: Command | str) -> Callable:
30
33
  """
31
34
  Public. Registers handler
32
35
  :param command: Registered command
33
36
  :return: decorated handler as Callable
34
37
  """
35
38
  self._validate_command(command)
39
+ if isinstance(command, str):
40
+ command = Command(command)
36
41
 
37
42
  def command_decorator(func):
38
43
  Router._validate_func_args(func)
@@ -73,9 +78,7 @@ class Router:
73
78
  response: Response = Response()
74
79
  if handle_command.get_registered_flags().get_flags():
75
80
  if input_command_flags.get_flags():
76
- flags, status = self._validate_input_flags(handle_command, input_command_flags)
77
- response.valid_flags, response.undefined_flags, response.invalid_value_flags = flags
78
- response.status = status
81
+ response: Response = self._structuring_input_flags(handle_command, input_command_flags)
79
82
  command_handler.handling(response)
80
83
  else:
81
84
  response.status = Status.ALL_FLAGS_VALID
@@ -92,15 +95,12 @@ class Router:
92
95
 
93
96
 
94
97
  @staticmethod
95
- def _validate_input_flags(handled_command: Command, input_flags: InputFlags) -> tuple[tuple[ValidInputFlags,
96
- UndefinedInputFlags,
97
- InvalidValueInputFlags],
98
- Status]:
98
+ def _structuring_input_flags(handled_command: Command, input_flags: InputFlags) -> Response:
99
99
  """
100
100
  Private. Validates flags of input command
101
101
  :param handled_command: entity of the handled command
102
102
  :param input_flags:
103
- :return: is flags of input command valid as bool
103
+ :return: entity of response as Response
104
104
  """
105
105
  valid_input_flags: ValidInputFlags = ValidInputFlags()
106
106
  invalid_value_input_flags: InvalidValueInputFlags = InvalidValueInputFlags()
@@ -124,25 +124,32 @@ class Router:
124
124
  else:
125
125
  status = Status.UNDEFINED_AND_INVALID_FLAGS
126
126
 
127
- return (valid_input_flags, undefined_input_flags, invalid_value_input_flags), status
127
+ return Response(invalid_value_flags=invalid_value_input_flags,
128
+ valid_flags=valid_input_flags,
129
+ status=status,
130
+ undefined_flags=undefined_input_flags)
128
131
 
129
132
 
130
133
  @staticmethod
131
- def _validate_command(command: Command) -> None:
134
+ def _validate_command(command: Command | str) -> None:
132
135
  """
133
136
  Private. Validates the command registered in handler
134
137
  :param command: validated command
135
138
  :return: None if command is valid else raise exception
136
139
  """
137
- command_name: str = command.get_trigger()
138
- if command_name.find(' ') != -1:
139
- raise TriggerContainSpacesException()
140
-
141
- flags: Flags = command.get_registered_flags()
142
- if flags:
143
- flags_name: list = [x.get_string_entity().lower() for x in flags]
144
- if len(set(flags_name)) < len(flags_name):
145
- raise RepeatedFlagNameException()
140
+ match type(command).__name__:
141
+ case 'Command':
142
+ command_name: str = command.get_trigger()
143
+ if command_name.find(' ') != -1:
144
+ raise TriggerContainSpacesException()
145
+ flags: Flags = command.get_registered_flags()
146
+ if flags:
147
+ flags_name: list = [x.get_string_entity().lower() for x in flags]
148
+ if len(set(flags_name)) < len(flags_name):
149
+ raise RepeatedFlagNameException()
150
+ case 'str':
151
+ if command.find(' ') != -1:
152
+ raise TriggerContainSpacesException()
146
153
 
147
154
 
148
155
  @staticmethod
@@ -158,10 +165,19 @@ class Router:
158
165
  elif len(transferred_args) == 0:
159
166
  raise RequiredArgumentNotPassedException()
160
167
 
161
- arg_annotation: Type = get_annotations(func)[transferred_args[0]]
162
- if not arg_annotation is Response:
163
- Console().print(f'\n\n[b red]WARNING:[/b red] [i]The type of argument passed to the handler is [/i][blue]{Response}[/blue],'
164
- f' [i]but[/i] [bold blue]{arg_annotation}[/bold blue] [i]is specified[/i]', highlight=False)
168
+ transferred_arg: str = transferred_args[0]
169
+ func_annotations: dict[str, Type] = get_annotations(func)
170
+
171
+ if arg_annotation := func_annotations.get(transferred_arg):
172
+ if arg_annotation is Response:
173
+ pass
174
+ else:
175
+ file_path: str = getsourcefile(func)
176
+ source_line: int = getsourcelines(func)[1]+1
177
+ fprint = Console().print
178
+ fprint(f'\nFile "{file_path}", line {source_line}\n[b red]WARNING:[/b red] [i]The typehint '
179
+ f'of argument([green]{transferred_arg}[/green]) passed to the handler is [/i][bold blue]{Response}[/bold blue],'
180
+ f' [i]but[/i] [bold blue]{arg_annotation}[/bold blue] [i]is specified[/i]\n', highlight=False)
165
181
 
166
182
 
167
183
 
@@ -1,32 +1,35 @@
1
1
  import _io
2
2
  from unittest.mock import patch, MagicMock
3
- import unittest
3
+ from unittest import TestCase
4
4
  import io
5
5
  import re
6
6
 
7
7
  from argenta.app import App
8
8
  from argenta.command import Command
9
9
  from argenta.router import Router
10
- from argenta.command.flag.models import Flags, InputFlags
10
+ from argenta.command.flags.models import Flags
11
11
  from argenta.command.flag.defaults import PredefinedFlags
12
+ from argenta.orchestrator import Orchestrator
13
+ from argenta.response import Response
12
14
 
13
15
 
14
16
 
15
- class TestSystemHandlerNormalWork(unittest.TestCase):
17
+ class TestSystemHandlerNormalWork(TestCase):
16
18
  @patch("builtins.input", side_effect=["help", "q"])
17
19
  @patch("sys.stdout", new_callable=io.StringIO)
18
20
  def test_input_incorrect_command(self, mock_stdout: _io.StringIO, magick_mock: MagicMock):
19
21
  router = Router()
22
+ orchestrator = Orchestrator()
20
23
 
21
24
  @router.command(Command('test'))
22
- def test():
25
+ def test(response: Response):
23
26
  print('test command')
24
27
 
25
28
  app = App(override_system_messages=True,
26
29
  print_func=print)
27
30
  app.include_router(router)
28
31
  app.set_unknown_command_handler(lambda command: print(f'Unknown command: {command.get_trigger()}'))
29
- app.run_polling()
32
+ orchestrator.start_polling(app)
30
33
 
31
34
  output = mock_stdout.getvalue()
32
35
 
@@ -37,9 +40,10 @@ class TestSystemHandlerNormalWork(unittest.TestCase):
37
40
  @patch("sys.stdout", new_callable=io.StringIO)
38
41
  def test_input_incorrect_command2(self, mock_stdout: _io.StringIO, magick_mock: MagicMock):
39
42
  router = Router()
43
+ orchestrator = Orchestrator()
40
44
 
41
45
  @router.command(Command('test'))
42
- def test():
46
+ def test(response: Response):
43
47
  print('test command')
44
48
 
45
49
  app = App(ignore_command_register=False,
@@ -47,7 +51,7 @@ class TestSystemHandlerNormalWork(unittest.TestCase):
47
51
  print_func=print)
48
52
  app.include_router(router)
49
53
  app.set_unknown_command_handler(lambda command: print(f'Unknown command: {command.get_trigger()}'))
50
- app.run_polling()
54
+ orchestrator.start_polling(app)
51
55
 
52
56
  output = mock_stdout.getvalue()
53
57
 
@@ -58,74 +62,80 @@ class TestSystemHandlerNormalWork(unittest.TestCase):
58
62
  @patch("sys.stdout", new_callable=io.StringIO)
59
63
  def test_input_correct_command_with_unregistered_flag(self, mock_stdout: _io.StringIO, magick_mock: MagicMock):
60
64
  router = Router()
65
+ orchestrator = Orchestrator()
61
66
 
62
67
  @router.command(Command('test'))
63
- def test():
64
- print(f'test command')
68
+ def test(response: Response):
69
+ print(f'test command with undefined flag: {response.undefined_flags.get_flag('help').get_string_entity()}')
65
70
 
66
71
  app = App(override_system_messages=True,
67
72
  print_func=print)
68
73
  app.include_router(router)
69
- app.run_polling()
74
+ orchestrator.start_polling(app)
70
75
 
71
76
  output = mock_stdout.getvalue()
72
77
 
73
- self.assertIn('\nUndefined or incorrect input flag: --help\n', output)
78
+ self.assertIn('\ntest command with undefined flag: --help\n', output)
74
79
 
75
80
 
76
81
  @patch("builtins.input", side_effect=["test --port 22", "q"])
77
82
  @patch("sys.stdout", new_callable=io.StringIO)
78
83
  def test_input_correct_command_with_unregistered_flag2(self, mock_stdout: _io.StringIO, magick_mock: MagicMock):
79
84
  router = Router()
85
+ orchestrator = Orchestrator()
80
86
 
81
87
  @router.command(Command('test'))
82
- def test():
83
- print('test command')
88
+ def test(response: Response):
89
+ flag = response.undefined_flags.get_flag("port")
90
+ print(f'test command with undefined flag with value: {flag.get_string_entity()} {flag.get_value()}')
84
91
 
85
92
  app = App(override_system_messages=True,
86
93
  print_func=print)
87
94
  app.include_router(router)
88
- app.run_polling()
95
+ orchestrator.start_polling(app)
89
96
 
90
97
  output = mock_stdout.getvalue()
91
98
 
92
- self.assertIn('\nUndefined or incorrect input flag: --port 22\n', output)
99
+ self.assertIn('\ntest command with undefined flag with value: --port 22\n', output)
93
100
 
94
101
 
95
102
  @patch("builtins.input", side_effect=["test --host 192.168.32.1 --port 132", "q"])
96
103
  @patch("sys.stdout", new_callable=io.StringIO)
97
104
  def test_input_correct_command_with_one_correct_flag_an_one_incorrect_flag(self, mock_stdout: _io.StringIO, magick_mock: MagicMock):
98
105
  router = Router()
106
+ orchestrator = Orchestrator()
99
107
  flags = Flags(PredefinedFlags.HOST)
100
108
 
101
109
  @router.command(Command('test', flags=flags))
102
- def test(args: InputFlags):
103
- print(f'connecting to host {args.get_flag('host').get_value()}')
110
+ def test(response: Response):
111
+ flag = response.undefined_flags.get_flag("port")
112
+ print(f'connecting to host with flag: {flag.get_string_entity()} {flag.get_value()}')
104
113
 
105
114
  app = App(override_system_messages=True,
106
115
  print_func=print)
107
116
  app.include_router(router)
108
- app.run_polling()
117
+ orchestrator.start_polling(app)
109
118
 
110
119
  output = mock_stdout.getvalue()
111
120
 
112
- self.assertIn('\nUndefined or incorrect input flag: --port 132\n', output)
121
+ self.assertIn('\nconnecting to host with flag: --port 132\n', output)
113
122
 
114
123
 
115
124
  @patch("builtins.input", side_effect=["test", "some", "q"])
116
125
  @patch("sys.stdout", new_callable=io.StringIO)
117
126
  def test_input_one_correct_command_and_one_incorrect_command(self, mock_stdout: _io.StringIO, magick_mock: MagicMock):
118
127
  router = Router()
128
+ orchestrator = Orchestrator()
119
129
 
120
130
  @router.command(Command('test'))
121
- def test():
131
+ def test(response: Response):
122
132
  print(f'test command')
123
133
 
124
134
  app = App(override_system_messages=True,
125
135
  print_func=print)
126
136
  app.include_router(router)
127
137
  app.set_unknown_command_handler(lambda command: print(f'Unknown command: {command.get_trigger()}'))
128
- app.run_polling()
138
+ orchestrator.start_polling(app)
129
139
 
130
140
  output = mock_stdout.getvalue()
131
141
 
@@ -136,20 +146,21 @@ class TestSystemHandlerNormalWork(unittest.TestCase):
136
146
  @patch("sys.stdout", new_callable=io.StringIO)
137
147
  def test_input_two_correct_commands_and_one_incorrect_command(self, mock_stdout: _io.StringIO, magick_mock: MagicMock):
138
148
  router = Router()
149
+ orchestrator = Orchestrator()
139
150
 
140
151
  @router.command(Command('test'))
141
- def test():
152
+ def test(response: Response):
142
153
  print(f'test command')
143
154
 
144
155
  @router.command(Command('more'))
145
- def test():
156
+ def test(response: Response):
146
157
  print(f'more command')
147
158
 
148
159
  app = App(override_system_messages=True,
149
160
  print_func=print)
150
161
  app.include_router(router)
151
162
  app.set_unknown_command_handler(lambda command: print(f'Unknown command: {command.get_trigger()}'))
152
- app.run_polling()
163
+ orchestrator.start_polling(app)
153
164
 
154
165
  output = mock_stdout.getvalue()
155
166
 
@@ -160,16 +171,17 @@ class TestSystemHandlerNormalWork(unittest.TestCase):
160
171
  @patch("sys.stdout", new_callable=io.StringIO)
161
172
  def test_input_correct_command_with_incorrect_flag(self, mock_stdout: _io.StringIO, magick_mock: MagicMock):
162
173
  router = Router()
174
+ orchestrator = Orchestrator()
163
175
 
164
176
  @router.command(Command('test'))
165
- def test():
177
+ def test(response: Response):
166
178
  print(f'test command')
167
179
 
168
180
  app = App(override_system_messages=True,
169
181
  print_func=print)
170
182
  app.include_router(router)
171
183
  app.set_invalid_input_flags_handler(lambda command: print(f'Incorrect flag syntax: "{command}"'))
172
- app.run_polling()
184
+ orchestrator.start_polling(app)
173
185
 
174
186
  output = mock_stdout.getvalue()
175
187
 
@@ -180,16 +192,17 @@ class TestSystemHandlerNormalWork(unittest.TestCase):
180
192
  @patch("sys.stdout", new_callable=io.StringIO)
181
193
  def test_input_empty_command(self, mock_stdout: _io.StringIO, magick_mock: MagicMock):
182
194
  router = Router()
195
+ orchestrator = Orchestrator()
183
196
 
184
197
  @router.command(Command('test'))
185
- def test():
198
+ def test(response: Response):
186
199
  print(f'test command')
187
200
 
188
201
  app = App(override_system_messages=True,
189
202
  print_func=print)
190
203
  app.include_router(router)
191
204
  app.set_empty_command_handler(lambda: print('Empty input command'))
192
- app.run_polling()
205
+ orchestrator.start_polling(app)
193
206
 
194
207
  output = mock_stdout.getvalue()
195
208
 
@@ -200,16 +213,17 @@ class TestSystemHandlerNormalWork(unittest.TestCase):
200
213
  @patch("sys.stdout", new_callable=io.StringIO)
201
214
  def test_input_correct_command_with_repeated_flags(self, mock_stdout: _io.StringIO, magick_mock: MagicMock):
202
215
  router = Router()
216
+ orchestrator = Orchestrator()
203
217
 
204
218
  @router.command(Command('test', flags=PredefinedFlags.PORT))
205
- def test(args: InputFlags):
219
+ def test(response: Response):
206
220
  print('test command')
207
221
 
208
222
  app = App(override_system_messages=True,
209
223
  print_func=print)
210
224
  app.include_router(router)
211
225
  app.set_repeated_input_flags_handler(lambda command: print(f'Repeated input flags: "{command}"'))
212
- app.run_polling()
226
+ orchestrator.start_polling(app)
213
227
 
214
228
  output = mock_stdout.getvalue()
215
229
 
@@ -1,31 +1,35 @@
1
1
  import _io
2
2
  from unittest.mock import patch, MagicMock
3
- import unittest
3
+ from unittest import TestCase
4
4
  import io
5
5
  import re
6
6
 
7
7
  from argenta.app import App
8
- from argenta.command.models import Command
8
+ from argenta.command import Command
9
+ from argenta.response import Response
9
10
  from argenta.router import Router
10
- from argenta.command.flag.models import Flag, Flags, InputFlags
11
+ from argenta.orchestrator import Orchestrator
12
+ from argenta.command.flag import Flag
13
+ from argenta.command.flags import Flags
11
14
  from argenta.command.flag.defaults import PredefinedFlags
12
15
 
13
16
 
14
17
 
15
- class TestSystemHandlerNormalWork(unittest.TestCase):
18
+ class TestSystemHandlerNormalWork(TestCase):
16
19
  @patch("builtins.input", side_effect=["test", "q"])
17
20
  @patch("sys.stdout", new_callable=io.StringIO)
18
21
  def test_input_correct_command(self, mock_stdout: _io.StringIO, magick_mock: MagicMock):
19
22
  router = Router()
23
+ orchestrator = Orchestrator()
20
24
 
21
25
  @router.command(Command('test'))
22
- def test():
26
+ def test(response):
23
27
  print('test command')
24
28
 
25
29
  app = App(override_system_messages=True,
26
30
  print_func=print)
27
31
  app.include_router(router)
28
- app.run_polling()
32
+ orchestrator.start_polling(app)
29
33
 
30
34
  output = mock_stdout.getvalue()
31
35
 
@@ -36,16 +40,17 @@ class TestSystemHandlerNormalWork(unittest.TestCase):
36
40
  @patch("sys.stdout", new_callable=io.StringIO)
37
41
  def test_input_correct_command2(self, mock_stdout: _io.StringIO, magick_mock: MagicMock):
38
42
  router = Router()
43
+ orchestrator = Orchestrator()
39
44
 
40
45
  @router.command(Command('test'))
41
- def test():
46
+ def test(response):
42
47
  print('test command')
43
48
 
44
49
  app = App(ignore_command_register=True,
45
50
  override_system_messages=True,
46
51
  print_func=print)
47
52
  app.include_router(router)
48
- app.run_polling()
53
+ orchestrator.start_polling(app)
49
54
 
50
55
  output = mock_stdout.getvalue()
51
56
 
@@ -56,16 +61,17 @@ class TestSystemHandlerNormalWork(unittest.TestCase):
56
61
  @patch("sys.stdout", new_callable=io.StringIO)
57
62
  def test_input_correct_command_with_custom_flag(self, mock_stdout: _io.StringIO, magick_mock: MagicMock):
58
63
  router = Router()
64
+ orchestrator = Orchestrator()
59
65
  flag = Flag('help', '--', False)
60
66
 
61
67
  @router.command(Command('test', flags=flag))
62
- def test(args: InputFlags):
63
- print(f'\nhelp for {args.get_flag('help').get_name()} flag\n')
68
+ def test(response: Response):
69
+ print(f'\nhelp for {response.valid_flags.get_flag('help').get_name()} flag\n')
64
70
 
65
71
  app = App(override_system_messages=True,
66
72
  print_func=print)
67
73
  app.include_router(router)
68
- app.run_polling()
74
+ orchestrator.start_polling(app)
69
75
 
70
76
  output = mock_stdout.getvalue()
71
77
 
@@ -75,16 +81,18 @@ class TestSystemHandlerNormalWork(unittest.TestCase):
75
81
  @patch("sys.stdout", new_callable=io.StringIO)
76
82
  def test_input_correct_command_with_custom_flag2(self, mock_stdout: _io.StringIO, magick_mock: MagicMock):
77
83
  router = Router()
84
+ orchestrator = Orchestrator()
78
85
  flag = Flag('port', '--', re.compile(r'^\d{1,5}$'))
79
86
 
80
87
  @router.command(Command('test', flags=flag))
81
- def test(args: InputFlags):
82
- print(f'flag value for {args.get_flag('port').get_name()} flag : {args.get_flag('port').get_value()}')
88
+ def test(response: Response):
89
+ input_flag = response.valid_flags.get_flag('port')
90
+ print(f'flag value for {input_flag.get_name()} flag : {input_flag.get_value()}')
83
91
 
84
92
  app = App(override_system_messages=True,
85
93
  print_func=print)
86
94
  app.include_router(router)
87
- app.run_polling()
95
+ orchestrator.start_polling(app)
88
96
 
89
97
  output = mock_stdout.getvalue()
90
98
 
@@ -95,16 +103,17 @@ class TestSystemHandlerNormalWork(unittest.TestCase):
95
103
  @patch("sys.stdout", new_callable=io.StringIO)
96
104
  def test_input_correct_command_with_default_flag(self, mock_stdout: _io.StringIO, magick_mock: MagicMock):
97
105
  router = Router()
106
+ orchestrator = Orchestrator()
98
107
  flag = PredefinedFlags.SHORT_HELP
99
108
 
100
109
  @router.command(Command('test', flags=flag))
101
- def test(args: InputFlags):
102
- print(f'help for {args.get_flag('H').get_name()} flag')
110
+ def test(response: Response):
111
+ print(f'help for {response.valid_flags.get_flag('H').get_name()} flag')
103
112
 
104
113
  app = App(override_system_messages=True,
105
114
  print_func=print)
106
115
  app.include_router(router)
107
- app.run_polling()
116
+ orchestrator.start_polling(app)
108
117
 
109
118
  output = mock_stdout.getvalue()
110
119
 
@@ -115,17 +124,18 @@ class TestSystemHandlerNormalWork(unittest.TestCase):
115
124
  @patch("sys.stdout", new_callable=io.StringIO)
116
125
  def test_input_correct_command_with_default_flag2(self, mock_stdout: _io.StringIO, magick_mock: MagicMock):
117
126
  router = Router()
127
+ orchestrator = Orchestrator()
118
128
  flag = PredefinedFlags.INFO
119
129
 
120
130
  @router.command(Command('test', flags=flag))
121
- def test(args: InputFlags):
122
- if args.get_flag('info'):
131
+ def test(response: Response):
132
+ if response.valid_flags.get_flag('info'):
123
133
  print('info about test command')
124
134
 
125
135
  app = App(override_system_messages=True,
126
136
  print_func=print)
127
137
  app.include_router(router)
128
- app.run_polling()
138
+ orchestrator.start_polling(app)
129
139
 
130
140
  output = mock_stdout.getvalue()
131
141
 
@@ -136,16 +146,17 @@ class TestSystemHandlerNormalWork(unittest.TestCase):
136
146
  @patch("sys.stdout", new_callable=io.StringIO)
137
147
  def test_input_correct_command_with_default_flag3(self, mock_stdout: _io.StringIO, magick_mock: MagicMock):
138
148
  router = Router()
149
+ orchestrator = Orchestrator()
139
150
  flag = PredefinedFlags.HOST
140
151
 
141
152
  @router.command(Command('test', flags=flag))
142
- def test(args: InputFlags):
143
- print(f'connecting to host {args[0].get_value()}')
153
+ def test(response: Response):
154
+ print(f'connecting to host {response.valid_flags.get_flag('host').get_value()}')
144
155
 
145
156
  app = App(override_system_messages=True,
146
157
  print_func=print)
147
158
  app.include_router(router)
148
- app.run_polling()
159
+ orchestrator.start_polling(app)
149
160
 
150
161
  output = mock_stdout.getvalue()
151
162
 
@@ -156,16 +167,18 @@ class TestSystemHandlerNormalWork(unittest.TestCase):
156
167
  @patch("sys.stdout", new_callable=io.StringIO)
157
168
  def test_input_correct_command_with_two_flags(self, mock_stdout: _io.StringIO, magick_mock: MagicMock):
158
169
  router = Router()
170
+ orchestrator = Orchestrator()
159
171
  flags = Flags(PredefinedFlags.HOST, PredefinedFlags.PORT)
160
172
 
161
173
  @router.command(Command('test', flags=flags))
162
- def test(args: InputFlags):
163
- print(f'connecting to host {args[0].get_value()} and port {args[1].get_value()}')
174
+ def test(response: Response):
175
+ valid_flags = response.valid_flags
176
+ print(f'connecting to host {valid_flags.get_flag('host').get_value()} and port {valid_flags.get_flag('port').get_value()}')
164
177
 
165
178
  app = App(override_system_messages=True,
166
179
  print_func=print)
167
180
  app.include_router(router)
168
- app.run_polling()
181
+ orchestrator.start_polling(app)
169
182
 
170
183
  output = mock_stdout.getvalue()
171
184
 
@@ -176,19 +189,20 @@ class TestSystemHandlerNormalWork(unittest.TestCase):
176
189
  @patch("sys.stdout", new_callable=io.StringIO)
177
190
  def test_input_two_correct_command(self, mock_stdout: _io.StringIO, magick_mock: MagicMock):
178
191
  router = Router()
192
+ orchestrator = Orchestrator()
179
193
 
180
194
  @router.command(Command('test'))
181
- def test():
195
+ def test(response):
182
196
  print(f'test command')
183
197
 
184
198
  @router.command(Command('some'))
185
- def test2():
199
+ def test2(response):
186
200
  print(f'some command')
187
201
 
188
202
  app = App(override_system_messages=True,
189
203
  print_func=print)
190
204
  app.include_router(router)
191
- app.run_polling()
205
+ orchestrator.start_polling(app)
192
206
 
193
207
  output = mock_stdout.getvalue()
194
208
 
@@ -199,23 +213,24 @@ class TestSystemHandlerNormalWork(unittest.TestCase):
199
213
  @patch("sys.stdout", new_callable=io.StringIO)
200
214
  def test_input_three_correct_command(self, mock_stdout: _io.StringIO, magick_mock: MagicMock):
201
215
  router = Router()
216
+ orchestrator = Orchestrator()
202
217
 
203
218
  @router.command(Command('test'))
204
- def test():
219
+ def test(response):
205
220
  print(f'test command')
206
221
 
207
222
  @router.command(Command('some'))
208
- def test():
223
+ def test(response):
209
224
  print(f'some command')
210
225
 
211
226
  @router.command(Command('more'))
212
- def test():
227
+ def test(response):
213
228
  print(f'more command')
214
229
 
215
230
  app = App(override_system_messages=True,
216
231
  print_func=print)
217
232
  app.include_router(router)
218
- app.run_polling()
233
+ orchestrator.start_polling(app)
219
234
 
220
235
  output = mock_stdout.getvalue()
221
236
 
@@ -1,10 +1,12 @@
1
- from argenta.command.flag import Flag, InputFlag, Flags
1
+ from argenta.command.flag import Flag, InputFlag
2
+ from argenta.command.flags import Flags
2
3
  from argenta.command.models import InputCommand, Command
3
4
  from argenta.command.exceptions import (UnprocessedInputFlagException,
4
5
  RepeatedInputFlagsException,
5
6
  EmptyInputCommandException)
6
7
 
7
8
  import unittest
9
+ import re
8
10
 
9
11
 
10
12
  class TestInputCommand(unittest.TestCase):
@@ -23,25 +25,37 @@ class TestInputCommand(unittest.TestCase):
23
25
  with self.assertRaises(EmptyInputCommandException):
24
26
  InputCommand.parse('')
25
27
 
26
- def test_validate_correct_input_flag1(self):
28
+ def test_validate_valid_input_flag1(self):
27
29
  command = Command('some', flags=Flag('test'))
28
- self.assertEqual(command.validate_input_flag(InputFlag('test')), True)
30
+ self.assertEqual(command.validate_input_flag(InputFlag('test')), 'Valid')
29
31
 
30
- def test_validate_correct_input_flag2(self):
32
+ def test_validate_valid_input_flag2(self):
31
33
  command = Command('some', flags=Flags(Flag('test'), Flag('more')))
32
- self.assertEqual(command.validate_input_flag(InputFlag('more')), True)
34
+ self.assertEqual(command.validate_input_flag(InputFlag('more')), 'Valid')
33
35
 
34
- def test_validate_incorrect_input_flag1(self):
35
- command = Command('some', flags=Flags(Flag('test')))
36
- self.assertEqual(command.validate_input_flag(InputFlag('more')), False)
36
+ def test_validate_undefined_input_flag1(self):
37
+ command = Command('some', flags=Flag('test'))
38
+ self.assertEqual(command.validate_input_flag(InputFlag('more')), 'Undefined')
37
39
 
38
- def test_validate_incorrect_input_flag2(self):
40
+ def test_validate_undefined_input_flag2(self):
39
41
  command = Command('some', flags=Flags(Flag('test'), Flag('more')))
40
- self.assertEqual(command.validate_input_flag(InputFlag('case')), False)
42
+ self.assertEqual(command.validate_input_flag(InputFlag('case')), 'Undefined')
41
43
 
42
- def test_validate_incorrect_input_flag3(self):
44
+ def test_validate_undefined_input_flag3(self):
43
45
  command = Command('some')
44
- self.assertEqual(command.validate_input_flag(InputFlag('case')), False)
46
+ self.assertEqual(command.validate_input_flag(InputFlag('case')), 'Undefined')
47
+
48
+ def test_invalid_input_flag1(self):
49
+ command = Command('some', flags=Flag('test', possible_values=False))
50
+ self.assertEqual(command.validate_input_flag(InputFlag('test', value='example')), 'Invalid')
51
+
52
+ def test_invalid_input_flag2(self):
53
+ command = Command('some', flags=Flag('test', possible_values=['some', 'case']))
54
+ self.assertEqual(command.validate_input_flag(InputFlag('test', value='slay')), 'Invalid')
55
+
56
+ def test_invalid_input_flag3(self):
57
+ command = Command('some', flags=Flag('test', possible_values=re.compile(r'^ex\d{, 2}op$')))
58
+ self.assertEqual(command.validate_input_flag(InputFlag('test', value='example')), 'Invalid')
45
59
 
46
60
  def test_isinstance_parse_correct_raw_command(self):
47
61
  cmd = InputCommand.parse('ssh --host 192.168.0.3')
@@ -1,4 +1,5 @@
1
- from argenta.command.flag.models import Flag, InputFlag, InputFlags, Flags
1
+ from argenta.command.flag import Flag, InputFlag
2
+ from argenta.command.flags import InputFlags, Flags
2
3
 
3
4
  import unittest
4
5
  import re
@@ -1,4 +1,6 @@
1
- from argenta.command.flag import InputFlags, InputFlag, Flag, Flags
1
+ from argenta.command.flag import InputFlag, Flag
2
+ from argenta.command.flags import Flags, InputFlags, UndefinedInputFlags, InvalidValueInputFlags, ValidInputFlags
3
+ from argenta.response import Response
2
4
  from argenta.router import Router
3
5
  from argenta.command import Command
4
6
  from argenta.router.exceptions import (TriggerContainSpacesException,
@@ -24,113 +26,95 @@ class TestRouter(unittest.TestCase):
24
26
  with self.assertRaises(RepeatedFlagNameException):
25
27
  router._validate_command(Command(trigger='command', flags=Flags(Flag('test'), Flag('test'))))
26
28
 
27
- def test_validate_incorrect_input_flag1(self):
29
+ def test_structuring_input_flags1(self):
28
30
  router = Router()
29
- router.set_invalid_input_flag_handler(lambda flag: None)
30
- self.assertEqual(router._validate_input_flags(Command('cmd'), InputFlags(InputFlag('ssh'))), False)
31
+ cmd = Command('cmd')
32
+ input_flags = InputFlags(InputFlag('ssh'))
33
+ self.assertEqual(router._structuring_input_flags(cmd, input_flags).undefined_flags, UndefinedInputFlags(InputFlag('ssh')))
31
34
 
32
- def test_validate_incorrect_input_flag2(self):
35
+ def test_structuring_input_flags2(self):
33
36
  router = Router()
34
- router.set_invalid_input_flag_handler(lambda flag: None)
35
- self.assertEqual(router._validate_input_flags(Command('cmd'), InputFlags(InputFlag('ssh', value='some'))), False)
37
+ cmd = Command('cmd')
38
+ input_flags = InputFlags(InputFlag('ssh', value='some'))
39
+ self.assertEqual(router._structuring_input_flags(cmd, input_flags).undefined_flags, UndefinedInputFlags(InputFlag('ssh', value='some')))
36
40
 
37
- def test_validate_incorrect_input_flag3(self):
41
+ def test_structuring_input_flags3(self):
38
42
  router = Router()
39
- router.set_invalid_input_flag_handler(lambda flag: None)
40
- command = Command('cmd', flags=Flag('port'))
43
+ cmd = Command('cmd', flags=Flag('port'))
41
44
  input_flags = InputFlags(InputFlag('ssh', value='some2'))
42
- self.assertEqual(router._validate_input_flags(command, input_flags), False)
45
+ self.assertEqual(router._structuring_input_flags(cmd, input_flags).undefined_flags, UndefinedInputFlags(InputFlag('ssh', value='some2')))
43
46
 
44
- def test_validate_incorrect_input_flag4(self):
47
+ def test_structuring_input_flags4(self):
45
48
  router = Router()
46
- router.set_invalid_input_flag_handler(lambda flag: None)
47
49
  command = Command('cmd', flags=Flag('ssh', possible_values=False))
48
50
  input_flags = InputFlags(InputFlag('ssh', value='some3'))
49
- self.assertEqual(router._validate_input_flags(command, input_flags), False)
51
+ self.assertEqual(router._structuring_input_flags(command, input_flags).invalid_value_flags, InvalidValueInputFlags(InputFlag('ssh', value='some3')))
50
52
 
51
- def test_validate_incorrect_input_flag5(self):
53
+ def test_structuring_input_flags5(self):
52
54
  router = Router()
53
- router.set_invalid_input_flag_handler(lambda flag: None)
54
55
  command = Command('cmd', flags=Flag('ssh', possible_values=re.compile(r'some[1-5]$')))
55
56
  input_flags = InputFlags(InputFlag('ssh', value='some40'))
56
- self.assertEqual(router._validate_input_flags(command, input_flags), False)
57
+ self.assertEqual(router._structuring_input_flags(command, input_flags).invalid_value_flags, InvalidValueInputFlags(InputFlag('ssh', value='some40')))
57
58
 
58
- def test_validate_incorrect_input_flag6(self):
59
+ def test_structuring_input_flags6(self):
59
60
  router = Router()
60
- router.set_invalid_input_flag_handler(lambda flag: None)
61
61
  command = Command('cmd', flags=Flag('ssh', possible_values=['example']))
62
62
  input_flags = InputFlags(InputFlag('ssh', value='example2'))
63
- self.assertEqual(router._validate_input_flags(command, input_flags), False)
63
+ self.assertEqual(router._structuring_input_flags(command, input_flags).invalid_value_flags, InvalidValueInputFlags(InputFlag('ssh', value='example2')))
64
64
 
65
- def test_validate_incorrect_input_flag7(self):
66
- router = Router()
67
- router.set_invalid_input_flag_handler(lambda flag: None)
68
- command = Command('cmd', flags=Flag('ssh', possible_values=['example']))
69
- input_flags = InputFlags(InputFlag('ssh'))
70
- self.assertEqual(router._validate_input_flags(command, input_flags), False)
71
-
72
- def test_validate_correct_input_flag1(self):
65
+ def test_structuring_input_flags7(self):
73
66
  command = Command('cmd', flags=Flag('port'))
74
67
  input_flags = InputFlags(InputFlag('port', value='some2'))
75
- self.assertEqual(Router()._validate_input_flags(command, input_flags), True)
68
+ self.assertEqual(Router()._structuring_input_flags(command, input_flags).valid_flags, ValidInputFlags(InputFlag('port', value='some2')))
76
69
 
77
- def test_validate_correct_input_flag2(self):
70
+ def test_structuring_input_flags8(self):
78
71
  command = Command('cmd', flags=Flag('port', possible_values=['some2', 'some3']))
79
72
  input_flags = InputFlags(InputFlag('port', value='some2'))
80
- self.assertEqual(Router()._validate_input_flags(command, input_flags), True)
73
+ self.assertEqual(Router()._structuring_input_flags(command, input_flags).valid_flags, ValidInputFlags(InputFlag('port', value='some2')))
81
74
 
82
- def test_validate_correct_input_flag3(self):
75
+ def test_structuring_input_flags9(self):
83
76
  command = Command('cmd', flags=Flag('ssh', possible_values=re.compile(r'more[1-5]$')))
84
77
  input_flags = InputFlags(InputFlag('ssh', value='more5'))
85
- self.assertEqual(Router()._validate_input_flags(command, input_flags), True)
78
+ self.assertEqual(Router()._structuring_input_flags(command, input_flags).valid_flags, ValidInputFlags(InputFlag('ssh', value='more5')))
86
79
 
87
- def test_validate_correct_input_flag4(self):
80
+ def test_structuring_input_flags10(self):
88
81
  command = Command('cmd', flags=Flag('ssh', possible_values=False))
89
82
  input_flags = InputFlags(InputFlag('ssh'))
90
- self.assertEqual(Router()._validate_input_flags(command, input_flags), True)
83
+ self.assertEqual(Router()._structuring_input_flags(command, input_flags).valid_flags, ValidInputFlags(InputFlag('ssh')))
91
84
 
92
85
  def test_validate_incorrect_func_args1(self):
93
- command = Command('cmd', flags=Flag('port'))
94
86
  def handler():
95
87
  pass
96
88
  with self.assertRaises(RequiredArgumentNotPassedException):
97
- Router()._validate_func_args(command, handler)
89
+ Router()._validate_func_args(handler)
98
90
 
99
91
  def test_validate_incorrect_func_args2(self):
100
- command = Command('cmd', flags=Flag('port'))
101
92
  def handler(args, kwargs):
102
93
  pass
103
94
  with self.assertRaises(TooManyTransferredArgsException):
104
- Router()._validate_func_args(command, handler)
105
-
106
- def test_validate_incorrect_func_args3(self):
107
- command = Command('cmd')
108
- def handler(args):
109
- pass
110
- with self.assertRaises(TooManyTransferredArgsException):
111
- Router()._validate_func_args(command, handler)
95
+ Router()._validate_func_args(handler)
112
96
 
113
97
  def test_get_router_aliases(self):
114
98
  router = Router()
115
99
  @router.command(Command('some', aliases=['test', 'case']))
116
- def handler():
100
+ def handler(response):
117
101
  pass
118
102
  self.assertListEqual(router.get_aliases(), ['test', 'case'])
119
103
 
120
104
  def test_get_router_aliases2(self):
121
105
  router = Router()
122
106
  @router.command(Command('some', aliases=['test', 'case']))
123
- def handler():
107
+ def handler(response):
124
108
  pass
125
109
  @router.command(Command('ext', aliases=['more', 'foo']))
126
- def handler2():
110
+ def handler2(response):
127
111
  pass
128
112
  self.assertListEqual(router.get_aliases(), ['test', 'case', 'more', 'foo'])
129
113
 
130
114
  def test_get_router_aliases3(self):
131
115
  router = Router()
132
116
  @router.command(Command('some'))
133
- def handler():
117
+ def handler(response):
134
118
  pass
135
119
  self.assertListEqual(router.get_aliases(), [])
136
120
 
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes