/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# Copyright (C) 2006, 2009, 2010, 2011 Canonical Ltd
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA


"""Tests for tuned_gzip."""

import gzip
from io import BytesIO
import zlib

from .. import (
    tuned_gzip,
    tests,
    )


class TestToGzip(tests.TestCase):

    def assertToGzip(self, chunks):
        raw_bytes = b''.join(chunks)
        gzfromchunks = tuned_gzip.chunks_to_gzip(chunks)
        decoded = gzip.GzipFile(fileobj=BytesIO(b''.join(gzfromchunks))).read()
        lraw, ldecoded = len(raw_bytes), len(decoded)
        self.assertEqual(lraw, ldecoded,
                         'Expecting data length %d, got %d' % (lraw, ldecoded))
        self.assertEqual(raw_bytes, decoded)

    def test_single_chunk(self):
        self.assertToGzip([b'a modest chunk\nwith some various\nbits\n'])

    def test_simple_text(self):
        self.assertToGzip([b'some\n', b'strings\n', b'to\n', b'process\n'])

    def test_large_chunks(self):
        self.assertToGzip([b'a large string\n'*1024])
        self.assertToGzip([b'a large string\n']*1024)

    def test_enormous_chunks(self):
        self.assertToGzip([b'a large string\n'*1024*256])
        self.assertToGzip([b'a large string\n']*1024*256)