aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_encoding.py
blob: ba0755d6660498f2fb1e45972c10cceca1fe5a84 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from libmproxy import encoding
import libpry

import cStringIO
import gzip, zlib

class udecode_identity(libpry.AutoTree):
    def test_decode(self):
        assert 'string' == encoding.decode('identity', 'string')

    def test_fallthrough(self):
        assert 'string' == encoding.decode('nonexistent encoding', 'string')

class udecode_gzip(libpry.AutoTree):
    def test_simple(self):
        s = cStringIO.StringIO()
        gf = gzip.GzipFile(fileobj=s, mode='wb')
        gf.write('string')
        gf.close()
        assert 'string' == encoding.decode('gzip', s.getvalue())

class udecode_deflate(libpry.AutoTree):
    def test_simple(self):
        assert 'string' == encoding.decode('deflate', zlib.compress('string'))
        assert 'string' == encoding.decode('deflate', zlib.compress('string')[2:-4])

tests = [
    udecode_identity(),
    udecode_gzip(),
    udecode_deflate()
]