diff options
author | Aldo Cortesi <aldo@corte.si> | 2017-04-30 22:30:29 +1200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-30 22:30:29 +1200 |
commit | b10a3992d8a66d993894b7dc1755a741229357fa (patch) | |
tree | 136b6d7a0309d707c22c1fbd91ba30bdfc250642 /test | |
parent | 82f87919e2494576d073f930ce0adaf31106c3e9 (diff) | |
parent | a570caccbda28f19e637231df10b28550e8919af (diff) | |
download | mitmproxy-b10a3992d8a66d993894b7dc1755a741229357fa.tar.gz mitmproxy-b10a3992d8a66d993894b7dc1755a741229357fa.tar.bz2 mitmproxy-b10a3992d8a66d993894b7dc1755a741229357fa.zip |
Merge pull request #2296 from cortesi/viewload
commands: view.load
Diffstat (limited to 'test')
-rw-r--r-- | test/mitmproxy/addons/test_export.py | 109 | ||||
-rw-r--r-- | test/mitmproxy/addons/test_view.py | 21 | ||||
-rw-r--r-- | test/mitmproxy/data/test_flow_export/locust_get.py | 35 | ||||
-rw-r--r-- | test/mitmproxy/data/test_flow_export/locust_patch.py | 37 | ||||
-rw-r--r-- | test/mitmproxy/data/test_flow_export/locust_post.py | 26 | ||||
-rw-r--r-- | test/mitmproxy/data/test_flow_export/locust_task_get.py | 20 | ||||
-rw-r--r-- | test/mitmproxy/data/test_flow_export/locust_task_patch.py | 22 | ||||
-rw-r--r-- | test/mitmproxy/data/test_flow_export/locust_task_post.py | 11 | ||||
-rw-r--r-- | test/mitmproxy/data/test_flow_export/python_get.py | 9 | ||||
-rw-r--r-- | test/mitmproxy/data/test_flow_export/python_patch.py | 10 | ||||
-rw-r--r-- | test/mitmproxy/data/test_flow_export/python_post.py | 17 | ||||
-rw-r--r-- | test/mitmproxy/data/test_flow_export/python_post_json.py | 9 | ||||
-rw-r--r-- | test/mitmproxy/test_command.py | 54 | ||||
-rw-r--r-- | test/mitmproxy/test_export.py | 133 | ||||
-rw-r--r-- | test/mitmproxy/utils/test_typecheck.py | 23 |
15 files changed, 178 insertions, 358 deletions
diff --git a/test/mitmproxy/addons/test_export.py b/test/mitmproxy/addons/test_export.py new file mode 100644 index 00000000..5c7c4976 --- /dev/null +++ b/test/mitmproxy/addons/test_export.py @@ -0,0 +1,109 @@ +import pytest +import os + +from mitmproxy import exceptions +from mitmproxy.addons import export # heh +from mitmproxy.test import tflow +from mitmproxy.test import tutils +from mitmproxy.test import taddons +from unittest import mock + + +@pytest.fixture +def get_request(): + return tflow.tflow( + req=tutils.treq( + method=b'GET', + content=b'', + path=b"/path?a=foo&a=bar&b=baz" + ) + ) + + +@pytest.fixture +def post_request(): + return tflow.tflow( + req=tutils.treq( + method=b'POST', + headers=(), + content=bytes(range(256)) + ) + ) + + +@pytest.fixture +def patch_request(): + return tflow.tflow( + req=tutils.treq(method=b'PATCH', path=b"/path?query=param") + ) + + +@pytest.fixture +def tcp_flow(): + return tflow.ttcpflow() + + +class TestExportCurlCommand: + def test_get(self, get_request): + result = """curl -H 'header:qvalue' -H 'content-length:7' 'http://address:22/path?a=foo&a=bar&b=baz'""" + assert export.curl_command(get_request) == result + + def test_post(self, post_request): + result = "curl -X POST 'http://address:22/path' --data-binary '{}'".format( + str(bytes(range(256)))[2:-1] + ) + assert export.curl_command(post_request) == result + + def test_patch(self, patch_request): + result = """curl -H 'header:qvalue' -H 'content-length:7' -X PATCH 'http://address:22/path?query=param' --data-binary 'content'""" + assert export.curl_command(patch_request) == result + + def test_tcp(self, tcp_flow): + with pytest.raises(exceptions.CommandError): + export.curl_command(tcp_flow) + + +class TestRaw: + def test_get(self, get_request): + assert b"header: qvalue" in export.raw(get_request) + + def test_tcp(self, tcp_flow): + with pytest.raises(exceptions.CommandError): + export.raw(tcp_flow) + + +def qr(f): + with open(f, "rb") as fp: + return fp.read() + + +def test_export(tmpdir): + f = str(tmpdir.join("path")) + e = export.Export() + with taddons.context(): + assert e.formats() == ["curl", "raw"] + with pytest.raises(exceptions.CommandError): + e.file("nonexistent", tflow.tflow(resp=True), f) + + e.file("raw", tflow.tflow(resp=True), f) + assert qr(f) + os.unlink(f) + + e.file("curl", tflow.tflow(resp=True), f) + assert qr(f) + os.unlink(f) + + +def test_clip(tmpdir): + e = export.Export() + with taddons.context(): + with pytest.raises(exceptions.CommandError): + e.clip("nonexistent", tflow.tflow(resp=True)) + + with mock.patch('pyperclip.copy') as pc: + e.clip("raw", tflow.tflow(resp=True)) + assert pc.called + + with mock.patch('pyperclip.copy') as pc: + e.clip("curl", tflow.tflow(resp=True)) + assert pc.called diff --git a/test/mitmproxy/addons/test_view.py b/test/mitmproxy/addons/test_view.py index 979f0aa1..eddcb04c 100644 --- a/test/mitmproxy/addons/test_view.py +++ b/test/mitmproxy/addons/test_view.py @@ -5,6 +5,7 @@ from mitmproxy.test import tflow from mitmproxy.addons import view from mitmproxy import flowfilter from mitmproxy import exceptions +from mitmproxy import io from mitmproxy.test import taddons @@ -130,10 +131,28 @@ def test_filter(): assert len(v) == 4 -def test_load(): +def tdump(path, flows): + w = io.FlowWriter(open(path, "wb")) + for i in flows: + w.add(i) + + +def test_load(tmpdir): + path = str(tmpdir.join("path")) v = view.View() with taddons.context() as tctx: tctx.master.addons.add(v) + tdump( + path, + [ + tflow.tflow(resp=True), + tflow.tflow(resp=True) + ] + ) + v.load_file(path) + assert len(v) == 2 + v.load_file(path) + assert len(v) == 4 def test_resolve(): diff --git a/test/mitmproxy/data/test_flow_export/locust_get.py b/test/mitmproxy/data/test_flow_export/locust_get.py deleted file mode 100644 index 632d5d53..00000000 --- a/test/mitmproxy/data/test_flow_export/locust_get.py +++ /dev/null @@ -1,35 +0,0 @@ -from locust import HttpLocust, TaskSet, task - -class UserBehavior(TaskSet): - def on_start(self): - ''' on_start is called when a Locust start before any task is scheduled ''' - self.path() - - @task() - def path(self): - url = self.locust.host + '/path' - - headers = { - 'header': 'qvalue', - 'content-length': '7', - } - - params = { - 'a': ['foo', 'bar'], - 'b': 'baz', - } - - self.response = self.client.request( - method='GET', - url=url, - headers=headers, - params=params, - ) - - ### Additional tasks can go here ### - - -class WebsiteUser(HttpLocust): - task_set = UserBehavior - min_wait = 1000 - max_wait = 3000 diff --git a/test/mitmproxy/data/test_flow_export/locust_patch.py b/test/mitmproxy/data/test_flow_export/locust_patch.py deleted file mode 100644 index f64e0857..00000000 --- a/test/mitmproxy/data/test_flow_export/locust_patch.py +++ /dev/null @@ -1,37 +0,0 @@ -from locust import HttpLocust, TaskSet, task - -class UserBehavior(TaskSet): - def on_start(self): - ''' on_start is called when a Locust start before any task is scheduled ''' - self.path() - - @task() - def path(self): - url = self.locust.host + '/path' - - headers = { - 'header': 'qvalue', - 'content-length': '7', - } - - params = { - 'query': 'param', - } - - data = '''content''' - - self.response = self.client.request( - method='PATCH', - url=url, - headers=headers, - params=params, - data=data, - ) - - ### Additional tasks can go here ### - - -class WebsiteUser(HttpLocust): - task_set = UserBehavior - min_wait = 1000 - max_wait = 3000 diff --git a/test/mitmproxy/data/test_flow_export/locust_post.py b/test/mitmproxy/data/test_flow_export/locust_post.py deleted file mode 100644 index df23476a..00000000 --- a/test/mitmproxy/data/test_flow_export/locust_post.py +++ /dev/null @@ -1,26 +0,0 @@ -from locust import HttpLocust, TaskSet, task - -class UserBehavior(TaskSet): - def on_start(self): - ''' on_start is called when a Locust start before any task is scheduled ''' - self.path() - - @task() - def path(self): - url = self.locust.host + '/path' - - data = '''content''' - - self.response = self.client.request( - method='POST', - url=url, - data=data, - ) - - ### Additional tasks can go here ### - - -class WebsiteUser(HttpLocust): - task_set = UserBehavior - min_wait = 1000 - max_wait = 3000 diff --git a/test/mitmproxy/data/test_flow_export/locust_task_get.py b/test/mitmproxy/data/test_flow_export/locust_task_get.py deleted file mode 100644 index 03821cd8..00000000 --- a/test/mitmproxy/data/test_flow_export/locust_task_get.py +++ /dev/null @@ -1,20 +0,0 @@ - @task() - def path(self): - url = self.locust.host + '/path' - - headers = { - 'header': 'qvalue', - 'content-length': '7', - } - - params = { - 'a': ['foo', 'bar'], - 'b': 'baz', - } - - self.response = self.client.request( - method='GET', - url=url, - headers=headers, - params=params, - ) diff --git a/test/mitmproxy/data/test_flow_export/locust_task_patch.py b/test/mitmproxy/data/test_flow_export/locust_task_patch.py deleted file mode 100644 index d425209c..00000000 --- a/test/mitmproxy/data/test_flow_export/locust_task_patch.py +++ /dev/null @@ -1,22 +0,0 @@ - @task() - def path(self): - url = self.locust.host + '/path' - - headers = { - 'header': 'qvalue', - 'content-length': '7', - } - - params = { - 'query': 'param', - } - - data = '''content''' - - self.response = self.client.request( - method='PATCH', - url=url, - headers=headers, - params=params, - data=data, - ) diff --git a/test/mitmproxy/data/test_flow_export/locust_task_post.py b/test/mitmproxy/data/test_flow_export/locust_task_post.py deleted file mode 100644 index a5f307ee..00000000 --- a/test/mitmproxy/data/test_flow_export/locust_task_post.py +++ /dev/null @@ -1,11 +0,0 @@ - @task() - def path(self): - url = self.locust.host + '/path' - - data = '''\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\x7f\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff''' - - self.response = self.client.request( - method='POST', - url=url, - data=data, - ) diff --git a/test/mitmproxy/data/test_flow_export/python_get.py b/test/mitmproxy/data/test_flow_export/python_get.py deleted file mode 100644 index e9ed072a..00000000 --- a/test/mitmproxy/data/test_flow_export/python_get.py +++ /dev/null @@ -1,9 +0,0 @@ -import requests - -response = requests.get( - 'http://address:22/path', - params=[('a', 'foo'), ('a', 'bar'), ('b', 'baz')], - headers={'header': 'qvalue'} -) - -print(response.text)
\ No newline at end of file diff --git a/test/mitmproxy/data/test_flow_export/python_patch.py b/test/mitmproxy/data/test_flow_export/python_patch.py deleted file mode 100644 index d83a57b9..00000000 --- a/test/mitmproxy/data/test_flow_export/python_patch.py +++ /dev/null @@ -1,10 +0,0 @@ -import requests - -response = requests.patch( - 'http://address:22/path', - params=[('query', 'param')], - headers={'header': 'qvalue'}, - data=b'content' -) - -print(response.text)
\ No newline at end of file diff --git a/test/mitmproxy/data/test_flow_export/python_post.py b/test/mitmproxy/data/test_flow_export/python_post.py deleted file mode 100644 index 42f1af9a..00000000 --- a/test/mitmproxy/data/test_flow_export/python_post.py +++ /dev/null @@ -1,17 +0,0 @@ -import requests - -response = requests.post( - 'http://address:22/path', - data=(b'\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f\x10\x11\x12\x13' - b'\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f !"#$%&\'()*+,-./01234567' - b'89:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\x7f' - b'\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f' - b'\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f' - b'\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf' - b'\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf' - b'\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf' - b'\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf' - b'\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef' - b'\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff') -) -print(response.text) diff --git a/test/mitmproxy/data/test_flow_export/python_post_json.py b/test/mitmproxy/data/test_flow_export/python_post_json.py deleted file mode 100644 index d6ae6357..00000000 --- a/test/mitmproxy/data/test_flow_export/python_post_json.py +++ /dev/null @@ -1,9 +0,0 @@ -import requests - -response = requests.post( - 'http://address:22/path', - headers={'content-type': 'application/json'}, - json={'email': 'example@example.com', 'name': 'example'} -) - -print(response.text)
\ No newline at end of file diff --git a/test/mitmproxy/test_command.py b/test/mitmproxy/test_command.py index 24d11d37..958328b2 100644 --- a/test/mitmproxy/test_command.py +++ b/test/mitmproxy/test_command.py @@ -1,9 +1,6 @@ import typing from mitmproxy import command from mitmproxy import flow -from mitmproxy import master -from mitmproxy import options -from mitmproxy import proxy from mitmproxy import exceptions from mitmproxy.test import tflow from mitmproxy.test import taddons @@ -19,24 +16,41 @@ class TAddon: def cmd2(self, foo: str) -> str: return 99 + def cmd3(self, foo: int) -> int: + return foo + def empty(self) -> None: pass + def varargs(self, one: str, *var: typing.Sequence[str]) -> typing.Sequence[str]: + return list(var) + class TestCommand: + def test_varargs(self): + with taddons.context() as tctx: + cm = command.CommandManager(tctx.master) + a = TAddon() + c = command.Command(cm, "varargs", a.varargs) + assert c.signature_help() == "varargs str *str -> [str]" + assert c.call(["one", "two", "three"]) == ["two", "three"] + with pytest.raises(exceptions.CommandError): + c.call(["one", "two", 3]) + def test_call(self): - o = options.Options() - m = master.Master(o, proxy.DummyServer(o)) - cm = command.CommandManager(m) + with taddons.context() as tctx: + cm = command.CommandManager(tctx.master) + a = TAddon() + c = command.Command(cm, "cmd.path", a.cmd1) + assert c.call(["foo"]) == "ret foo" + assert c.signature_help() == "cmd.path str -> str" - a = TAddon() - c = command.Command(cm, "cmd.path", a.cmd1) - assert c.call(["foo"]) == "ret foo" - assert c.signature_help() == "cmd.path str -> str" + c = command.Command(cm, "cmd.two", a.cmd2) + with pytest.raises(exceptions.CommandError): + c.call(["foo"]) - c = command.Command(cm, "cmd.two", a.cmd2) - with pytest.raises(exceptions.CommandError): - c.call(["foo"]) + c = command.Command(cm, "cmd.three", a.cmd3) + assert c.call(["1"]) == 1 def test_simple(): @@ -70,17 +84,16 @@ def test_typename(): assert command.typename(command.Cuts, True) == "[cuts]" assert command.typename(flow.Flow, False) == "flow" + assert command.typename(typing.Sequence[str], False) == "[str]" class DummyConsole: - def load(self, l): - l.add_command("view.resolve", self.resolve) - l.add_command("cut", self.cut) - + @command.command("view.resolve") def resolve(self, spec: str) -> typing.Sequence[flow.Flow]: n = int(spec) return [tflow.tflow(resp=True)] * n + @command.command("cut") def cut(self, spec: str) -> command.Cuts: return [["test"]] @@ -114,6 +127,13 @@ def test_parsearg(): tctx.master.commands, "foo", command.Cuts ) == [["test"]] + assert command.parsearg( + tctx.master.commands, "foo", typing.Sequence[str] + ) == ["foo"] + assert command.parsearg( + tctx.master.commands, "foo, bar", typing.Sequence[str] + ) == ["foo", "bar"] + class TDec: @command.command("cmd1") diff --git a/test/mitmproxy/test_export.py b/test/mitmproxy/test_export.py deleted file mode 100644 index b789e6b5..00000000 --- a/test/mitmproxy/test_export.py +++ /dev/null @@ -1,133 +0,0 @@ -import re - -import pytest - -from mitmproxy import export # heh -from mitmproxy.net.http import Headers -from mitmproxy.test import tflow -from mitmproxy.test import tutils - - -def clean_blanks(s): - return re.sub(r"^\s+", "", s, flags=re.MULTILINE) - - -def python_equals(testdata, text): - """ - Compare two bits of Python code, disregarding non-significant differences - like whitespace on blank lines and trailing space. - """ - d = open(tutils.test_data.path(testdata)).read() - assert clean_blanks(text).rstrip() == clean_blanks(d).rstrip() - - -@pytest.fixture -def get_request(): - return tflow.tflow( - req=tutils.treq( - method=b'GET', - content=b'', - path=b"/path?a=foo&a=bar&b=baz" - ) - ) - - -@pytest.fixture -def post_request(): - return tflow.tflow( - req=tutils.treq( - method=b'POST', - headers=(), - content=bytes(range(256)) - ) - ) - - -@pytest.fixture -def patch_request(): - return tflow.tflow( - req=tutils.treq(method=b'PATCH', path=b"/path?query=param") - ) - - -class TExport: - def test_get(self, get_request): - raise NotImplementedError() - - def test_post(self, post_request): - raise NotImplementedError() - - def test_patch(self, patch_request): - raise NotImplementedError() - - -class TestExportCurlCommand(TExport): - def test_get(self, get_request): - result = """curl -H 'header:qvalue' -H 'content-length:7' 'http://address:22/path?a=foo&a=bar&b=baz'""" - assert export.curl_command(get_request) == result - - def test_post(self, post_request): - result = "curl -X POST 'http://address:22/path' --data-binary '{}'".format( - str(bytes(range(256)))[2:-1] - ) - assert export.curl_command(post_request) == result - - def test_patch(self, patch_request): - result = """curl -H 'header:qvalue' -H 'content-length:7' -X PATCH 'http://address:22/path?query=param' --data-binary 'content'""" - assert export.curl_command(patch_request) == result - - -class TestExportPythonCode(TExport): - def test_get(self, get_request): - python_equals("mitmproxy/data/test_flow_export/python_get.py", - export.python_code(get_request)) - - def test_post(self, post_request): - python_equals("mitmproxy/data/test_flow_export/python_post.py", - export.python_code(post_request)) - - def test_post_json(self, post_request): - post_request.request.content = b'{"name": "example", "email": "example@example.com"}' - post_request.request.headers = Headers(content_type="application/json") - python_equals("mitmproxy/data/test_flow_export/python_post_json.py", - export.python_code(post_request)) - - def test_patch(self, patch_request): - python_equals("mitmproxy/data/test_flow_export/python_patch.py", - export.python_code(patch_request)) - - -class TestExportLocustCode(TExport): - def test_get(self, get_request): - python_equals("mitmproxy/data/test_flow_export/locust_get.py", - export.locust_code(get_request)) - - def test_post(self, post_request): - post_request.request.content = b'content' - post_request.request.headers.clear() - python_equals("mitmproxy/data/test_flow_export/locust_post.py", - export.locust_code(post_request)) - - def test_patch(self, patch_request): - python_equals("mitmproxy/data/test_flow_export/locust_patch.py", - export.locust_code(patch_request)) - - -class TestExportLocustTask(TExport): - def test_get(self, get_request): - python_equals("mitmproxy/data/test_flow_export/locust_task_get.py", - export.locust_task(get_request)) - - def test_post(self, post_request): - python_equals("mitmproxy/data/test_flow_export/locust_task_post.py", - export.locust_task(post_request)) - - def test_patch(self, patch_request): - python_equals("mitmproxy/data/test_flow_export/locust_task_patch.py", - export.locust_task(patch_request)) - - -class TestURL: - def test_url(self): - flow = tflow.tflow() - assert export.url(flow) == "http://address:22/path" diff --git a/test/mitmproxy/utils/test_typecheck.py b/test/mitmproxy/utils/test_typecheck.py index 17f70d37..fe33070e 100644 --- a/test/mitmproxy/utils/test_typecheck.py +++ b/test/mitmproxy/utils/test_typecheck.py @@ -88,25 +88,26 @@ def test_check_any(): typecheck.check_option_type("foo", None, typing.Any) -def test_check_command_return_type(): - assert(typecheck.check_command_return_type("foo", str)) - assert(typecheck.check_command_return_type(["foo"], typing.Sequence[str])) - assert(typecheck.check_command_return_type(None, None)) - assert(not typecheck.check_command_return_type(["foo"], typing.Sequence[int])) - assert(not typecheck.check_command_return_type("foo", typing.Sequence[int])) - assert(typecheck.check_command_return_type([["foo", b"bar"]], command.Cuts)) - assert(not typecheck.check_command_return_type(["foo", b"bar"], command.Cuts)) - assert(not typecheck.check_command_return_type([["foo", 22]], command.Cuts)) +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])) + assert(typecheck.check_command_type([["foo", b"bar"]], command.Cuts)) + assert(not typecheck.check_command_type(["foo", b"bar"], command.Cuts)) + assert(not typecheck.check_command_type([["foo", 22]], command.Cuts)) # Python 3.5 only defines __parameters__ m = mock.Mock() m.__str__ = lambda self: "typing.Sequence" m.__parameters__ = (int,) - typecheck.check_command_return_type([10], m) + 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_return_type([22], m) + assert not typecheck.check_command_type([22], m) |