42 lines
1.3 KiB
Python
42 lines
1.3 KiB
Python
import unittest
|
|
|
|
from sbp import commands, protocols
|
|
from sbp.cli import build_parser
|
|
|
|
|
|
class ParserTest(unittest.TestCase):
|
|
def setUp(self) -> None:
|
|
self.parser = build_parser()
|
|
|
|
def test_every_command_has_a_module(self) -> None:
|
|
sub = next(
|
|
action for action in self.parser._actions if action.dest == "command"
|
|
)
|
|
registered = set(sub.choices)
|
|
self.assertEqual(registered, set(commands.COMMANDS))
|
|
|
|
def test_protocol_choices_match_registry(self) -> None:
|
|
args = self.parser.parse_args(["protocol", "enable", "hysteria2", "--port", "24000"])
|
|
self.assertEqual(args.command, "protocol")
|
|
self.assertEqual(args.action, "enable")
|
|
self.assertEqual(args.port, 24000)
|
|
self.assertEqual(set(protocols.keys()), set(protocols.REGISTRY))
|
|
|
|
def test_user_show_options(self) -> None:
|
|
args = self.parser.parse_args(
|
|
["user", "show", "phone", "--protocol", "trojan", "--json"]
|
|
)
|
|
self.assertEqual(args.name, "phone")
|
|
self.assertEqual(args.protocol, "trojan")
|
|
self.assertTrue(args.json)
|
|
|
|
def test_install_defaults(self) -> None:
|
|
args = self.parser.parse_args(["install"])
|
|
self.assertEqual(args.base_port, 20000)
|
|
self.assertFalse(args.force)
|
|
self.assertIsNone(args.protocols)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|