work on docs, tests and some fix

This commit is contained in:
2025-03-05 02:20:02 +03:00
parent 971258728c
commit 2bf2144815
25 changed files with 262 additions and 397 deletions
+2 -3
View File
@@ -1,5 +1,4 @@
from argenta.command import Command
from argenta.command.params.flag import Flag, FlagsGroup
from argenta.command.exceptions import (UnprocessedInputFlagException,
RepeatedInputFlagsException,
EmptyInputCommandException)
@@ -9,7 +8,7 @@ import unittest
class TestCommand(unittest.TestCase):
def test_parse_correct_raw_command(self):
self.assertEqual(Command.parse_input_command('ssh --host 192.168.0.3').get_string_entity(), 'ssh')
self.assertEqual(Command.parse_input_command('ssh --host 192.168.0.3').get_trigger(), 'ssh')
def test_parse_raw_command_with_flag_name_without_value(self):
with self.assertRaises(UnprocessedInputFlagException):
@@ -28,5 +27,5 @@ class TestCommand(unittest.TestCase):
Command.parse_input_command('')
def test_get_command_description(self):
self.assertEqual(Command(command='test', description='test description').get_description(), 'test description')
self.assertEqual(Command(trigger='test', description='test description').get_description(), 'test description')
+2 -2
View File
@@ -7,7 +7,7 @@ import re
class TestFlag(unittest.TestCase):
def test_get_string_entity(self):
self.assertEqual(Flag(flag_name='test').get_string_entity(),
'-test')
'--test')
def test_get_string_entity2(self):
self.assertEqual(Flag(flag_name='test',
@@ -20,7 +20,7 @@ class TestFlag(unittest.TestCase):
def test_get_flag_prefix(self):
self.assertEqual(Flag(flag_name='test').get_flag_prefix(),
'-')
'--')
def test_get_flag_prefix2(self):
self.assertEqual(Flag(flag_name='test',
+23
View File
@@ -24,3 +24,26 @@ class TestFlagsGroup(unittest.TestCase):
flags = FlagsGroup()
flags.add_flags([Flag('test'), Flag('test2')])
self.assertEqual(len(flags.get_flags()), 2)
def test_unparse_flags_to_dict(self):
list_of_flags = [
Flag('test1'),
Flag('test2'),
Flag('test3'),
]
flags = FlagsGroup(list_of_flags)
serialized_flags = flags.unparse_to_dict()
needed_result = {'test1': {'name': 'test1',
'prefix': '--',
'string_entity': '--test1',
'value': None},
'test2': {'name': 'test2',
'prefix': '--',
'string_entity': '--test2',
'value': None},
'test3': {'name': 'test3',
'prefix': '--',
'string_entity': '--test3',
'value': None}}
self.assertDictEqual(serialized_flags, needed_result)
+19 -19
View File
@@ -15,71 +15,71 @@ class TestRouter(unittest.TestCase):
def test_input_correct_command(self):
router = Router()
@router.command(Command(command='test'))
@router.command(Command(trigger='test'))
def test():
return 'correct result'
self.assertEqual(router.input_command_handler(Command(command='test')), '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(command='test'))
@router.command(Command(trigger='test'))
def test():
return 'correct result'
input_command = Command(command='test')
input_command.set_input_flags(FlagsGroup([Flag('host')]))
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(command='test'))
@router.command(Command(trigger='test'))
def test():
return 'correct result'
self.assertEqual(router.input_command_handler(Command(command='test')), '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(command='test'))
@router.command(Command(trigger='test'))
def test():
return 'correct result'
self.assertEqual(router.input_command_handler(Command(command='TeSt')), '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(command='test'))
@router.command(Command(trigger='test'))
def test():
return 'correct result'
self.assertEqual(router.input_command_handler(Command(command='Test2')), None)
self.assertEqual(router.input_command_handler(Command(trigger='Test2')), None)
def test_register_repeated_commands_with_one_register(self):
router = Router()
@router.command(Command(command='test'))
@router.command(Command(trigger='test'))
def test():
return 'correct result'
with self.assertRaises(RepeatedCommandException):
@router.command(Command(command='test'))
@router.command(Command(trigger='test'))
def test():
return 'correct result'
def test_register_commands_with_different_register(self):
router = Router()
@router.command(Command(command='test'))
@router.command(Command(trigger='test'))
def test():
return 'correct result'
try:
@router.command(Command(command='Test'))
@router.command(Command(trigger='Test'))
def test():
return 'correct result'
except RepeatedCommandException:
@@ -88,24 +88,24 @@ class TestRouter(unittest.TestCase):
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(command='test'))
@router.command(Command(trigger='test'))
def test():
return 'correct result'
with self.assertRaises(RepeatedCommandException):
@router.command(Command(command='test'))
@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(command='test'))
@router.command(Command(trigger='test'))
def test():
return 'correct result'
with self.assertRaises(RepeatedCommandException):
@router.command(Command(command='Test'))
@router.command(Command(trigger='Test'))
def test():
return 'correct result'