From 61ef6a6466d50753541360756fbbd1d1b41d3b39 Mon Sep 17 00:00:00 2001 From: kolo Date: Tue, 6 May 2025 21:53:53 +0300 Subject: [PATCH] all tests passed --- src/argenta/command/flags/models.py | 3 + src/argenta/router/entity.py | 12 +-- ...t_system_handling_non_standard_behavior.py | 74 ++++++++++------- .../test_system_handling_normal_behavior.py | 81 +++++++++++-------- tests/unit_tests/test_command.py | 38 ++++++--- tests/unit_tests/test_router.py | 56 ++++++------- 6 files changed, 154 insertions(+), 110 deletions(-) diff --git a/src/argenta/command/flags/models.py b/src/argenta/command/flags/models.py index 492c943..7e39660 100644 --- a/src/argenta/command/flags/models.py +++ b/src/argenta/command/flags/models.py @@ -58,6 +58,9 @@ class BaseFlags(Generic[FlagType]): def __getitem__(self, item): return self._flags[item] + def __bool__(self): + return bool(self._flags) + def __eq__(self, other): if len(self.get_flags()) != len(other.get_flags()): return False diff --git a/src/argenta/router/entity.py b/src/argenta/router/entity.py index 2e0bced..2a49ac8 100644 --- a/src/argenta/router/entity.py +++ b/src/argenta/router/entity.py @@ -158,11 +158,13 @@ class Router: elif len(transferred_args) == 0: raise RequiredArgumentNotPassedException() - arg_annotation: Type = get_annotations(func)[transferred_args[0]] - if not arg_annotation is Response: - Console().print(f'\n\nFile "{getsourcefile(func)}", line {getsourcelines(func)[1]+1}\n' - f'[b red]WARNING:[/b red] [i]The typehint of argument([green]{transferred_args[0]}[/green]) passed to the handler is [/i][blue]{Response}[/blue],' - f' [i]but[/i] [bold blue]{arg_annotation}[/bold blue] [i]is specified[/i]', highlight=False) + func_annotations: dict[str, Type] = get_annotations(func) + if func_annotations: + arg_annotation: Type = func_annotations[transferred_args[0]] + if not arg_annotation is Response: + Console().print(f'\n\nFile "{getsourcefile(func)}", line {getsourcelines(func)[1]+1}\n' + f'[b red]WARNING:[/b red] [i]The typehint of argument([green]{transferred_args[0]}[/green]) passed to the handler is [/i][blue]{Response}[/blue],' + f' [i]but[/i] [bold blue]{arg_annotation}[/bold blue] [i]is specified[/i]', highlight=False) diff --git a/tests/system_tests/test_system_handling_non_standard_behavior.py b/tests/system_tests/test_system_handling_non_standard_behavior.py index 4247b58..ae7f32f 100644 --- a/tests/system_tests/test_system_handling_non_standard_behavior.py +++ b/tests/system_tests/test_system_handling_non_standard_behavior.py @@ -1,32 +1,35 @@ import _io from unittest.mock import patch, MagicMock -import unittest +from unittest import TestCase import io import re from argenta.app import App from argenta.command import Command from argenta.router import Router -from argenta.command.flag.models import Flags, InputFlags +from argenta.command.flags.models import Flags from argenta.command.flag.defaults import PredefinedFlags +from argenta.orchestrator import Orchestrator +from argenta.response import Response -class TestSystemHandlerNormalWork(unittest.TestCase): +class TestSystemHandlerNormalWork(TestCase): @patch("builtins.input", side_effect=["help", "q"]) @patch("sys.stdout", new_callable=io.StringIO) def test_input_incorrect_command(self, mock_stdout: _io.StringIO, magick_mock: MagicMock): router = Router() + orchestrator = Orchestrator() @router.command(Command('test')) - def test(): + def test(response: Response): print('test command') app = App(override_system_messages=True, print_func=print) app.include_router(router) app.set_unknown_command_handler(lambda command: print(f'Unknown command: {command.get_trigger()}')) - app.run_polling() + orchestrator.start_polling(app) output = mock_stdout.getvalue() @@ -37,9 +40,10 @@ class TestSystemHandlerNormalWork(unittest.TestCase): @patch("sys.stdout", new_callable=io.StringIO) def test_input_incorrect_command2(self, mock_stdout: _io.StringIO, magick_mock: MagicMock): router = Router() + orchestrator = Orchestrator() @router.command(Command('test')) - def test(): + def test(response: Response): print('test command') app = App(ignore_command_register=False, @@ -47,7 +51,7 @@ class TestSystemHandlerNormalWork(unittest.TestCase): print_func=print) app.include_router(router) app.set_unknown_command_handler(lambda command: print(f'Unknown command: {command.get_trigger()}')) - app.run_polling() + orchestrator.start_polling(app) output = mock_stdout.getvalue() @@ -58,74 +62,80 @@ class TestSystemHandlerNormalWork(unittest.TestCase): @patch("sys.stdout", new_callable=io.StringIO) def test_input_correct_command_with_unregistered_flag(self, mock_stdout: _io.StringIO, magick_mock: MagicMock): router = Router() + orchestrator = Orchestrator() @router.command(Command('test')) - def test(): - print(f'test command') + def test(response: Response): + print(f'test command with undefined flag: {response.undefined_flags.get_flag('help').get_string_entity()}') app = App(override_system_messages=True, print_func=print) app.include_router(router) - app.run_polling() + orchestrator.start_polling(app) output = mock_stdout.getvalue() - self.assertIn('\nUndefined or incorrect input flag: --help\n', output) + self.assertIn('\ntest command with undefined flag: --help\n', output) @patch("builtins.input", side_effect=["test --port 22", "q"]) @patch("sys.stdout", new_callable=io.StringIO) def test_input_correct_command_with_unregistered_flag2(self, mock_stdout: _io.StringIO, magick_mock: MagicMock): router = Router() + orchestrator = Orchestrator() @router.command(Command('test')) - def test(): - print('test command') + def test(response: Response): + flag = response.undefined_flags.get_flag("port") + print(f'test command with undefined flag with value: {flag.get_string_entity()} {flag.get_value()}') app = App(override_system_messages=True, print_func=print) app.include_router(router) - app.run_polling() + orchestrator.start_polling(app) output = mock_stdout.getvalue() - self.assertIn('\nUndefined or incorrect input flag: --port 22\n', output) + self.assertIn('\ntest command with undefined flag with value: --port 22\n', output) @patch("builtins.input", side_effect=["test --host 192.168.32.1 --port 132", "q"]) @patch("sys.stdout", new_callable=io.StringIO) def test_input_correct_command_with_one_correct_flag_an_one_incorrect_flag(self, mock_stdout: _io.StringIO, magick_mock: MagicMock): router = Router() + orchestrator = Orchestrator() flags = Flags(PredefinedFlags.HOST) @router.command(Command('test', flags=flags)) - def test(args: InputFlags): - print(f'connecting to host {args.get_flag('host').get_value()}') + def test(response: Response): + flag = response.undefined_flags.get_flag("port") + print(f'connecting to host with flag: {flag.get_string_entity()} {flag.get_value()}') app = App(override_system_messages=True, print_func=print) app.include_router(router) - app.run_polling() + orchestrator.start_polling(app) output = mock_stdout.getvalue() - self.assertIn('\nUndefined or incorrect input flag: --port 132\n', output) + self.assertIn('\nconnecting to host with flag: --port 132\n', output) @patch("builtins.input", side_effect=["test", "some", "q"]) @patch("sys.stdout", new_callable=io.StringIO) def test_input_one_correct_command_and_one_incorrect_command(self, mock_stdout: _io.StringIO, magick_mock: MagicMock): router = Router() + orchestrator = Orchestrator() @router.command(Command('test')) - def test(): + def test(response: Response): print(f'test command') app = App(override_system_messages=True, print_func=print) app.include_router(router) app.set_unknown_command_handler(lambda command: print(f'Unknown command: {command.get_trigger()}')) - app.run_polling() + orchestrator.start_polling(app) output = mock_stdout.getvalue() @@ -136,20 +146,21 @@ class TestSystemHandlerNormalWork(unittest.TestCase): @patch("sys.stdout", new_callable=io.StringIO) def test_input_two_correct_commands_and_one_incorrect_command(self, mock_stdout: _io.StringIO, magick_mock: MagicMock): router = Router() + orchestrator = Orchestrator() @router.command(Command('test')) - def test(): + def test(response: Response): print(f'test command') @router.command(Command('more')) - def test(): + def test(response: Response): print(f'more command') app = App(override_system_messages=True, print_func=print) app.include_router(router) app.set_unknown_command_handler(lambda command: print(f'Unknown command: {command.get_trigger()}')) - app.run_polling() + orchestrator.start_polling(app) output = mock_stdout.getvalue() @@ -160,16 +171,17 @@ class TestSystemHandlerNormalWork(unittest.TestCase): @patch("sys.stdout", new_callable=io.StringIO) def test_input_correct_command_with_incorrect_flag(self, mock_stdout: _io.StringIO, magick_mock: MagicMock): router = Router() + orchestrator = Orchestrator() @router.command(Command('test')) - def test(): + def test(response: Response): print(f'test command') app = App(override_system_messages=True, print_func=print) app.include_router(router) app.set_invalid_input_flags_handler(lambda command: print(f'Incorrect flag syntax: "{command}"')) - app.run_polling() + orchestrator.start_polling(app) output = mock_stdout.getvalue() @@ -180,16 +192,17 @@ class TestSystemHandlerNormalWork(unittest.TestCase): @patch("sys.stdout", new_callable=io.StringIO) def test_input_empty_command(self, mock_stdout: _io.StringIO, magick_mock: MagicMock): router = Router() + orchestrator = Orchestrator() @router.command(Command('test')) - def test(): + def test(response: Response): print(f'test command') app = App(override_system_messages=True, print_func=print) app.include_router(router) app.set_empty_command_handler(lambda: print('Empty input command')) - app.run_polling() + orchestrator.start_polling(app) output = mock_stdout.getvalue() @@ -200,16 +213,17 @@ class TestSystemHandlerNormalWork(unittest.TestCase): @patch("sys.stdout", new_callable=io.StringIO) def test_input_correct_command_with_repeated_flags(self, mock_stdout: _io.StringIO, magick_mock: MagicMock): router = Router() + orchestrator = Orchestrator() @router.command(Command('test', flags=PredefinedFlags.PORT)) - def test(args: InputFlags): + def test(response: Response): print('test command') app = App(override_system_messages=True, print_func=print) app.include_router(router) app.set_repeated_input_flags_handler(lambda command: print(f'Repeated input flags: "{command}"')) - app.run_polling() + orchestrator.start_polling(app) output = mock_stdout.getvalue() diff --git a/tests/system_tests/test_system_handling_normal_behavior.py b/tests/system_tests/test_system_handling_normal_behavior.py index 01aa9d7..64dafd5 100644 --- a/tests/system_tests/test_system_handling_normal_behavior.py +++ b/tests/system_tests/test_system_handling_normal_behavior.py @@ -1,31 +1,35 @@ import _io from unittest.mock import patch, MagicMock -import unittest +from unittest import TestCase import io import re from argenta.app import App -from argenta.command.models import Command +from argenta.command import Command +from argenta.response import Response from argenta.router import Router -from argenta.command.flag.models import Flag, Flags, InputFlags +from argenta.orchestrator import Orchestrator +from argenta.command.flag import Flag +from argenta.command.flags import Flags from argenta.command.flag.defaults import PredefinedFlags -class TestSystemHandlerNormalWork(unittest.TestCase): +class TestSystemHandlerNormalWork(TestCase): @patch("builtins.input", side_effect=["test", "q"]) @patch("sys.stdout", new_callable=io.StringIO) def test_input_correct_command(self, mock_stdout: _io.StringIO, magick_mock: MagicMock): router = Router() + orchestrator = Orchestrator() @router.command(Command('test')) - def test(): + def test(response): print('test command') app = App(override_system_messages=True, print_func=print) app.include_router(router) - app.run_polling() + orchestrator.start_polling(app) output = mock_stdout.getvalue() @@ -36,16 +40,17 @@ class TestSystemHandlerNormalWork(unittest.TestCase): @patch("sys.stdout", new_callable=io.StringIO) def test_input_correct_command2(self, mock_stdout: _io.StringIO, magick_mock: MagicMock): router = Router() + orchestrator = Orchestrator() @router.command(Command('test')) - def test(): + def test(response): print('test command') app = App(ignore_command_register=True, override_system_messages=True, print_func=print) app.include_router(router) - app.run_polling() + orchestrator.start_polling(app) output = mock_stdout.getvalue() @@ -56,16 +61,17 @@ class TestSystemHandlerNormalWork(unittest.TestCase): @patch("sys.stdout", new_callable=io.StringIO) def test_input_correct_command_with_custom_flag(self, mock_stdout: _io.StringIO, magick_mock: MagicMock): router = Router() + orchestrator = Orchestrator() flag = Flag('help', '--', False) @router.command(Command('test', flags=flag)) - def test(args: InputFlags): - print(f'\nhelp for {args.get_flag('help').get_name()} flag\n') + def test(response: Response): + print(f'\nhelp for {response.valid_flags.get_flag('help').get_name()} flag\n') app = App(override_system_messages=True, print_func=print) app.include_router(router) - app.run_polling() + orchestrator.start_polling(app) output = mock_stdout.getvalue() @@ -75,16 +81,18 @@ class TestSystemHandlerNormalWork(unittest.TestCase): @patch("sys.stdout", new_callable=io.StringIO) def test_input_correct_command_with_custom_flag2(self, mock_stdout: _io.StringIO, magick_mock: MagicMock): router = Router() + orchestrator = Orchestrator() flag = Flag('port', '--', re.compile(r'^\d{1,5}$')) @router.command(Command('test', flags=flag)) - def test(args: InputFlags): - print(f'flag value for {args.get_flag('port').get_name()} flag : {args.get_flag('port').get_value()}') + def test(response: Response): + input_flag = response.valid_flags.get_flag('port') + print(f'flag value for {input_flag.get_name()} flag : {input_flag.get_value()}') app = App(override_system_messages=True, print_func=print) app.include_router(router) - app.run_polling() + orchestrator.start_polling(app) output = mock_stdout.getvalue() @@ -95,16 +103,17 @@ class TestSystemHandlerNormalWork(unittest.TestCase): @patch("sys.stdout", new_callable=io.StringIO) def test_input_correct_command_with_default_flag(self, mock_stdout: _io.StringIO, magick_mock: MagicMock): router = Router() + orchestrator = Orchestrator() flag = PredefinedFlags.SHORT_HELP @router.command(Command('test', flags=flag)) - def test(args: InputFlags): - print(f'help for {args.get_flag('H').get_name()} flag') + def test(response: Response): + print(f'help for {response.valid_flags.get_flag('H').get_name()} flag') app = App(override_system_messages=True, print_func=print) app.include_router(router) - app.run_polling() + orchestrator.start_polling(app) output = mock_stdout.getvalue() @@ -115,17 +124,18 @@ class TestSystemHandlerNormalWork(unittest.TestCase): @patch("sys.stdout", new_callable=io.StringIO) def test_input_correct_command_with_default_flag2(self, mock_stdout: _io.StringIO, magick_mock: MagicMock): router = Router() + orchestrator = Orchestrator() flag = PredefinedFlags.INFO @router.command(Command('test', flags=flag)) - def test(args: InputFlags): - if args.get_flag('info'): + def test(response: Response): + if response.valid_flags.get_flag('info'): print('info about test command') app = App(override_system_messages=True, print_func=print) app.include_router(router) - app.run_polling() + orchestrator.start_polling(app) output = mock_stdout.getvalue() @@ -136,16 +146,17 @@ class TestSystemHandlerNormalWork(unittest.TestCase): @patch("sys.stdout", new_callable=io.StringIO) def test_input_correct_command_with_default_flag3(self, mock_stdout: _io.StringIO, magick_mock: MagicMock): router = Router() + orchestrator = Orchestrator() flag = PredefinedFlags.HOST @router.command(Command('test', flags=flag)) - def test(args: InputFlags): - print(f'connecting to host {args[0].get_value()}') + def test(response: Response): + print(f'connecting to host {response.valid_flags.get_flag('host').get_value()}') app = App(override_system_messages=True, print_func=print) app.include_router(router) - app.run_polling() + orchestrator.start_polling(app) output = mock_stdout.getvalue() @@ -156,16 +167,18 @@ class TestSystemHandlerNormalWork(unittest.TestCase): @patch("sys.stdout", new_callable=io.StringIO) def test_input_correct_command_with_two_flags(self, mock_stdout: _io.StringIO, magick_mock: MagicMock): router = Router() + orchestrator = Orchestrator() flags = Flags(PredefinedFlags.HOST, PredefinedFlags.PORT) @router.command(Command('test', flags=flags)) - def test(args: InputFlags): - print(f'connecting to host {args[0].get_value()} and port {args[1].get_value()}') + def test(response: Response): + valid_flags = response.valid_flags + print(f'connecting to host {valid_flags.get_flag('host').get_value()} and port {valid_flags.get_flag('port').get_value()}') app = App(override_system_messages=True, print_func=print) app.include_router(router) - app.run_polling() + orchestrator.start_polling(app) output = mock_stdout.getvalue() @@ -176,19 +189,20 @@ class TestSystemHandlerNormalWork(unittest.TestCase): @patch("sys.stdout", new_callable=io.StringIO) def test_input_two_correct_command(self, mock_stdout: _io.StringIO, magick_mock: MagicMock): router = Router() + orchestrator = Orchestrator() @router.command(Command('test')) - def test(): + def test(response): print(f'test command') @router.command(Command('some')) - def test2(): + def test2(response): print(f'some command') app = App(override_system_messages=True, print_func=print) app.include_router(router) - app.run_polling() + orchestrator.start_polling(app) output = mock_stdout.getvalue() @@ -199,23 +213,24 @@ class TestSystemHandlerNormalWork(unittest.TestCase): @patch("sys.stdout", new_callable=io.StringIO) def test_input_three_correct_command(self, mock_stdout: _io.StringIO, magick_mock: MagicMock): router = Router() + orchestrator = Orchestrator() @router.command(Command('test')) - def test(): + def test(response): print(f'test command') @router.command(Command('some')) - def test(): + def test(response): print(f'some command') @router.command(Command('more')) - def test(): + def test(response): print(f'more command') app = App(override_system_messages=True, print_func=print) app.include_router(router) - app.run_polling() + orchestrator.start_polling(app) output = mock_stdout.getvalue() diff --git a/tests/unit_tests/test_command.py b/tests/unit_tests/test_command.py index 2587c0c..ae43d1c 100644 --- a/tests/unit_tests/test_command.py +++ b/tests/unit_tests/test_command.py @@ -1,10 +1,12 @@ -from argenta.command.flag import Flag, InputFlag, Flags +from argenta.command.flag import Flag, InputFlag +from argenta.command.flags import Flags from argenta.command.models import InputCommand, Command from argenta.command.exceptions import (UnprocessedInputFlagException, RepeatedInputFlagsException, EmptyInputCommandException) import unittest +import re class TestInputCommand(unittest.TestCase): @@ -23,25 +25,37 @@ class TestInputCommand(unittest.TestCase): with self.assertRaises(EmptyInputCommandException): InputCommand.parse('') - def test_validate_correct_input_flag1(self): + def test_validate_valid_input_flag1(self): command = Command('some', flags=Flag('test')) - self.assertEqual(command.validate_input_flag(InputFlag('test')), True) + self.assertEqual(command.validate_input_flag(InputFlag('test')), 'Valid') - def test_validate_correct_input_flag2(self): + def test_validate_valid_input_flag2(self): command = Command('some', flags=Flags(Flag('test'), Flag('more'))) - self.assertEqual(command.validate_input_flag(InputFlag('more')), True) + self.assertEqual(command.validate_input_flag(InputFlag('more')), 'Valid') - def test_validate_incorrect_input_flag1(self): - command = Command('some', flags=Flags(Flag('test'))) - self.assertEqual(command.validate_input_flag(InputFlag('more')), False) + def test_validate_undefined_input_flag1(self): + command = Command('some', flags=Flag('test')) + self.assertEqual(command.validate_input_flag(InputFlag('more')), 'Undefined') - def test_validate_incorrect_input_flag2(self): + def test_validate_undefined_input_flag2(self): command = Command('some', flags=Flags(Flag('test'), Flag('more'))) - self.assertEqual(command.validate_input_flag(InputFlag('case')), False) + self.assertEqual(command.validate_input_flag(InputFlag('case')), 'Undefined') - def test_validate_incorrect_input_flag3(self): + def test_validate_undefined_input_flag3(self): command = Command('some') - self.assertEqual(command.validate_input_flag(InputFlag('case')), False) + self.assertEqual(command.validate_input_flag(InputFlag('case')), 'Undefined') + + def test_invalid_input_flag1(self): + command = Command('some', flags=Flag('test', possible_values=False)) + self.assertEqual(command.validate_input_flag(InputFlag('test', value='example')), 'Invalid') + + def test_invalid_input_flag2(self): + command = Command('some', flags=Flag('test', possible_values=['some', 'case'])) + self.assertEqual(command.validate_input_flag(InputFlag('test', value='slay')), 'Invalid') + + def test_invalid_input_flag3(self): + command = Command('some', flags=Flag('test', possible_values=re.compile(r'^ex\d{, 2}op$'))) + self.assertEqual(command.validate_input_flag(InputFlag('test', value='example')), 'Invalid') def test_isinstance_parse_correct_raw_command(self): cmd = InputCommand.parse('ssh --host 192.168.0.3') diff --git a/tests/unit_tests/test_router.py b/tests/unit_tests/test_router.py index 12baa00..072b2d4 100644 --- a/tests/unit_tests/test_router.py +++ b/tests/unit_tests/test_router.py @@ -1,5 +1,5 @@ from argenta.command.flag import InputFlag, Flag -from argenta.command.flags import Flags, InputFlags, UndefinedInputFlags +from argenta.command.flags import Flags, InputFlags, UndefinedInputFlags, InvalidValueInputFlags, ValidInputFlags from argenta.response import Response from argenta.router import Router from argenta.command import Command @@ -26,65 +26,61 @@ class TestRouter(unittest.TestCase): with self.assertRaises(RepeatedFlagNameException): router._validate_command(Command(trigger='command', flags=Flags(Flag('test'), Flag('test')))) - def test_validate_incorrect_input_flag1(self): + def test_structuring_input_flags1(self): router = Router() cmd = Command('cmd') input_flags = InputFlags(InputFlag('ssh')) self.assertEqual(router._structuring_input_flags(cmd, input_flags).undefined_flags, UndefinedInputFlags(InputFlag('ssh'))) - def test_validate_incorrect_input_flag2(self): + def test_structuring_input_flags2(self): router = Router() - self.assertEqual(router._structuring_input_flags(Command('cmd'), InputFlags(InputFlag('ssh', value='some'))), False) + cmd = Command('cmd') + input_flags = InputFlags(InputFlag('ssh', value='some')) + self.assertEqual(router._structuring_input_flags(cmd, input_flags).undefined_flags, UndefinedInputFlags(InputFlag('ssh', value='some'))) - def test_validate_incorrect_input_flag3(self): + def test_structuring_input_flags3(self): router = Router() - command = Command('cmd', flags=Flag('port')) + cmd = Command('cmd', flags=Flag('port')) input_flags = InputFlags(InputFlag('ssh', value='some2')) - self.assertEqual(router._structuring_input_flags(command, input_flags), False) + self.assertEqual(router._structuring_input_flags(cmd, input_flags).undefined_flags, UndefinedInputFlags(InputFlag('ssh', value='some2'))) - def test_validate_incorrect_input_flag4(self): + def test_structuring_input_flags4(self): router = Router() command = Command('cmd', flags=Flag('ssh', possible_values=False)) input_flags = InputFlags(InputFlag('ssh', value='some3')) - self.assertEqual(router._structuring_input_flags(command, input_flags), False) + self.assertEqual(router._structuring_input_flags(command, input_flags).invalid_value_flags, InvalidValueInputFlags(InputFlag('ssh', value='some3'))) - def test_validate_incorrect_input_flag5(self): + def test_structuring_input_flags5(self): router = Router() command = Command('cmd', flags=Flag('ssh', possible_values=re.compile(r'some[1-5]$'))) input_flags = InputFlags(InputFlag('ssh', value='some40')) - self.assertEqual(router._structuring_input_flags(command, input_flags), False) + self.assertEqual(router._structuring_input_flags(command, input_flags).invalid_value_flags, InvalidValueInputFlags(InputFlag('ssh', value='some40'))) - def test_validate_incorrect_input_flag6(self): + def test_structuring_input_flags6(self): router = Router() command = Command('cmd', flags=Flag('ssh', possible_values=['example'])) input_flags = InputFlags(InputFlag('ssh', value='example2')) - self.assertEqual(router._structuring_input_flags(command, input_flags), False) + self.assertEqual(router._structuring_input_flags(command, input_flags).invalid_value_flags, InvalidValueInputFlags(InputFlag('ssh', value='example2'))) - def test_validate_incorrect_input_flag7(self): - router = Router() - command = Command('cmd', flags=Flag('ssh', possible_values=['example'])) - input_flags = InputFlags(InputFlag('ssh')) - self.assertEqual(router._structuring_input_flags(command, input_flags), False) - - def test_validate_correct_input_flag1(self): + def test_structuring_input_flags7(self): command = Command('cmd', flags=Flag('port')) input_flags = InputFlags(InputFlag('port', value='some2')) - self.assertEqual(Router()._structuring_input_flags(command, input_flags), True) + self.assertEqual(Router()._structuring_input_flags(command, input_flags).valid_flags, ValidInputFlags(InputFlag('port', value='some2'))) - def test_validate_correct_input_flag2(self): + def test_structuring_input_flags8(self): command = Command('cmd', flags=Flag('port', possible_values=['some2', 'some3'])) input_flags = InputFlags(InputFlag('port', value='some2')) - self.assertEqual(Router()._structuring_input_flags(command, input_flags), True) + self.assertEqual(Router()._structuring_input_flags(command, input_flags).valid_flags, ValidInputFlags(InputFlag('port', value='some2'))) - def test_validate_correct_input_flag3(self): + def test_structuring_input_flags9(self): command = Command('cmd', flags=Flag('ssh', possible_values=re.compile(r'more[1-5]$'))) input_flags = InputFlags(InputFlag('ssh', value='more5')) - self.assertEqual(Router()._structuring_input_flags(command, input_flags), True) + self.assertEqual(Router()._structuring_input_flags(command, input_flags).valid_flags, ValidInputFlags(InputFlag('ssh', value='more5'))) - def test_validate_correct_input_flag4(self): + def test_structuring_input_flags10(self): command = Command('cmd', flags=Flag('ssh', possible_values=False)) input_flags = InputFlags(InputFlag('ssh')) - self.assertEqual(Router()._structuring_input_flags(command, input_flags), True) + self.assertEqual(Router()._structuring_input_flags(command, input_flags).valid_flags, ValidInputFlags(InputFlag('ssh'))) def test_validate_incorrect_func_args1(self): def handler(): @@ -101,17 +97,17 @@ class TestRouter(unittest.TestCase): def test_get_router_aliases(self): router = Router() @router.command(Command('some', aliases=['test', 'case'])) - def handler(): + def handler(response): pass self.assertListEqual(router.get_aliases(), ['test', 'case']) def test_get_router_aliases2(self): router = Router() @router.command(Command('some', aliases=['test', 'case'])) - def handler(): + def handler(response): pass @router.command(Command('ext', aliases=['more', 'foo'])) - def handler2(): + def handler2(response): pass self.assertListEqual(router.get_aliases(), ['test', 'case', 'more', 'foo'])