diff options
author | Aldo Cortesi <aldo@corte.si> | 2017-12-15 11:34:53 +1300 |
---|---|---|
committer | Aldo Cortesi <aldo@corte.si> | 2017-12-15 11:38:37 +1300 |
commit | 1c097813c16d530631562727cd9c2db0fae8755d (patch) | |
tree | 5edd65624284aef02198260f2819d3046acf9bef /test | |
parent | 8c0ba71fd8f2e29e8348c88aa6d653d3161ea20a (diff) | |
download | mitmproxy-1c097813c16d530631562727cd9c2db0fae8755d.tar.gz mitmproxy-1c097813c16d530631562727cd9c2db0fae8755d.tar.bz2 mitmproxy-1c097813c16d530631562727cd9c2db0fae8755d.zip |
commands: emit types from partial parser, implement choice completion
Diffstat (limited to 'test')
-rw-r--r-- | test/mitmproxy/test_command.py | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/test/mitmproxy/test_command.py b/test/mitmproxy/test_command.py index b4711236..76ce2245 100644 --- a/test/mitmproxy/test_command.py +++ b/test/mitmproxy/test_command.py @@ -11,19 +11,24 @@ from mitmproxy.utils import typecheck class TAddon: + @command.command("cmd1") def cmd1(self, foo: str) -> str: """cmd1 help""" return "ret " + foo + @command.command("cmd2") def cmd2(self, foo: str) -> str: return 99 + @command.command("cmd3") def cmd3(self, foo: int) -> int: return foo + @command.command("empty") def empty(self) -> None: pass + @command.command("varargs") def varargs(self, one: str, *var: str) -> typing.Sequence[str]: return list(var) @@ -34,6 +39,7 @@ class TAddon: def choose(self, arg: str) -> typing.Sequence[str]: return ["one", "two", "three"] + @command.command("path") def path(self, arg: command.Path) -> None: pass @@ -82,11 +88,25 @@ class TestCommand: ], ["a", [command.ParseResult(value = "a", type = command.Cmd)]], ["", [command.ParseResult(value = "", type = command.Cmd)]], + [ + "cmd3 1", + [ + command.ParseResult(value = "cmd3", type = command.Cmd), + command.ParseResult(value = "1", type = int), + ] + ], + [ + "cmd3 ", + [ + command.ParseResult(value = "cmd3", type = command.Cmd), + command.ParseResult(value = "", type = int), + ] + ], ] with taddons.context() as tctx: - cm = command.CommandManager(tctx.master) + tctx.master.addons.add(TAddon()) for s, expected in tests: - assert cm.parse_partial(s) == expected + assert tctx.master.commands.parse_partial(s) == expected def test_simple(): |