diff options
| author | Maximilian Hils <git@maximilianhils.com> | 2016-06-07 00:23:07 -0700 | 
|---|---|---|
| committer | Maximilian Hils <git@maximilianhils.com> | 2016-06-07 01:03:08 -0700 | 
| commit | c98c83190baa078539b79136c2de348985cc61cc (patch) | |
| tree | 7171738e02e1fe8bcc1bdef99c7fa33c33f0024c /test | |
| parent | 637a3be937f382ec45829a1084b2b56d1f6a55e9 (diff) | |
| download | mitmproxy-c98c83190baa078539b79136c2de348985cc61cc.tar.gz mitmproxy-c98c83190baa078539b79136c2de348985cc61cc.tar.bz2 mitmproxy-c98c83190baa078539b79136c2de348985cc61cc.zip  | |
tests++
Diffstat (limited to 'test')
| -rw-r--r-- | test/netlib/test_strutils.py | 24 | 
1 files changed, 23 insertions, 1 deletions
diff --git a/test/netlib/test_strutils.py b/test/netlib/test_strutils.py index 734265c4..84a0dded 100644 --- a/test/netlib/test_strutils.py +++ b/test/netlib/test_strutils.py @@ -1,6 +1,18 @@  # coding=utf-8 +import six -from netlib import strutils +from netlib import strutils, tutils + + +def test_native(): +    with tutils.raises(TypeError): +        strutils.native(42) +    if six.PY2: +        assert strutils.native(u"foo") == b"foo" +        assert strutils.native(b"foo") == b"foo" +    else: +        assert strutils.native(u"foo") == u"foo" +        assert strutils.native(b"foo") == u"foo"  def test_clean_bin(): @@ -29,6 +41,9 @@ def test_bytes_to_escaped_str():      assert strutils.bytes_to_escaped_str(b"'") == r"\'"      assert strutils.bytes_to_escaped_str(b'"') == r'"' +    with tutils.raises(ValueError): +        strutils.bytes_to_escaped_str(u"such unicode") +  def test_escaped_str_to_bytes():      assert strutils.escaped_str_to_bytes("foo") == b"foo" @@ -39,6 +54,13 @@ def test_escaped_str_to_bytes():      assert strutils.escaped_str_to_bytes(u"&!?=\\\\)") == br"&!?=\)"      assert strutils.escaped_str_to_bytes(u"ΓΌ") == b'\xc3\xbc' +    if six.PY2: +        with tutils.raises(ValueError): +            strutils.escaped_str_to_bytes(42) +    else: +        with tutils.raises(ValueError): +            strutils.escaped_str_to_bytes(b"very byte") +  def test_isBin():      assert not strutils.isBin("testing\n\r")  | 
