PageRenderTime 12ms CodeModel.GetById 2ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/web/test_utils.py

https://bitbucket.org/prologic/circuits/
Python | 25 lines | 18 code | 6 blank | 1 comment | 0 complexity | 4c48b02667c89e2ce7c4f7e74fbbe717 MD5 | raw file
 1#!/usr/bin/env python
 2
 3from io import BytesIO
 4try:
 5    from gzip import decompress
 6except ImportError:
 7    import zlib
 8    decompress = zlib.decompressobj(16+zlib.MAX_WBITS).decompress  # NOQA
 9
10from circuits.web.utils import compress
11from circuits.web.utils import get_ranges
12
13
14def test_ranges():
15    assert get_ranges("bytes=3-6", 8) == [(3, 7)]
16    assert get_ranges("bytes=2-4,-1", 8) == [(2, 5), (7, 8)]
17
18
19def test_gzip():
20    s = b"Hello World!"
21    contents = BytesIO(s)
22    compressed = b"".join(compress(contents, 1))
23    uncompressed = decompress(compressed)
24    assert uncompressed == s
25    contents.close()