argenta 1.0.0a0__tar.gz → 1.0.0a2__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 (64) hide show
  1. {argenta-1.0.0a0 → argenta-1.0.0a2}/PKG-INFO +1 -98
  2. {argenta-1.0.0a0 → argenta-1.0.0a2}/README.md +0 -97
  3. {argenta-1.0.0a0 → argenta-1.0.0a2}/mock/default_mock_app/main.py +0 -1
  4. argenta-1.0.0a2/mock/local_test.py +6 -0
  5. {argenta-1.0.0a0 → argenta-1.0.0a2}/mock/mock_app/handlers/routers.py +0 -3
  6. {argenta-1.0.0a0 → argenta-1.0.0a2}/pyproject.toml +33 -33
  7. {argenta-1.0.0a0 → argenta-1.0.0a2}/src/argenta/command/flag/defaults.py +5 -5
  8. {argenta-1.0.0a0 → argenta-1.0.0a2}/src/argenta/router/entity.py +10 -15
  9. {argenta-1.0.0a0 → argenta-1.0.0a2}/src/argenta/router/exceptions.py +1 -9
  10. {argenta-1.0.0a0 → argenta-1.0.0a2}/tests/system_tests/test_system_handling_normal_behavior.py +3 -3
  11. argenta-1.0.0a2/tests/unit_tests/test_app.py +73 -0
  12. argenta-1.0.0a2/tests/unit_tests/test_command.py +49 -0
  13. {argenta-1.0.0a0 → argenta-1.0.0a2}/tests/unit_tests/test_flag.py +39 -1
  14. argenta-1.0.0a2/tests/unit_tests/test_router.py +144 -0
  15. argenta-1.0.0a0/mock/local_test.py +0 -15
  16. argenta-1.0.0a0/tests/unit_tests/test_command.py +0 -24
  17. argenta-1.0.0a0/tests/unit_tests/test_flagsgroup.py +0 -26
  18. argenta-1.0.0a0/tests/unit_tests/test_router.py +0 -33
  19. {argenta-1.0.0a0 → argenta-1.0.0a2}/.github/workflows/ruff.yml +0 -0
  20. {argenta-1.0.0a0 → argenta-1.0.0a2}/.github/workflows/tests.yml +0 -0
  21. {argenta-1.0.0a0 → argenta-1.0.0a2}/.gitignore +0 -0
  22. {argenta-1.0.0a0 → argenta-1.0.0a2}/LICENSE +0 -0
  23. {argenta-1.0.0a0 → argenta-1.0.0a2}/imgs/mock_app_preview1.png +0 -0
  24. {argenta-1.0.0a0 → argenta-1.0.0a2}/imgs/mock_app_preview2.png +0 -0
  25. {argenta-1.0.0a0 → argenta-1.0.0a2}/imgs/mock_app_preview3.png +0 -0
  26. {argenta-1.0.0a0 → argenta-1.0.0a2}/mock/__init__.py +0 -0
  27. {argenta-1.0.0a0 → argenta-1.0.0a2}/mock/default_mock_app/__init__.py +0 -0
  28. {argenta-1.0.0a0 → argenta-1.0.0a2}/mock/mock_app/__init__.py +0 -0
  29. {argenta-1.0.0a0 → argenta-1.0.0a2}/mock/mock_app/handlers/__init__.py +0 -0
  30. {argenta-1.0.0a0 → argenta-1.0.0a2}/mock/mock_app/handlers/handlers_implementation/__init__.py +0 -0
  31. {argenta-1.0.0a0 → argenta-1.0.0a2}/mock/mock_app/handlers/handlers_implementation/help_command.py +0 -0
  32. {argenta-1.0.0a0 → argenta-1.0.0a2}/mock/mock_app/main.py +0 -0
  33. {argenta-1.0.0a0 → argenta-1.0.0a2}/src/__init__.py +0 -0
  34. {argenta-1.0.0a0 → argenta-1.0.0a2}/src/argenta/__init__.py +0 -0
  35. {argenta-1.0.0a0 → argenta-1.0.0a2}/src/argenta/app/__init__.py +0 -0
  36. {argenta-1.0.0a0 → argenta-1.0.0a2}/src/argenta/app/autocompleter/__init__.py +0 -0
  37. {argenta-1.0.0a0 → argenta-1.0.0a2}/src/argenta/app/autocompleter/entity.py +0 -0
  38. {argenta-1.0.0a0 → argenta-1.0.0a2}/src/argenta/app/defaults.py +0 -0
  39. {argenta-1.0.0a0 → argenta-1.0.0a2}/src/argenta/app/dividing_line/__init__.py +0 -0
  40. {argenta-1.0.0a0 → argenta-1.0.0a2}/src/argenta/app/dividing_line/models.py +0 -0
  41. {argenta-1.0.0a0 → argenta-1.0.0a2}/src/argenta/app/exceptions.py +0 -0
  42. {argenta-1.0.0a0 → argenta-1.0.0a2}/src/argenta/app/models.py +0 -0
  43. {argenta-1.0.0a0 → argenta-1.0.0a2}/src/argenta/app/registered_routers/__init__.py +0 -0
  44. {argenta-1.0.0a0 → argenta-1.0.0a2}/src/argenta/app/registered_routers/entity.py +0 -0
  45. {argenta-1.0.0a0 → argenta-1.0.0a2}/src/argenta/command/__init__.py +0 -0
  46. {argenta-1.0.0a0 → argenta-1.0.0a2}/src/argenta/command/exceptions.py +0 -0
  47. {argenta-1.0.0a0 → argenta-1.0.0a2}/src/argenta/command/flag/__init__.py +0 -0
  48. {argenta-1.0.0a0 → argenta-1.0.0a2}/src/argenta/command/flag/models.py +0 -0
  49. {argenta-1.0.0a0 → argenta-1.0.0a2}/src/argenta/command/models.py +0 -0
  50. {argenta-1.0.0a0 → argenta-1.0.0a2}/src/argenta/orchestrator/__init__.py +0 -0
  51. {argenta-1.0.0a0 → argenta-1.0.0a2}/src/argenta/orchestrator/argparser/__init__.py +0 -0
  52. {argenta-1.0.0a0 → argenta-1.0.0a2}/src/argenta/orchestrator/argparser/arguments/__init__.py +0 -0
  53. {argenta-1.0.0a0 → argenta-1.0.0a2}/src/argenta/orchestrator/argparser/arguments/models.py +0 -0
  54. {argenta-1.0.0a0 → argenta-1.0.0a2}/src/argenta/orchestrator/argparser/entity.py +0 -0
  55. {argenta-1.0.0a0 → argenta-1.0.0a2}/src/argenta/orchestrator/entity.py +0 -0
  56. {argenta-1.0.0a0 → argenta-1.0.0a2}/src/argenta/router/__init__.py +0 -0
  57. {argenta-1.0.0a0 → argenta-1.0.0a2}/src/argenta/router/command_handler/__init__.py +0 -0
  58. {argenta-1.0.0a0 → argenta-1.0.0a2}/src/argenta/router/command_handler/entity.py +0 -0
  59. {argenta-1.0.0a0 → argenta-1.0.0a2}/src/argenta/router/defaults.py +0 -0
  60. {argenta-1.0.0a0 → argenta-1.0.0a2}/tests/__init__.py +0 -0
  61. {argenta-1.0.0a0 → argenta-1.0.0a2}/tests/system_tests/__init__.py +0 -0
  62. {argenta-1.0.0a0 → argenta-1.0.0a2}/tests/system_tests/test_system_handling_non_standard_behavior.py +0 -0
  63. {argenta-1.0.0a0 → argenta-1.0.0a2}/tests/unit_tests/__init__.py +0 -0
  64. {argenta-1.0.0a0 → argenta-1.0.0a2}/tests/unit_tests/test_dividing_line.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: argenta
3
- Version: 1.0.0a0
3
+ Version: 1.0.0a2
4
4
  Summary: Python library for creating TUI
5
5
  Author-email: kolo <kolo.is.main@gmail.com>
6
6
  License: MIT
@@ -347,22 +347,6 @@ Public. Sets the handler for exit command when entering a command
347
347
 
348
348
  ---
349
349
 
350
- <a id="argenta.app.models.App.run_polling"></a>
351
-
352
- #### run\_polling
353
-
354
- ```python
355
- def run_polling() -> None
356
- ```
357
-
358
- Private. Starts the user input processing cycle
359
-
360
- **Returns**:
361
-
362
- `None`
363
-
364
- ---
365
-
366
350
  <a id="argenta.app.models.App.include_router"></a>
367
351
 
368
352
  #### include\_router
@@ -507,26 +491,6 @@ Public. The static dividing line
507
491
 
508
492
  ---
509
493
 
510
- <a id="argenta.app.dividing_line.models.StaticDividingLine.get_full_static_line"></a>
511
-
512
- #### get\_full\_static\_line
513
-
514
- ```python
515
- def get_full_static_line(is_override: bool) -> str
516
- ```
517
-
518
- Private. Returns the full line of the dividing line
519
-
520
- **Arguments**:
521
-
522
- - `is_override`: has the default text layout been redefined
523
-
524
- **Returns**:
525
-
526
- full line of dividing line as str
527
-
528
- ---
529
-
530
494
  <a id="argenta.app.dividing_line.models.DynamicDividingLine"></a>
531
495
 
532
496
  ## DynamicDividingLine Objects
@@ -555,27 +519,6 @@ Public. The dynamic dividing line
555
519
 
556
520
  ---
557
521
 
558
- <a id="argenta.app.dividing_line.models.DynamicDividingLine.get_full_dynamic_line"></a>
559
-
560
- #### get\_full\_dynamic\_line
561
-
562
- ```python
563
- def get_full_dynamic_line(length: int, is_override: bool) -> str
564
- ```
565
-
566
- Private. Returns the full line of the dividing line
567
-
568
- **Arguments**:
569
-
570
- - `length`: the length of the dividing line
571
- - `is_override`: has the default text layout been redefined
572
-
573
- **Returns**:
574
-
575
- full line of dividing line as str
576
-
577
- ---
578
-
579
522
  <a id="argenta.app.exceptions"></a>
580
523
 
581
524
  # `.app.exceptions`
@@ -1246,46 +1189,6 @@ Public. Registers handler for invalid input flag
1246
1189
 
1247
1190
  ---
1248
1191
 
1249
- <a id="argenta.router.entity.Router.input_command_handler"></a>
1250
-
1251
- #### input\_command\_handler
1252
-
1253
- ```python
1254
- def input_command_handler(input_command: InputCommand) -> None
1255
- ```
1256
-
1257
- Private. One handler for all input commands
1258
-
1259
- **Arguments**:
1260
-
1261
- - `input_command`: input command as InputCommand
1262
-
1263
- **Returns**:
1264
-
1265
- `None`
1266
-
1267
- ---
1268
-
1269
- <a id="argenta.router.entity.Router.set_command_register_ignore"></a>
1270
-
1271
- #### set\_command\_register\_ignore
1272
-
1273
- ```python
1274
- def set_command_register_ignore(_: bool) -> None
1275
- ```
1276
-
1277
- Private. Sets the router behavior on the input commands register
1278
-
1279
- **Arguments**:
1280
-
1281
- - `_`: is command register ignore
1282
-
1283
- **Returns**:
1284
-
1285
- `None`
1286
-
1287
- ---
1288
-
1289
1192
  <a id="argenta.router.entity.Router.get_triggers"></a>
1290
1193
 
1291
1194
  #### get\_triggers
@@ -334,22 +334,6 @@ Public. Sets the handler for exit command when entering a command
334
334
 
335
335
  ---
336
336
 
337
- <a id="argenta.app.models.App.run_polling"></a>
338
-
339
- #### run\_polling
340
-
341
- ```python
342
- def run_polling() -> None
343
- ```
344
-
345
- Private. Starts the user input processing cycle
346
-
347
- **Returns**:
348
-
349
- `None`
350
-
351
- ---
352
-
353
337
  <a id="argenta.app.models.App.include_router"></a>
354
338
 
355
339
  #### include\_router
@@ -494,26 +478,6 @@ Public. The static dividing line
494
478
 
495
479
  ---
496
480
 
497
- <a id="argenta.app.dividing_line.models.StaticDividingLine.get_full_static_line"></a>
498
-
499
- #### get\_full\_static\_line
500
-
501
- ```python
502
- def get_full_static_line(is_override: bool) -> str
503
- ```
504
-
505
- Private. Returns the full line of the dividing line
506
-
507
- **Arguments**:
508
-
509
- - `is_override`: has the default text layout been redefined
510
-
511
- **Returns**:
512
-
513
- full line of dividing line as str
514
-
515
- ---
516
-
517
481
  <a id="argenta.app.dividing_line.models.DynamicDividingLine"></a>
518
482
 
519
483
  ## DynamicDividingLine Objects
@@ -542,27 +506,6 @@ Public. The dynamic dividing line
542
506
 
543
507
  ---
544
508
 
545
- <a id="argenta.app.dividing_line.models.DynamicDividingLine.get_full_dynamic_line"></a>
546
-
547
- #### get\_full\_dynamic\_line
548
-
549
- ```python
550
- def get_full_dynamic_line(length: int, is_override: bool) -> str
551
- ```
552
-
553
- Private. Returns the full line of the dividing line
554
-
555
- **Arguments**:
556
-
557
- - `length`: the length of the dividing line
558
- - `is_override`: has the default text layout been redefined
559
-
560
- **Returns**:
561
-
562
- full line of dividing line as str
563
-
564
- ---
565
-
566
509
  <a id="argenta.app.exceptions"></a>
567
510
 
568
511
  # `.app.exceptions`
@@ -1233,46 +1176,6 @@ Public. Registers handler for invalid input flag
1233
1176
 
1234
1177
  ---
1235
1178
 
1236
- <a id="argenta.router.entity.Router.input_command_handler"></a>
1237
-
1238
- #### input\_command\_handler
1239
-
1240
- ```python
1241
- def input_command_handler(input_command: InputCommand) -> None
1242
- ```
1243
-
1244
- Private. One handler for all input commands
1245
-
1246
- **Arguments**:
1247
-
1248
- - `input_command`: input command as InputCommand
1249
-
1250
- **Returns**:
1251
-
1252
- `None`
1253
-
1254
- ---
1255
-
1256
- <a id="argenta.router.entity.Router.set_command_register_ignore"></a>
1257
-
1258
- #### set\_command\_register\_ignore
1259
-
1260
- ```python
1261
- def set_command_register_ignore(_: bool) -> None
1262
- ```
1263
-
1264
- Private. Sets the router behavior on the input commands register
1265
-
1266
- **Arguments**:
1267
-
1268
- - `_`: is command register ignore
1269
-
1270
- **Returns**:
1271
-
1272
- `None`
1273
-
1274
- ---
1275
-
1276
1179
  <a id="argenta.router.entity.Router.get_triggers"></a>
1277
1180
 
1278
1181
  #### get\_triggers
@@ -1,5 +1,4 @@
1
1
  from argenta.app import App
2
- from argenta.app.defaults import PredefinedMessages
3
2
  from argenta.orchestrator import Orchestrator
4
3
 
5
4
  app = App(repeat_command_groups=True)
@@ -0,0 +1,6 @@
1
+ from argenta.app import App
2
+ from argenta.command.models import InputCommand
3
+
4
+ app = App()
5
+ app._all_registered_triggers_in_lower = ['fr', 'Tre', 'Pre']
6
+ print(app._is_unknown_command(InputCommand('fr')))
@@ -1,10 +1,7 @@
1
1
  from rich.console import Console
2
2
 
3
3
  from argenta.command import Command
4
- from argenta.command.flag import Flags, InputFlags
5
- from argenta.command.flag.defaults import PredefinedFlags
6
4
  from argenta.router import Router
7
- from .handlers_implementation.help_command import help_command
8
5
 
9
6
 
10
7
  work_router: Router = Router(title='Work points:')
@@ -1,33 +1,33 @@
1
- [project]
2
- name = "argenta"
3
- version = "1.0.0-alpha"
4
- description = "Python library for creating TUI"
5
- authors = [{ name = "kolo", email = "kolo.is.main@gmail.com" }]
6
- requires-python = ">=3.11, <4.0"
7
- readme = "README.md"
8
- license = { text = "MIT" }
9
- dependencies = [
10
- "rich (>=14.0.0,<15.0.0)",
11
- "art (>=6.4,<7.0)",
12
- "pyreadline3 (>=3.5.4,<4.0.0)",
13
- ]
14
-
15
- [dependency-groups]
16
- dev = [
17
- "pydoc-markdown>=4.8.2,<5",
18
- ]
19
-
20
- [tool.ruff]
21
- exclude = [
22
- ".idea",
23
- "venv",
24
- ".git",
25
- "poetry.lock",
26
- ".__pycache__",
27
- "tests"
28
- ]
29
-
30
- [build-system]
31
- requires = ["hatchling"]
32
- build-backend = "hatchling.build"
33
-
1
+ [project]
2
+ name = "argenta"
3
+ version = "1.0.0-alpha2"
4
+ description = "Python library for creating TUI"
5
+ authors = [{ name = "kolo", email = "kolo.is.main@gmail.com" }]
6
+ requires-python = ">=3.11, <4.0"
7
+ readme = "README.md"
8
+ license = { text = "MIT" }
9
+ dependencies = [
10
+ "rich (>=14.0.0,<15.0.0)",
11
+ "art (>=6.4,<7.0)",
12
+ "pyreadline3 (>=3.5.4,<4.0.0)",
13
+ ]
14
+
15
+ [dependency-groups]
16
+ dev = [
17
+ "pydoc-markdown>=4.8.2,<5",
18
+ ]
19
+
20
+ [tool.ruff]
21
+ exclude = [
22
+ ".idea",
23
+ "venv",
24
+ ".git",
25
+ "poetry.lock",
26
+ ".__pycache__",
27
+ "tests"
28
+ ]
29
+
30
+ [build-system]
31
+ requires = ["hatchling"]
32
+ build-backend = "hatchling.build"
33
+
@@ -9,16 +9,16 @@ class PredefinedFlags:
9
9
  Public. A dataclass with predefined flags and most frequently used flags for quick use
10
10
  """
11
11
  HELP = Flag(name='help', possible_values=False)
12
- SHORT_HELP = Flag(name='h', prefix='-', possible_values=False)
12
+ SHORT_HELP = Flag(name='H', prefix='-', possible_values=False)
13
13
 
14
14
  INFO = Flag(name='info', possible_values=False)
15
- SHORT_INFO = Flag(name='i', prefix='-', possible_values=False)
15
+ SHORT_INFO = Flag(name='I', prefix='-', possible_values=False)
16
16
 
17
17
  ALL = Flag(name='all', possible_values=False)
18
- SHORT_ALL = Flag(name='a', prefix='-', possible_values=False)
18
+ SHORT_ALL = Flag(name='A', prefix='-', possible_values=False)
19
19
 
20
20
  HOST = Flag(name='host', possible_values=re.compile(r'^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$'))
21
- SHORT_HOST = Flag(name='h', prefix='-', possible_values=re.compile(r'^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$'))
21
+ SHORT_HOST = Flag(name='H', prefix='-', possible_values=re.compile(r'^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$'))
22
22
 
23
23
  PORT = Flag(name='port', possible_values=re.compile(r'^\d{1,5}$'))
24
- SHORT_PORT = Flag(name='p', prefix='-', possible_values=re.compile(r'^\d{1,5}$'))
24
+ SHORT_PORT = Flag(name='P', prefix='-', possible_values=re.compile(r'^\d{1,5}$'))
@@ -1,14 +1,13 @@
1
1
  from typing import Callable
2
2
  from inspect import getfullargspec
3
- from src.argenta.command import Command
4
- from src.argenta.command.models import InputCommand
5
- from src.argenta.router.command_handler.entity import CommandHandlers, CommandHandler
6
- from src.argenta.command.flag.models import Flag, Flags, InputFlags
7
- from src.argenta.router.exceptions import (RepeatedFlagNameException,
8
- TooManyTransferredArgsException,
9
- RequiredArgumentNotPassedException,
10
- IncorrectNumberOfHandlerArgsException,
11
- TriggerContainSpacesException)
3
+ from argenta.command import Command
4
+ from argenta.command.models import InputCommand
5
+ from argenta.router.command_handler.entity import CommandHandlers, CommandHandler
6
+ from argenta.command.flag.models import Flag, Flags, InputFlags
7
+ from argenta.router.exceptions import (RepeatedFlagNameException,
8
+ TooManyTransferredArgsException,
9
+ RequiredArgumentNotPassedException,
10
+ TriggerContainSpacesException)
12
11
 
13
12
 
14
13
  class Router:
@@ -45,17 +44,13 @@ class Router:
45
44
  return command_decorator
46
45
 
47
46
 
48
- def set_invalid_input_flag_handler(self, func) -> None:
47
+ def set_invalid_input_flag_handler(self, func: Callable[[Flag], None]) -> None:
49
48
  """
50
49
  Public. Registers handler for invalid input flag
51
50
  :param func: registered handler
52
51
  :return: None
53
52
  """
54
- processed_args = getfullargspec(func).args
55
- if len(processed_args) != 1:
56
- raise IncorrectNumberOfHandlerArgsException()
57
- else:
58
- self._not_valid_flag_handler = func
53
+ self._not_valid_flag_handler = func
59
54
 
60
55
 
61
56
  def finds_appropriate_handler(self, input_command: InputCommand) -> None:
@@ -3,7 +3,7 @@ class RepeatedFlagNameException(Exception):
3
3
  Private. Raised when a repeated flag name is registered
4
4
  """
5
5
  def __str__(self):
6
- return "Repeated registered_flag name in register command"
6
+ return "Repeated registered flag names in register command"
7
7
 
8
8
 
9
9
  class TooManyTransferredArgsException(Exception):
@@ -22,14 +22,6 @@ class RequiredArgumentNotPassedException(Exception):
22
22
  return "Required argument not passed"
23
23
 
24
24
 
25
- class IncorrectNumberOfHandlerArgsException(Exception):
26
- """
27
- Private. Raised when incorrect number of arguments are passed
28
- """
29
- def __str__(self):
30
- return "Handler has incorrect number of arguments"
31
-
32
-
33
25
  class TriggerContainSpacesException(Exception):
34
26
  """
35
27
  Private. Raised when there is a space in the trigger being registered
@@ -91,7 +91,7 @@ class TestSystemHandlerNormalWork(unittest.TestCase):
91
91
  self.assertIn('\nflag value for port flag : 22\n', output)
92
92
 
93
93
 
94
- @patch("builtins.input", side_effect=["test -h", "q"])
94
+ @patch("builtins.input", side_effect=["test -H", "q"])
95
95
  @patch("sys.stdout", new_callable=io.StringIO)
96
96
  def test_input_correct_command_with_default_flag(self, mock_stdout: _io.StringIO, magick_mock: MagicMock):
97
97
  router = Router()
@@ -99,7 +99,7 @@ class TestSystemHandlerNormalWork(unittest.TestCase):
99
99
 
100
100
  @router.command(Command('test', flags=flag))
101
101
  def test(args: InputFlags):
102
- print(f'help for {args.get_flag('h').get_name()} flag')
102
+ print(f'help for {args.get_flag('H').get_name()} flag')
103
103
 
104
104
  app = App(override_system_messages=True,
105
105
  print_func=print)
@@ -108,7 +108,7 @@ class TestSystemHandlerNormalWork(unittest.TestCase):
108
108
 
109
109
  output = mock_stdout.getvalue()
110
110
 
111
- self.assertIn('\nhelp for h flag\n', output)
111
+ self.assertIn('\nhelp for H flag\n', output)
112
112
 
113
113
 
114
114
  @patch("builtins.input", side_effect=["test --info", "q"])
@@ -0,0 +1,73 @@
1
+ from argenta.command.models import InputCommand, Command
2
+ from argenta.app import App
3
+
4
+ import unittest
5
+
6
+
7
+ class MyTestCase(unittest.TestCase):
8
+ def test_is_exit_command1(self):
9
+ app = App()
10
+ self.assertEqual(app._is_exit_command(InputCommand('q')), True)
11
+
12
+ def test_is_exit_command5(self):
13
+ app = App()
14
+ self.assertEqual(app._is_exit_command(InputCommand('Q')), True)
15
+
16
+ def test_is_exit_command2(self):
17
+ app = App(ignore_command_register=False)
18
+ self.assertEqual(app._is_exit_command(InputCommand('q')), False)
19
+
20
+ def test_is_exit_command3(self):
21
+ app = App(exit_command=Command('quit'))
22
+ self.assertEqual(app._is_exit_command(InputCommand('quit')), True)
23
+
24
+ def test_is_exit_command4(self):
25
+ app = App(exit_command=Command('quit'))
26
+ self.assertEqual(app._is_exit_command(InputCommand('qUIt')), True)
27
+
28
+ def test_is_exit_command6(self):
29
+ app = App(ignore_command_register=False,
30
+ exit_command=Command('quit'))
31
+ self.assertEqual(app._is_exit_command(InputCommand('qUIt')), False)
32
+
33
+ def test_is_unknown_command1(self):
34
+ app = App()
35
+ app.set_unknown_command_handler(lambda command: None)
36
+ app._all_registered_triggers_in_lower = ['fr', 'tr', 'de']
37
+ self.assertEqual(app._is_unknown_command(InputCommand('fr')), False)
38
+
39
+ def test_is_unknown_command2(self):
40
+ app = App()
41
+ app.set_unknown_command_handler(lambda command: None)
42
+ app._all_registered_triggers_in_lower = ['fr', 'tr', 'de']
43
+ self.assertEqual(app._is_unknown_command(InputCommand('cr')), True)
44
+
45
+ def test_is_unknown_command3(self):
46
+ app = App(ignore_command_register=False)
47
+ app.set_unknown_command_handler(lambda command: None)
48
+ app._all_registered_triggers_in_default_case = ['Pr', 'tW', 'deQW']
49
+ self.assertEqual(app._is_unknown_command(InputCommand('pr')), True)
50
+
51
+ def test_is_unknown_command4(self):
52
+ app = App(ignore_command_register=False)
53
+ app.set_unknown_command_handler(lambda command: None)
54
+ app._all_registered_triggers_in_default_case = ['Pr', 'tW', 'deQW']
55
+ self.assertEqual(app._is_unknown_command(InputCommand('tW')), False)
56
+
57
+
58
+
59
+
60
+
61
+
62
+
63
+
64
+
65
+
66
+
67
+
68
+
69
+
70
+
71
+
72
+
73
+
@@ -0,0 +1,49 @@
1
+ from argenta.command.flag import Flag, InputFlag, Flags
2
+ from argenta.command.models import InputCommand, Command
3
+ from argenta.command.exceptions import (UnprocessedInputFlagException,
4
+ RepeatedInputFlagsException,
5
+ EmptyInputCommandException)
6
+
7
+ import unittest
8
+
9
+
10
+ class TestInputCommand(unittest.TestCase):
11
+ def test_parse_correct_raw_command(self):
12
+ self.assertEqual(InputCommand.parse('ssh --host 192.168.0.3').get_trigger(), 'ssh')
13
+
14
+ def test_parse_raw_command_without_flag_name_with_value(self):
15
+ with self.assertRaises(UnprocessedInputFlagException):
16
+ InputCommand.parse('ssh 192.168.0.3')
17
+
18
+ def test_parse_raw_command_with_repeated_flag_name(self):
19
+ with self.assertRaises(RepeatedInputFlagsException):
20
+ InputCommand.parse('ssh --host 192.168.0.3 --host 172.198.0.43')
21
+
22
+ def test_parse_empty_raw_command(self):
23
+ with self.assertRaises(EmptyInputCommandException):
24
+ InputCommand.parse('')
25
+
26
+ def test_validate_correct_input_flag1(self):
27
+ command = Command('some', flags=Flag('test'))
28
+ self.assertEqual(command.validate_input_flag(InputFlag('test')), True)
29
+
30
+ def test_validate_correct_input_flag2(self):
31
+ command = Command('some', flags=Flags(Flag('test'), Flag('more')))
32
+ self.assertEqual(command.validate_input_flag(InputFlag('more')), True)
33
+
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)
37
+
38
+ def test_validate_incorrect_input_flag2(self):
39
+ command = Command('some', flags=Flags(Flag('test'), Flag('more')))
40
+ self.assertEqual(command.validate_input_flag(InputFlag('case')), False)
41
+
42
+ def test_validate_incorrect_input_flag3(self):
43
+ command = Command('some')
44
+ self.assertEqual(command.validate_input_flag(InputFlag('case')), False)
45
+
46
+ def test_isinstance_parse_correct_raw_command(self):
47
+ cmd = InputCommand.parse('ssh --host 192.168.0.3')
48
+ self.assertIsInstance(cmd, InputCommand)
49
+
@@ -1,4 +1,4 @@
1
- from argenta.command.flag.models import Flag, InputFlag
1
+ from argenta.command.flag.models import Flag, InputFlag, InputFlags, Flags
2
2
 
3
3
  import unittest
4
4
  import re
@@ -68,6 +68,44 @@ class TestFlag(unittest.TestCase):
68
68
  flag = Flag(name='test', possible_values=True)
69
69
  self.assertEqual(flag.validate_input_flag_value('random value'), True)
70
70
 
71
+ def test_get_input_flag1(self):
72
+ flag = InputFlag(name='test')
73
+ input_flags = InputFlags(flag)
74
+ self.assertEqual(input_flags.get_flag('test'), flag)
75
+
76
+ def test_get_input_flag2(self):
77
+ flag = InputFlag(name='test')
78
+ flag2 = InputFlag(name='some')
79
+ input_flags = InputFlags(flag, flag2)
80
+ self.assertEqual(input_flags.get_flag('some'), flag2)
81
+
82
+ def test_get_undefined_input_flag(self):
83
+ flag = InputFlag(name='test')
84
+ flag2 = InputFlag(name='some')
85
+ input_flags = InputFlags(flag, flag2)
86
+ self.assertEqual(input_flags.get_flag('case'), None)
87
+
88
+ def test_get_flags(self):
89
+ flags = Flags()
90
+ list_of_flags = [
91
+ Flag('test1'),
92
+ Flag('test2'),
93
+ Flag('test3'),
94
+ ]
95
+ flags.add_flags(list_of_flags)
96
+ self.assertEqual(flags.get_flags(),
97
+ list_of_flags)
98
+
99
+ def test_add_flag(self):
100
+ flags = Flags()
101
+ flags.add_flag(Flag('test'))
102
+ self.assertEqual(len(flags.get_flags()), 1)
103
+
104
+ def test_add_flags(self):
105
+ flags = Flags()
106
+ flags.add_flags([Flag('test'), Flag('test2')])
107
+ self.assertEqual(len(flags.get_flags()), 2)
108
+
71
109
 
72
110
 
73
111
 
@@ -0,0 +1,144 @@
1
+ from argenta.command.flag import InputFlags, InputFlag, Flag, Flags
2
+ from argenta.router import Router
3
+ from argenta.command import Command
4
+ from argenta.router.exceptions import (TriggerContainSpacesException,
5
+ RepeatedFlagNameException,
6
+ TooManyTransferredArgsException,
7
+ RequiredArgumentNotPassedException)
8
+
9
+ import unittest
10
+ import re
11
+
12
+
13
+ class TestRouter(unittest.TestCase):
14
+ def test_get_router_title(self):
15
+ self.assertEqual(Router(title='test title').get_title(), 'test title')
16
+
17
+ def test_register_command_with_spaces_in_trigger(self):
18
+ router = Router()
19
+ with self.assertRaises(TriggerContainSpacesException):
20
+ router._validate_command(Command(trigger='command with spaces'))
21
+
22
+ def test_register_command_with_repeated_flags(self):
23
+ router = Router()
24
+ with self.assertRaises(RepeatedFlagNameException):
25
+ router._validate_command(Command(trigger='command', flags=Flags(Flag('test'), Flag('test'))))
26
+
27
+ def test_validate_incorrect_input_flag1(self):
28
+ 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
+
32
+ def test_validate_incorrect_input_flag2(self):
33
+ 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)
36
+
37
+ def test_validate_incorrect_input_flag3(self):
38
+ router = Router()
39
+ router.set_invalid_input_flag_handler(lambda flag: None)
40
+ command = Command('cmd', flags=Flag('port'))
41
+ input_flags = InputFlags(InputFlag('ssh', value='some2'))
42
+ self.assertEqual(router._validate_input_flags(command, input_flags), False)
43
+
44
+ def test_validate_incorrect_input_flag4(self):
45
+ router = Router()
46
+ router.set_invalid_input_flag_handler(lambda flag: None)
47
+ command = Command('cmd', flags=Flag('ssh', possible_values=False))
48
+ input_flags = InputFlags(InputFlag('ssh', value='some3'))
49
+ self.assertEqual(router._validate_input_flags(command, input_flags), False)
50
+
51
+ def test_validate_incorrect_input_flag5(self):
52
+ router = Router()
53
+ router.set_invalid_input_flag_handler(lambda flag: None)
54
+ command = Command('cmd', flags=Flag('ssh', possible_values=re.compile(r'some[1-5]$')))
55
+ input_flags = InputFlags(InputFlag('ssh', value='some40'))
56
+ self.assertEqual(router._validate_input_flags(command, input_flags), False)
57
+
58
+ def test_validate_incorrect_input_flag6(self):
59
+ router = Router()
60
+ router.set_invalid_input_flag_handler(lambda flag: None)
61
+ command = Command('cmd', flags=Flag('ssh', possible_values=['example']))
62
+ input_flags = InputFlags(InputFlag('ssh', value='example2'))
63
+ self.assertEqual(router._validate_input_flags(command, input_flags), False)
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):
73
+ command = Command('cmd', flags=Flag('port'))
74
+ input_flags = InputFlags(InputFlag('port', value='some2'))
75
+ self.assertEqual(Router()._validate_input_flags(command, input_flags), True)
76
+
77
+ def test_validate_correct_input_flag2(self):
78
+ command = Command('cmd', flags=Flag('port', possible_values=['some2', 'some3']))
79
+ input_flags = InputFlags(InputFlag('port', value='some2'))
80
+ self.assertEqual(Router()._validate_input_flags(command, input_flags), True)
81
+
82
+ def test_validate_correct_input_flag3(self):
83
+ command = Command('cmd', flags=Flag('ssh', possible_values=re.compile(r'more[1-5]$')))
84
+ input_flags = InputFlags(InputFlag('ssh', value='more5'))
85
+ self.assertEqual(Router()._validate_input_flags(command, input_flags), True)
86
+
87
+ def test_validate_correct_input_flag4(self):
88
+ command = Command('cmd', flags=Flag('ssh', possible_values=False))
89
+ input_flags = InputFlags(InputFlag('ssh'))
90
+ self.assertEqual(Router()._validate_input_flags(command, input_flags), True)
91
+
92
+ def test_validate_incorrect_func_args1(self):
93
+ command = Command('cmd', flags=Flag('port'))
94
+ def handler():
95
+ pass
96
+ with self.assertRaises(RequiredArgumentNotPassedException):
97
+ Router()._validate_func_args(command, handler)
98
+
99
+ def test_validate_incorrect_func_args2(self):
100
+ command = Command('cmd', flags=Flag('port'))
101
+ def handler(args, kwargs):
102
+ pass
103
+ 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)
112
+
113
+ def test_get_router_aliases(self):
114
+ router = Router()
115
+ @router.command(Command('some', aliases=['test', 'case']))
116
+ def handler():
117
+ pass
118
+ self.assertListEqual(router.get_aliases(), ['test', 'case'])
119
+
120
+ def test_get_router_aliases2(self):
121
+ router = Router()
122
+ @router.command(Command('some', aliases=['test', 'case']))
123
+ def handler():
124
+ pass
125
+ @router.command(Command('ext', aliases=['more', 'foo']))
126
+ def handler2():
127
+ pass
128
+ self.assertListEqual(router.get_aliases(), ['test', 'case', 'more', 'foo'])
129
+
130
+ def test_get_router_aliases3(self):
131
+ router = Router()
132
+ @router.command(Command('some'))
133
+ def handler():
134
+ pass
135
+ self.assertListEqual(router.get_aliases(), [])
136
+
137
+
138
+
139
+
140
+
141
+
142
+
143
+
144
+
@@ -1,15 +0,0 @@
1
- import argparse
2
-
3
-
4
- parser = argparse.ArgumentParser(prog='ProgramName',
5
- description='What the program does',
6
- epilog='Text at the bottom of help')
7
-
8
- parser.add_argument('filename') # positional argument
9
- parser.add_argument('-c', '--count') # option that takes a value
10
- parser.add_argument('-v',
11
- action='store_const')
12
-
13
- args = parser.parse_args()
14
- print(args)
15
- print(args.filename, args.count, args.verbose)
@@ -1,24 +0,0 @@
1
- from argenta.command.models import InputCommand
2
- from argenta.command.exceptions import (UnprocessedInputFlagException,
3
- RepeatedInputFlagsException,
4
- EmptyInputCommandException)
5
-
6
- import unittest
7
-
8
-
9
- class TestInputCommand(unittest.TestCase):
10
- def test_parse_correct_raw_command(self):
11
- self.assertEqual(InputCommand.parse('ssh --host 192.168.0.3').get_trigger(), 'ssh')
12
-
13
- def test_parse_raw_command_without_flag_name_with_value(self):
14
- with self.assertRaises(UnprocessedInputFlagException):
15
- InputCommand.parse('ssh 192.168.0.3')
16
-
17
- def test_parse_raw_command_with_repeated_flag_name(self):
18
- with self.assertRaises(RepeatedInputFlagsException):
19
- InputCommand.parse('ssh --host 192.168.0.3 --host 172.198.0.43')
20
-
21
- def test_parse_empty_raw_command(self):
22
- with self.assertRaises(EmptyInputCommandException):
23
- InputCommand.parse('')
24
-
@@ -1,26 +0,0 @@
1
- from argenta.command.flag.models import Flag, Flags
2
-
3
- import unittest
4
-
5
-
6
- class TestFlags(unittest.TestCase):
7
- def test_get_flags(self):
8
- flags = Flags()
9
- list_of_flags = [
10
- Flag('test1'),
11
- Flag('test2'),
12
- Flag('test3'),
13
- ]
14
- flags.add_flags(list_of_flags)
15
- self.assertEqual(flags.get_flags(),
16
- list_of_flags)
17
-
18
- def test_add_flag(self):
19
- flags = Flags()
20
- flags.add_flag(Flag('test'))
21
- self.assertEqual(len(flags.get_flags()), 1)
22
-
23
- def test_add_flags(self):
24
- flags = Flags()
25
- flags.add_flags([Flag('test'), Flag('test2')])
26
- self.assertEqual(len(flags.get_flags()), 2)
@@ -1,33 +0,0 @@
1
- from src.argenta.router import Router
2
- from src.argenta.command import Command
3
- from src.argenta.router import TriggerContainSpacesException
4
-
5
- import unittest
6
-
7
-
8
- class TestRouter(unittest.TestCase):
9
- def test_get_router_title(self):
10
- self.assertEqual(Router(title='test title').get_title(), 'test title')
11
-
12
- def test_register_command_with_spaces_in_trigger(self):
13
- router = Router()
14
- with self.assertRaises(TriggerContainSpacesException):
15
- @router.command(Command(trigger='command with spaces'))
16
- def test():
17
- return 'correct result'
18
-
19
-
20
-
21
-
22
-
23
-
24
-
25
-
26
-
27
-
28
-
29
-
30
-
31
-
32
-
33
-
File without changes
File without changes
File without changes
File without changes
File without changes