mitmproxy/test/netlib/test_encoding.py

40 lines
918 B
Python
Raw Normal View History

from netlib import encoding, tutils
2015-08-10 18:44:36 +00:00
def test_identity():
assert b"string" == encoding.decode(b"string", "identity")
assert b"string" == encoding.encode(b"string", "identity")
with tutils.raises(ValueError):
encoding.encode(b"string", "nonexistent encoding")
def test_gzip():
2015-09-15 17:12:15 +00:00
assert b"string" == encoding.decode(
encoding.encode(
b"string",
"gzip"
),
"gzip"
2015-09-15 17:12:15 +00:00
)
with tutils.raises(ValueError):
encoding.decode(b"bogus", "gzip")
def test_deflate():
2015-09-15 17:12:15 +00:00
assert b"string" == encoding.decode(
encoding.encode(
b"string",
"deflate"
),
"deflate"
2015-09-15 17:12:15 +00:00
)
assert b"string" == encoding.decode(
encoding.encode(
b"string",
"deflate"
)[2:-4],
"deflate"
2015-09-15 17:12:15 +00:00
)
with tutils.raises(ValueError):
encoding.decode(b"bogus", "deflate")