aboutsummaryrefslogtreecommitdiffstats
path: root/test/netlib
diff options
context:
space:
mode:
authorMaximilian Hils <git@maximilianhils.com>2016-07-07 18:02:59 -0700
committerMaximilian Hils <git@maximilianhils.com>2016-07-07 18:02:59 -0700
commit00dce240150595e41719e512f1b156103c3c9c31 (patch)
tree0e2fcbcd02270386e067ab671c377e2d8e8a9628 /test/netlib
parent76473d44e035306503a426ebcd55967798f243a1 (diff)
downloadmitmproxy-00dce240150595e41719e512f1b156103c3c9c31.tar.gz
mitmproxy-00dce240150595e41719e512f1b156103c3c9c31.tar.bz2
mitmproxy-00dce240150595e41719e512f1b156103c3c9c31.zip
tests++
Diffstat (limited to 'test/netlib')
-rw-r--r--test/netlib/test_strutils.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/test/netlib/test_strutils.py b/test/netlib/test_strutils.py
index f88e33ed..68bfdb94 100644
--- a/test/netlib/test_strutils.py
+++ b/test/netlib/test_strutils.py
@@ -3,6 +3,13 @@ import six
from netlib import strutils, tutils
+def test_always_bytes():
+ assert strutils.always_bytes(bytes(bytearray(range(256)))) == bytes(bytearray(range(256)))
+ assert strutils.always_bytes("foo") == b"foo"
+ with tutils.raises(ValueError):
+ strutils.always_bytes(u"\u2605", "ascii")
+
+
def test_native():
with tutils.raises(TypeError):
strutils.native(42)
@@ -31,6 +38,9 @@ def test_escape_control_characters():
u'=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~.'
)
+ with tutils.raises(ValueError):
+ strutils.escape_control_characters(b"foo")
+
def test_bytes_to_escaped_str():
assert strutils.bytes_to_escaped_str(b"foo") == "foo"
@@ -68,6 +78,11 @@ def test_escaped_str_to_bytes():
strutils.escaped_str_to_bytes(b"very byte")
+def test_is_mostly_bin():
+ assert not strutils.is_mostly_bin(b"foo\xFF")
+ assert strutils.is_mostly_bin(b"foo" + b"\xFF" * 10)
+
+
def test_is_xml():
assert not strutils.is_xml(b"foo")
assert strutils.is_xml(b"<foo")