aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/mitmproxy/utils/__init__.py0
-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.py48
-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