diff options
author | Aldo Cortesi <aldo@corte.si> | 2018-05-12 11:46:28 +1200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-12 11:46:28 +1200 |
commit | 45c435592fef8419c12ffe8c7152fbfa4e04144d (patch) | |
tree | 24267cc9cbedf95f7dc9f34abac7625aa89cbc60 /test | |
parent | ac7880132e9b1d7c0b4ae27df846e63b6424c27a (diff) | |
parent | 482043cdcfbcf48ecd7a0185a20c8678ce7deb0d (diff) | |
download | mitmproxy-45c435592fef8419c12ffe8c7152fbfa4e04144d.tar.gz mitmproxy-45c435592fef8419c12ffe8c7152fbfa4e04144d.tar.bz2 mitmproxy-45c435592fef8419c12ffe8c7152fbfa4e04144d.zip |
Merge pull request #3115 from cortesi/cmds
commands fixes and improvements
Diffstat (limited to 'test')
-rw-r--r-- | test/mitmproxy/test_command.py | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/test/mitmproxy/test_command.py b/test/mitmproxy/test_command.py index ea1017e7..7c0dc06d 100644 --- a/test/mitmproxy/test_command.py +++ b/test/mitmproxy/test_command.py @@ -1,4 +1,5 @@ import typing +import inspect from mitmproxy import command from mitmproxy import flow from mitmproxy import exceptions @@ -55,7 +56,35 @@ class TAddon: pass +class Unsupported: + pass + + +class TypeErrAddon: + @command.command("noret") + def noret(self): + pass + + @command.command("invalidret") + def invalidret(self) -> Unsupported: + pass + + @command.command("invalidarg") + def invalidarg(self, u: Unsupported): + pass + + class TestCommand: + def test_typecheck(self): + with taddons.context(loadcore=False) as tctx: + cm = command.CommandManager(tctx.master) + a = TypeErrAddon() + command.Command(cm, "noret", a.noret) + with pytest.raises(exceptions.CommandError): + command.Command(cm, "invalidret", a.invalidret) + with pytest.raises(exceptions.CommandError): + command.Command(cm, "invalidarg", a.invalidarg) + def test_varargs(self): with taddons.context() as tctx: cm = command.CommandManager(tctx.master) @@ -275,6 +304,11 @@ def test_typename(): assert command.typename(mitmproxy.types.Path) == "path" assert command.typename(mitmproxy.types.Cmd) == "cmd" + with pytest.raises(exceptions.CommandError, match="missing type annotation"): + command.typename(inspect._empty) + with pytest.raises(exceptions.CommandError, match="unsupported type"): + command.typename(None) + class DummyConsole: @command.command("view.resolve") @@ -326,7 +360,8 @@ class TCmds(TAttr): pass -def test_collect_commands(): +@pytest.mark.asyncio +async def test_collect_commands(): """ This tests for the error thrown by hasattr() """ @@ -336,6 +371,10 @@ def test_collect_commands(): c.collect_commands(a) assert "empty" in c.commands + a = TypeErrAddon() + c.collect_commands(a) + await tctx.master.await_log("Could not load") + def test_decorator(): with taddons.context() as tctx: |