mirror of
https://github.com/koloideal/Argenta.git
synced 2026-06-10 10:05:28 +03:00
refactor, new model e.t.c.
This commit is contained in:
@@ -7,8 +7,8 @@ import re
|
||||
from argenta.app import App
|
||||
from argenta.command import Command
|
||||
from argenta.router import Router
|
||||
from argenta.command.flag import FlagsGroup
|
||||
from argenta.command.flag.defaults import DefaultFlags
|
||||
from argenta.command.flag.registered_flag import FlagsGroup
|
||||
from argenta.command.flag.registered_flag.defaults import DefaultFlags
|
||||
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ class TestSystemHandlerNormalWork(unittest.TestCase):
|
||||
|
||||
output = mock_stdout.getvalue()
|
||||
|
||||
self.assertIn('\nUndefined or incorrect input flag: --help\n', output)
|
||||
self.assertIn('\nUndefined or incorrect input registered_flag: --help\n', output)
|
||||
|
||||
|
||||
@patch("builtins.input", side_effect=["test --port 22", "q"])
|
||||
@@ -82,14 +82,14 @@ class TestSystemHandlerNormalWork(unittest.TestCase):
|
||||
|
||||
output = mock_stdout.getvalue()
|
||||
|
||||
self.assertIn('\nUndefined or incorrect input flag: --port 22\n', output)
|
||||
self.assertIn('\nUndefined or incorrect input registered_flag: --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()
|
||||
flags = FlagsGroup(DefaultFlags.host_flag)
|
||||
flags = FlagsGroup(DefaultFlags.HOST)
|
||||
|
||||
@router.command(Command('test', flags=flags))
|
||||
def test(args: dict):
|
||||
@@ -101,7 +101,7 @@ class TestSystemHandlerNormalWork(unittest.TestCase):
|
||||
|
||||
output = mock_stdout.getvalue()
|
||||
|
||||
self.assertIn('\nUndefined or incorrect input flag: --port 132\n', output)
|
||||
self.assertIn('\nUndefined or incorrect input registered_flag: --port 132\n', output)
|
||||
|
||||
|
||||
@patch("builtins.input", side_effect=["test", "some", "q"])
|
||||
@@ -159,7 +159,7 @@ class TestSystemHandlerNormalWork(unittest.TestCase):
|
||||
|
||||
output = mock_stdout.getvalue()
|
||||
|
||||
self.assertIn("\nIncorrect flag syntax: \"test 535 --port\"\n", output)
|
||||
self.assertIn("\nIncorrect registered_flag syntax: \"test 535 --port\"\n", output)
|
||||
|
||||
|
||||
@patch("builtins.input", side_effect=["", "q"])
|
||||
@@ -185,7 +185,7 @@ class TestSystemHandlerNormalWork(unittest.TestCase):
|
||||
def test_input_correct_command_with_repeated_flags(self, mock_stdout: _io.StringIO, magick_mock: MagicMock):
|
||||
router = Router()
|
||||
|
||||
@router.command(Command('test', flags=DefaultFlags.port_flag))
|
||||
@router.command(Command('test', flags=DefaultFlags.PORT))
|
||||
def test(args):
|
||||
print('test command')
|
||||
|
||||
|
||||
@@ -7,8 +7,8 @@ import re
|
||||
from argenta.app import App
|
||||
from argenta.command import Command
|
||||
from argenta.router import Router
|
||||
from argenta.command.flag import Flag, FlagsGroup
|
||||
from argenta.command.flag.defaults import DefaultFlags
|
||||
from argenta.command.flag.registered_flag import Flag, FlagsGroup
|
||||
from argenta.command.flag.registered_flag.defaults import DefaultFlags
|
||||
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ class TestSystemHandlerNormalWork(unittest.TestCase):
|
||||
|
||||
@router.command(Command('test', flags=flag))
|
||||
def test(args: dict):
|
||||
print(f'\nhelp for {args['help']['name']} flag\n')
|
||||
print(f'\nhelp for {args['help']['name']} registered_flag\n')
|
||||
|
||||
app = App()
|
||||
app.include_router(router)
|
||||
@@ -65,7 +65,7 @@ class TestSystemHandlerNormalWork(unittest.TestCase):
|
||||
|
||||
output = mock_stdout.getvalue()
|
||||
|
||||
self.assertIn('\nhelp for help flag\n', output)
|
||||
self.assertIn('\nhelp for help registered_flag\n', output)
|
||||
|
||||
@patch("builtins.input", side_effect=["test --port 22", "q"])
|
||||
@patch("sys.stdout", new_callable=io.StringIO)
|
||||
@@ -75,7 +75,7 @@ class TestSystemHandlerNormalWork(unittest.TestCase):
|
||||
|
||||
@router.command(Command('test', flags=flag))
|
||||
def test(args: dict):
|
||||
print(f'flag value for {args['port']['name']} flag : {args["port"]["value"]}')
|
||||
print(f'registered_flag value for {args['port']['name']} registered_flag : {args["port"]["value"]}')
|
||||
|
||||
app = App()
|
||||
app.include_router(router)
|
||||
@@ -83,18 +83,18 @@ class TestSystemHandlerNormalWork(unittest.TestCase):
|
||||
|
||||
output = mock_stdout.getvalue()
|
||||
|
||||
self.assertIn('\nflag value for port flag : 22\n', output)
|
||||
self.assertIn('\nregistered_flag value for port registered_flag : 22\n', output)
|
||||
|
||||
|
||||
@patch("builtins.input", side_effect=["test -h", "q"])
|
||||
@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()
|
||||
flag = DefaultFlags.short_help_flag
|
||||
flag = DefaultFlags.SHORT_HELP
|
||||
|
||||
@router.command(Command('test', flags=flag))
|
||||
def test(args: dict):
|
||||
print(f'help for {args['h']['name']} flag')
|
||||
print(f'help for {args['h']['name']} registered_flag')
|
||||
|
||||
app = App()
|
||||
app.include_router(router)
|
||||
@@ -102,14 +102,14 @@ class TestSystemHandlerNormalWork(unittest.TestCase):
|
||||
|
||||
output = mock_stdout.getvalue()
|
||||
|
||||
self.assertIn('\nhelp for h flag\n', output)
|
||||
self.assertIn('\nhelp for h registered_flag\n', output)
|
||||
|
||||
|
||||
@patch("builtins.input", side_effect=["test --info", "q"])
|
||||
@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()
|
||||
flag = DefaultFlags.info_flag
|
||||
flag = DefaultFlags.INFO
|
||||
|
||||
@router.command(Command('test', flags=flag))
|
||||
def test(args: dict):
|
||||
@@ -129,7 +129,7 @@ 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()
|
||||
flag = DefaultFlags.host_flag
|
||||
flag = DefaultFlags.HOST
|
||||
|
||||
@router.command(Command('test', flags=flag))
|
||||
def test(args: dict):
|
||||
@@ -148,7 +148,7 @@ 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()
|
||||
flags = FlagsGroup(DefaultFlags.host_flag, DefaultFlags.port_flag)
|
||||
flags = FlagsGroup(DefaultFlags.HOST, DefaultFlags.PORT)
|
||||
|
||||
@router.command(Command('test', flags=flags))
|
||||
def test(args: dict):
|
||||
@@ -173,7 +173,7 @@ class TestSystemHandlerNormalWork(unittest.TestCase):
|
||||
print(f'test command')
|
||||
|
||||
@router.command(Command('some'))
|
||||
def test():
|
||||
def test2():
|
||||
print(f'some command')
|
||||
|
||||
app = App()
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
from argenta.app import App
|
||||
from argenta.app.exceptions import (InvalidDescriptionMessagePatternException,
|
||||
NoRegisteredRoutersException)
|
||||
from argenta.app.exceptions import InvalidDescriptionMessagePatternException
|
||||
|
||||
import unittest
|
||||
|
||||
@@ -14,7 +13,3 @@ class TestApp(unittest.TestCase):
|
||||
with self.assertRaises(InvalidDescriptionMessagePatternException):
|
||||
App().set_description_message_pattern('Invalid {desription} description {comand} pattern')
|
||||
|
||||
def test_no_registered_router(self):
|
||||
with self.assertRaises(NoRegisteredRoutersException):
|
||||
App()._validate_number_of_routers()
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from argenta.command.flag import Flag
|
||||
from argenta.command.flag.registered_flag import Flag
|
||||
|
||||
import unittest
|
||||
import re
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from argenta.command.flag import Flag, FlagsGroup
|
||||
from argenta.command.flag.registered_flag import Flag, FlagsGroup
|
||||
|
||||
import unittest
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
from argenta.command.flag import FlagsGroup, Flag
|
||||
from argenta.router import Router
|
||||
from argenta.command import Command
|
||||
from argenta.router.exceptions import RepeatedCommandException, TriggerCannotContainSpacesException
|
||||
from argenta.router.exceptions import TriggerCannotContainSpacesException
|
||||
|
||||
import unittest
|
||||
|
||||
@@ -13,102 +12,6 @@ class TestRouter(unittest.TestCase):
|
||||
def test_get_router_title(self):
|
||||
self.assertEqual(Router(title='test title').get_title(), 'test title')
|
||||
|
||||
def test_input_correct_command(self):
|
||||
router = Router()
|
||||
@router.command(Command(trigger='test'))
|
||||
def test():
|
||||
return 'correct result'
|
||||
|
||||
self.assertEqual(router.input_command_handler(Command(trigger='test')), 'correct result')
|
||||
|
||||
def test_input_command_with_invalid_flag(self):
|
||||
router = Router()
|
||||
router.set_invalid_input_flag_handler(lambda x: x)
|
||||
|
||||
@router.command(Command(trigger='test'))
|
||||
def test():
|
||||
return 'correct result'
|
||||
|
||||
input_command = Command(trigger='test')
|
||||
input_command._set_input_flags(FlagsGroup([Flag('host')]))
|
||||
|
||||
self.assertEqual(router.input_command_handler(input_command), None)
|
||||
|
||||
def test_input_correct_command_with_one_register_and_ignore_command_register(self):
|
||||
router = Router()
|
||||
router.set_ignore_command_register(True)
|
||||
@router.command(Command(trigger='test'))
|
||||
def test():
|
||||
return 'correct result'
|
||||
|
||||
self.assertEqual(router.input_command_handler(Command(trigger='test')), 'correct result')
|
||||
|
||||
def test_input_correct_command_with_different_register_and_ignore_command_register(self):
|
||||
router = Router()
|
||||
router.set_ignore_command_register(True)
|
||||
@router.command(Command(trigger='test'))
|
||||
def test():
|
||||
return 'correct result'
|
||||
|
||||
self.assertEqual(router.input_command_handler(Command(trigger='TeSt')), 'correct result')
|
||||
|
||||
def test_input_incorrect_command_with_ignore_command_register(self):
|
||||
router = Router()
|
||||
router.set_ignore_command_register(True)
|
||||
@router.command(Command(trigger='test'))
|
||||
def test():
|
||||
return 'correct result'
|
||||
|
||||
self.assertEqual(router.input_command_handler(Command(trigger='Test2')), None)
|
||||
|
||||
def test_register_repeated_commands_with_one_register(self):
|
||||
router = Router()
|
||||
@router.command(Command(trigger='test'))
|
||||
def test():
|
||||
return 'correct result'
|
||||
|
||||
with self.assertRaises(RepeatedCommandException):
|
||||
@router.command(Command(trigger='test'))
|
||||
def test():
|
||||
return 'correct result'
|
||||
|
||||
def test_register_commands_with_different_register(self):
|
||||
router = Router()
|
||||
@router.command(Command(trigger='test'))
|
||||
def test():
|
||||
return 'correct result'
|
||||
|
||||
try:
|
||||
@router.command(Command(trigger='Test'))
|
||||
def test():
|
||||
return 'correct result'
|
||||
except RepeatedCommandException:
|
||||
self.fail('RepeatedCommandException should not have been thrown')
|
||||
|
||||
def test_register_repeated_commands_with_one_register_and_set_ignore_command_register(self):
|
||||
router = Router()
|
||||
router.set_ignore_command_register(True)
|
||||
@router.command(Command(trigger='test'))
|
||||
def test():
|
||||
return 'correct result'
|
||||
|
||||
with self.assertRaises(RepeatedCommandException):
|
||||
@router.command(Command(trigger='test'))
|
||||
def test():
|
||||
return 'correct result'
|
||||
|
||||
def test_register_repeated_commands_with_different_register_and_set_ignore_command_register(self):
|
||||
router = Router()
|
||||
router.set_ignore_command_register(True)
|
||||
@router.command(Command(trigger='test'))
|
||||
def test():
|
||||
return 'correct result'
|
||||
|
||||
with self.assertRaises(RepeatedCommandException):
|
||||
@router.command(Command(trigger='Test'))
|
||||
def test():
|
||||
return 'correct result'
|
||||
|
||||
def test_register_command_with_spaces_in_trigger(self):
|
||||
router = Router()
|
||||
with self.assertRaises(TriggerCannotContainSpacesException):
|
||||
|
||||
Reference in New Issue
Block a user