diff options
author | Aldo Cortesi <aldo@corte.si> | 2017-12-19 10:09:14 +1300 |
---|---|---|
committer | Aldo Cortesi <aldo@corte.si> | 2017-12-19 10:19:08 +1300 |
commit | 6563feaf059f9c829ba6b57d312a0f1dbfb84e33 (patch) | |
tree | 6baebf45d24369be51964d6a628902e582a325c2 /test | |
parent | cda14830d349f4c1c60af2d1ec563e4894b836c3 (diff) | |
download | mitmproxy-6563feaf059f9c829ba6b57d312a0f1dbfb84e33.tar.gz mitmproxy-6563feaf059f9c829ba6b57d312a0f1dbfb84e33.tar.bz2 mitmproxy-6563feaf059f9c829ba6b57d312a0f1dbfb84e33.zip |
types: use new type validation mechanism in commands
Diffstat (limited to 'test')
-rw-r--r-- | test/mitmproxy/test_command.py | 13 | ||||
-rw-r--r-- | test/mitmproxy/test_types.py | 4 | ||||
-rw-r--r-- | test/mitmproxy/utils/test_typecheck.py | 22 |
3 files changed, 4 insertions, 35 deletions
diff --git a/test/mitmproxy/test_command.py b/test/mitmproxy/test_command.py index f9315dd2..608a08b6 100644 --- a/test/mitmproxy/test_command.py +++ b/test/mitmproxy/test_command.py @@ -8,8 +8,6 @@ import mitmproxy.types import io import pytest -from mitmproxy.utils import typecheck - class TAddon: @command.command("cmd1") @@ -140,7 +138,7 @@ def test_simple(): c.call("nonexistent") with pytest.raises(exceptions.CommandError, match="Invalid"): c.call("") - with pytest.raises(exceptions.CommandError, match="Usage"): + with pytest.raises(exceptions.CommandError, match="argument mismatch"): c.call("one.two too many args") c.add("empty", a.empty) @@ -262,12 +260,3 @@ def test_verify_arg_signature(): command.verify_arg_signature(lambda: None, [1, 2], {}) print('hello there') command.verify_arg_signature(lambda a, b: None, [1, 2], {}) - - -def test_choice(): - """ - basic typechecking for choices should fail as we cannot verify if strings are a valid choice - at this point. - """ - c = mitmproxy.types.Choice("foo") - assert not typecheck.check_command_type("foo", c) diff --git a/test/mitmproxy/test_types.py b/test/mitmproxy/test_types.py index dcf7a1d2..df9bd4e0 100644 --- a/test/mitmproxy/test_types.py +++ b/test/mitmproxy/test_types.py @@ -125,8 +125,10 @@ def test_strseq(): assert b.completion(tctx.master.commands, typing.Sequence[str], "") == [] assert b.parse(tctx.master.commands, typing.Sequence[str], "foo") == ["foo"] assert b.parse(tctx.master.commands, typing.Sequence[str], "foo,bar") == ["foo", "bar"] - assert b.is_valid(tctx.master.commands, typing.Sequence[str], "foo") is True + assert b.is_valid(tctx.master.commands, typing.Sequence[str], ["foo"]) is True + assert b.is_valid(tctx.master.commands, typing.Sequence[str], ["a", "b", 3]) is False assert b.is_valid(tctx.master.commands, typing.Sequence[str], 1) is False + assert b.is_valid(tctx.master.commands, typing.Sequence[str], "foo") is False class DummyConsole: diff --git a/test/mitmproxy/utils/test_typecheck.py b/test/mitmproxy/utils/test_typecheck.py index 365509f1..5295fff5 100644 --- a/test/mitmproxy/utils/test_typecheck.py +++ b/test/mitmproxy/utils/test_typecheck.py @@ -87,28 +87,6 @@ def test_check_any(): typecheck.check_option_type("foo", None, typing.Any) -def test_check_command_type(): - assert(typecheck.check_command_type("foo", str)) - assert(typecheck.check_command_type(["foo"], typing.Sequence[str])) - assert(not typecheck.check_command_type(["foo", 1], typing.Sequence[str])) - assert(typecheck.check_command_type(None, None)) - assert(not typecheck.check_command_type(["foo"], typing.Sequence[int])) - assert(not typecheck.check_command_type("foo", typing.Sequence[int])) - - # Python 3.5 only defines __parameters__ - m = mock.Mock() - m.__str__ = lambda self: "typing.Sequence" - m.__parameters__ = (int,) - - typecheck.check_command_type([10], m) - - # Python 3.5 only defines __union_params__ - m = mock.Mock() - m.__str__ = lambda self: "typing.Union" - m.__union_params__ = (int,) - assert not typecheck.check_command_type([22], m) - - def test_typesec_to_str(): assert(typecheck.typespec_to_str(str)) == "str" assert(typecheck.typespec_to_str(typing.Sequence[str])) == "sequence of str" |