/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/tests/test_tuned_gzip.py

  • Committer: Jelmer Vernooij
  • Date: 2017-06-08 23:30:31 UTC
  • mto: This revision was merged to the branch mainline in revision 6690.
  • Revision ID: jelmer@jelmer.uk-20170608233031-3qavls2o7a1pqllj
Update imports.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2006, 2009, 2010, 2011 Canonical Ltd
 
2
#
 
3
# This program is free software; you can redistribute it and/or modify
 
4
# it under the terms of the GNU General Public License as published by
 
5
# the Free Software Foundation; either version 2 of the License, or
 
6
# (at your option) any later version.
 
7
#
 
8
# This program is distributed in the hope that it will be useful,
 
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
# GNU General Public License for more details.
 
12
#
 
13
# You should have received a copy of the GNU General Public License
 
14
# along with this program; if not, write to the Free Software
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
16
 
 
17
 
 
18
"""Tests for tuned_gzip."""
 
19
 
 
20
import gzip
 
21
from io import BytesIO
 
22
import zlib
 
23
 
 
24
from .. import (
 
25
    tuned_gzip,
 
26
    tests,
 
27
    )
 
28
 
 
29
 
 
30
class TestToGzip(tests.TestCase):
 
31
 
 
32
    def assertToGzip(self, chunks):
 
33
        raw_bytes = b''.join(chunks)
 
34
        gzfromchunks = tuned_gzip.chunks_to_gzip(chunks)
 
35
        gzfrombytes = tuned_gzip.bytes_to_gzip(raw_bytes)
 
36
        self.assertEqual(gzfrombytes, gzfromchunks)
 
37
        decoded = gzip.GzipFile(fileobj=BytesIO(gzfromchunks)).read()
 
38
        lraw, ldecoded = len(raw_bytes), len(decoded)
 
39
        self.assertEqual(lraw, ldecoded,
 
40
                         'Expecting data length %d, got %d' % (lraw, ldecoded))
 
41
        self.assertEqual(raw_bytes, decoded)
 
42
 
 
43
    def test_single_chunk(self):
 
44
        self.assertToGzip([b'a modest chunk\nwith some various\nbits\n'])
 
45
 
 
46
    def test_simple_text(self):
 
47
        self.assertToGzip([b'some\n', b'strings\n', b'to\n', b'process\n'])
 
48
 
 
49
    def test_large_chunks(self):
 
50
        self.assertToGzip([b'a large string\n'*1024])
 
51
        self.assertToGzip([b'a large string\n']*1024)
 
52
 
 
53
    def test_enormous_chunks(self):
 
54
        self.assertToGzip([b'a large string\n'*1024*256])
 
55
        self.assertToGzip([b'a large string\n']*1024*256)