2016-07-02 08:51:47 +00:00
|
|
|
from netlib import encoding, tutils
|
2015-08-01 12:53:13 +00:00
|
|
|
|
2015-08-10 18:44:36 +00:00
|
|
|
|
2015-08-01 12:53:13 +00:00
|
|
|
def test_identity():
|
2016-07-02 08:51:47 +00:00
|
|
|
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")
|
2015-08-01 12:53:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_gzip():
|
2015-09-15 17:12:15 +00:00
|
|
|
assert b"string" == encoding.decode(
|
2015-08-01 12:53:13 +00:00
|
|
|
encoding.encode(
|
2016-07-02 08:51:47 +00:00
|
|
|
b"string",
|
|
|
|
"gzip"
|
|
|
|
),
|
|
|
|
"gzip"
|
2015-09-15 17:12:15 +00:00
|
|
|
)
|
2016-07-02 08:51:47 +00:00
|
|
|
with tutils.raises(ValueError):
|
|
|
|
encoding.decode(b"bogus", "gzip")
|
2015-08-01 12:53:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_deflate():
|
2015-09-15 17:12:15 +00:00
|
|
|
assert b"string" == encoding.decode(
|
2015-08-01 12:53:13 +00:00
|
|
|
encoding.encode(
|
2016-07-02 08:51:47 +00:00
|
|
|
b"string",
|
|
|
|
"deflate"
|
|
|
|
),
|
|
|
|
"deflate"
|
2015-09-15 17:12:15 +00:00
|
|
|
)
|
|
|
|
assert b"string" == encoding.decode(
|
2015-08-01 12:53:13 +00:00
|
|
|
encoding.encode(
|
2016-07-02 08:51:47 +00:00
|
|
|
b"string",
|
|
|
|
"deflate"
|
|
|
|
)[2:-4],
|
|
|
|
"deflate"
|
2015-09-15 17:12:15 +00:00
|
|
|
)
|
2016-07-02 08:51:47 +00:00
|
|
|
with tutils.raises(ValueError):
|
|
|
|
encoding.decode(b"bogus", "deflate")
|