mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2025-02-02 00:05:27 +00:00
test that defaultkeys are valid commands
This commit is contained in:
parent
5661b40942
commit
465044c373
@ -76,11 +76,7 @@ class Command:
|
|||||||
ret = " -> " + ret
|
ret = " -> " + ret
|
||||||
return "%s %s%s" % (self.path, params, ret)
|
return "%s %s%s" % (self.path, params, ret)
|
||||||
|
|
||||||
def call(self, args: typing.Sequence[str]) -> typing.Any:
|
def prepare_args(self, args: typing.Sequence[str]) -> typing.List[typing.Any]:
|
||||||
"""
|
|
||||||
Call the command with a list of arguments. At this point, all
|
|
||||||
arguments are strings.
|
|
||||||
"""
|
|
||||||
verify_arg_signature(self.func, list(args), {})
|
verify_arg_signature(self.func, list(args), {})
|
||||||
|
|
||||||
remainder = [] # type: typing.Sequence[str]
|
remainder = [] # type: typing.Sequence[str]
|
||||||
@ -92,6 +88,14 @@ class Command:
|
|||||||
for arg, paramtype in zip(args, self.paramtypes):
|
for arg, paramtype in zip(args, self.paramtypes):
|
||||||
pargs.append(parsearg(self.manager, arg, paramtype))
|
pargs.append(parsearg(self.manager, arg, paramtype))
|
||||||
pargs.extend(remainder)
|
pargs.extend(remainder)
|
||||||
|
return pargs
|
||||||
|
|
||||||
|
def call(self, args: typing.Sequence[str]) -> typing.Any:
|
||||||
|
"""
|
||||||
|
Call the command with a list of arguments. At this point, all
|
||||||
|
arguments are strings.
|
||||||
|
"""
|
||||||
|
pargs = self.prepare_args(args)
|
||||||
|
|
||||||
with self.manager.master.handlecontext():
|
with self.manager.master.handlecontext():
|
||||||
ret = self.func(*pargs)
|
ret = self.func(*pargs)
|
||||||
@ -121,7 +125,7 @@ ParseResult = typing.NamedTuple(
|
|||||||
class CommandManager(mitmproxy.types._CommandBase):
|
class CommandManager(mitmproxy.types._CommandBase):
|
||||||
def __init__(self, master):
|
def __init__(self, master):
|
||||||
self.master = master
|
self.master = master
|
||||||
self.commands = {}
|
self.commands = {} # type: typing.Dict[str, Command]
|
||||||
|
|
||||||
def collect_commands(self, addon):
|
def collect_commands(self, addon):
|
||||||
for i in dir(addon):
|
for i in dir(addon):
|
||||||
|
23
test/mitmproxy/tools/console/test_defaultkeys.py
Normal file
23
test/mitmproxy/tools/console/test_defaultkeys.py
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
from mitmproxy.test.tflow import tflow
|
||||||
|
from mitmproxy.tools.console import defaultkeys
|
||||||
|
from mitmproxy.tools.console import keymap
|
||||||
|
from mitmproxy.tools.console import master
|
||||||
|
from mitmproxy import command
|
||||||
|
|
||||||
|
|
||||||
|
def test_commands_exist():
|
||||||
|
km = keymap.Keymap(None)
|
||||||
|
defaultkeys.map(km)
|
||||||
|
assert km.bindings
|
||||||
|
m = master.ConsoleMaster(None)
|
||||||
|
m.load_flow(tflow())
|
||||||
|
|
||||||
|
for binding in km.bindings:
|
||||||
|
cmd, *args = command.lexer(binding.command)
|
||||||
|
assert cmd in m.commands.commands
|
||||||
|
|
||||||
|
cmd_obj = m.commands.commands[cmd]
|
||||||
|
try:
|
||||||
|
cmd_obj.prepare_args(args)
|
||||||
|
except Exception as e:
|
||||||
|
raise ValueError("Invalid command: {}".format(binding.command)) from e
|
Loading…
Reference in New Issue
Block a user