/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
5590.1.2 by John Arbash Meinel
Change tuned_gzip.GzipFile to be deprecated
1
# Copyright (C) 2006, 2009, 2010, 2011 Canonical Ltd
1666.1.2 by Robert Collins
Fix race condition between end of stream and end of file with tuned_gzip.
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
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1666.1.2 by Robert Collins
Fix race condition between end of stream and end of file with tuned_gzip.
16
17
18
"""Tests for tuned_gzip."""
19
6621.4.1 by Martin
Remove deprecated tuned_gzip.GzipFile class
20
import gzip
6621.4.2 by Martin
Make tuned_gzip and tests Python 3 compatible
21
from io import BytesIO
1666.1.2 by Robert Collins
Fix race condition between end of stream and end of file with tuned_gzip.
22
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
23
from .. import (
5590.1.2 by John Arbash Meinel
Change tuned_gzip.GzipFile to be deprecated
24
    tuned_gzip,
25
    tests,
26
    )
1666.1.2 by Robert Collins
Fix race condition between end of stream and end of file with tuned_gzip.
27
28
5590.1.2 by John Arbash Meinel
Change tuned_gzip.GzipFile to be deprecated
29
class TestToGzip(tests.TestCase):
4398.8.2 by John Arbash Meinel
Add a chunks_to_gzip function.
30
31
    def assertToGzip(self, chunks):
6621.4.2 by Martin
Make tuned_gzip and tests Python 3 compatible
32
        raw_bytes = b''.join(chunks)
4398.8.2 by John Arbash Meinel
Add a chunks_to_gzip function.
33
        gzfromchunks = tuned_gzip.chunks_to_gzip(chunks)
6833.6.1 by Jelmer Vernooij
Remove bytes_to_gzip; work with chunks instead.
34
        decoded = gzip.GzipFile(fileobj=BytesIO(b''.join(gzfromchunks))).read()
6579.1.3 by Vincent Ladeuil
Test fix mistakenly forgotten in previous commits.
35
        lraw, ldecoded = len(raw_bytes), len(decoded)
36
        self.assertEqual(lraw, ldecoded,
37
                         'Expecting data length %d, got %d' % (lraw, ldecoded))
38
        self.assertEqual(raw_bytes, decoded)
4398.8.2 by John Arbash Meinel
Add a chunks_to_gzip function.
39
40
    def test_single_chunk(self):
6621.4.2 by Martin
Make tuned_gzip and tests Python 3 compatible
41
        self.assertToGzip([b'a modest chunk\nwith some various\nbits\n'])
4398.8.2 by John Arbash Meinel
Add a chunks_to_gzip function.
42
43
    def test_simple_text(self):
6621.4.2 by Martin
Make tuned_gzip and tests Python 3 compatible
44
        self.assertToGzip([b'some\n', b'strings\n', b'to\n', b'process\n'])
4398.8.2 by John Arbash Meinel
Add a chunks_to_gzip function.
45
46
    def test_large_chunks(self):
7143.15.2 by Jelmer Vernooij
Run autopep8.
47
        self.assertToGzip([b'a large string\n' * 1024])
48
        self.assertToGzip([b'a large string\n'] * 1024)
4398.8.2 by John Arbash Meinel
Add a chunks_to_gzip function.
49
50
    def test_enormous_chunks(self):
7143.15.2 by Jelmer Vernooij
Run autopep8.
51
        self.assertToGzip([b'a large string\n' * 1024 * 256])
52
        self.assertToGzip([b'a large string\n'] * 1024 * 256)