diff options
author | Maximilian Hils <git@maximilianhils.com> | 2016-10-25 20:45:48 -0700 |
---|---|---|
committer | Maximilian Hils <git@maximilianhils.com> | 2016-10-25 20:45:48 -0700 |
commit | b1bdae3d1cbcf7c4c427cac5163faf75150f4cff (patch) | |
tree | 77fea1047afa278a369d885266e79a9201f0aec0 /test | |
parent | 917c701562794b59b7f4015e9165a7ef7ed50f79 (diff) | |
download | mitmproxy-b1bdae3d1cbcf7c4c427cac5163faf75150f4cff.tar.gz mitmproxy-b1bdae3d1cbcf7c4c427cac5163faf75150f4cff.tar.bz2 mitmproxy-b1bdae3d1cbcf7c4c427cac5163faf75150f4cff.zip |
typecheck options, fix current inconsistencies
Diffstat (limited to 'test')
-rw-r--r-- | test/mitmproxy/utils/__init__.py | 0 | ||||
-rw-r--r-- | test/mitmproxy/utils/test_data.py (renamed from test/mitmproxy/test_utils_data.py) | 5 | ||||
-rw-r--r-- | test/mitmproxy/utils/test_debug.py (renamed from test/mitmproxy/test_utils_debug.py) | 0 | ||||
-rw-r--r-- | test/mitmproxy/utils/test_human.py (renamed from test/mitmproxy/test_utils_human.py) | 0 | ||||
-rw-r--r-- | test/mitmproxy/utils/test_strutils.py (renamed from test/mitmproxy/test_utils_strutils.py) | 0 | ||||
-rw-r--r-- | test/mitmproxy/utils/test_typecheck.py | 48 | ||||
-rw-r--r-- | test/mitmproxy/utils/test_version_check.py (renamed from test/mitmproxy/test_utils_version_check.py) | 0 |
7 files changed, 51 insertions, 2 deletions
diff --git a/test/mitmproxy/utils/__init__.py b/test/mitmproxy/utils/__init__.py new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/test/mitmproxy/utils/__init__.py diff --git a/test/mitmproxy/test_utils_data.py b/test/mitmproxy/utils/test_data.py index c6e4420e..f40fc866 100644 --- a/test/mitmproxy/test_utils_data.py +++ b/test/mitmproxy/utils/test_data.py @@ -1,7 +1,8 @@ +import pytest from mitmproxy.utils import data -from . import tutils def test_pkg_data(): assert data.pkg_data.path("tools/console") - tutils.raises("does not exist", data.pkg_data.path, "nonexistent") + with pytest.raises(ValueError): + data.pkg_data.path("nonexistent") diff --git a/test/mitmproxy/test_utils_debug.py b/test/mitmproxy/utils/test_debug.py index 9acf8192..9acf8192 100644 --- a/test/mitmproxy/test_utils_debug.py +++ b/test/mitmproxy/utils/test_debug.py diff --git a/test/mitmproxy/test_utils_human.py b/test/mitmproxy/utils/test_human.py index 443c8f66..443c8f66 100644 --- a/test/mitmproxy/test_utils_human.py +++ b/test/mitmproxy/utils/test_human.py diff --git a/test/mitmproxy/test_utils_strutils.py b/test/mitmproxy/utils/test_strutils.py index 84281c6b..84281c6b 100644 --- a/test/mitmproxy/test_utils_strutils.py +++ b/test/mitmproxy/utils/test_strutils.py diff --git a/test/mitmproxy/utils/test_typecheck.py b/test/mitmproxy/utils/test_typecheck.py new file mode 100644 index 00000000..85684df9 --- /dev/null +++ b/test/mitmproxy/utils/test_typecheck.py @@ -0,0 +1,48 @@ +import typing + +import pytest +from mitmproxy.utils import typecheck + + +class TBase: + def __init__(self, bar: int): + pass + + +class T(TBase): + def __init__(self, foo: str): + super(T, self).__init__(42) + + +def test_get_arg_type_from_constructor_annotation(): + assert typecheck.get_arg_type_from_constructor_annotation(T, "foo") == str + assert typecheck.get_arg_type_from_constructor_annotation(T, "bar") == int + assert not typecheck.get_arg_type_from_constructor_annotation(T, "baz") + + +def test_check_type(): + typecheck.check_type("foo", 42, int) + with pytest.raises(TypeError): + typecheck.check_type("foo", 42, str) + with pytest.raises(TypeError): + typecheck.check_type("foo", None, str) + + +def test_check_union(): + typecheck.check_type("foo", 42, typing.Union[int, str]) + typecheck.check_type("foo", "42", typing.Union[int, str]) + with pytest.raises(TypeError): + typecheck.check_type("foo", [], typing.Union[int, str]) + + +def test_check_tuple(): + with pytest.raises(TypeError): + typecheck.check_type("foo", None, typing.Tuple[int, str]) + with pytest.raises(TypeError): + typecheck.check_type("foo", (), typing.Tuple[int, str]) + with pytest.raises(TypeError): + typecheck.check_type("foo", (42, 42), typing.Tuple[int, str]) + with pytest.raises(TypeError): + typecheck.check_type("foo", ("42", 42), typing.Tuple[int, str]) + + typecheck.check_type("foo", (42, "42"), typing.Tuple[int, str]) diff --git a/test/mitmproxy/test_utils_version_check.py b/test/mitmproxy/utils/test_version_check.py index 5c8d8c8c..5c8d8c8c 100644 --- a/test/mitmproxy/test_utils_version_check.py +++ b/test/mitmproxy/utils/test_version_check.py |