/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
4763.2.4 by John Arbash Meinel
merge bzr.2.1 in preparation for NEWS entry.
1
# Copyright (C) 2008, 2009, 2010 Canonical Ltd
3890.2.8 by John Arbash Meinel
Move everything into properly parameterized tests.
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
3890.2.8 by John Arbash Meinel
Move everything into properly parameterized tests.
16
#
17
18
"""Tests for chunks_to_lines."""
19
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
20
from .. import tests
21
from . import (
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
22
    features,
23
    )
3890.2.8 by John Arbash Meinel
Move everything into properly parameterized tests.
24
25
6625.1.5 by Martin
Drop custom load_tests implementation and use unittest signature
26
def load_tests(loader, standard_tests, pattern):
4913.3.5 by John Arbash Meinel
Handle the fact that osutils requires the feature to be available.
27
    suite, _ = tests.permute_tests_for_extension(
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
28
        standard_tests, loader, 'breezy._chunks_to_lines_py',
29
        'breezy._chunks_to_lines_pyx')
4913.3.1 by John Arbash Meinel
Implement a permute_for_extension helper.
30
    return suite
3890.2.8 by John Arbash Meinel
Move everything into properly parameterized tests.
31
7143.15.2 by Jelmer Vernooij
Run autopep8.
32
4913.3.5 by John Arbash Meinel
Handle the fact that osutils requires the feature to be available.
33
# test_osutils depends on this feature being around. We can't just use the one
34
# generated by load_tests, because if we only load osutils but not this module,
35
# then that code never gets run
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
36
compiled_chunkstolines_feature = features.ModuleAvailableFeature(
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
37
    'breezy._chunks_to_lines_pyx')
4913.3.5 by John Arbash Meinel
Handle the fact that osutils requires the feature to be available.
38
3890.2.8 by John Arbash Meinel
Move everything into properly parameterized tests.
39
40
class TestChunksToLines(tests.TestCase):
41
7143.15.2 by Jelmer Vernooij
Run autopep8.
42
    module = None  # Filled in by test parameterization
3890.2.8 by John Arbash Meinel
Move everything into properly parameterized tests.
43
44
    def assertChunksToLines(self, lines, chunks, alreadly_lines=False):
45
        result = self.module.chunks_to_lines(chunks)
46
        self.assertEqual(lines, result)
47
        if alreadly_lines:
48
            self.assertIs(chunks, result)
49
50
    def test_fulltext_chunk_to_lines(self):
6684.1.2 by Martin
Make _chunks_to_lines pass for Python 3
51
        self.assertChunksToLines(
52
            [b'foo\n', b'bar\r\n', b'ba\rz\n'],
53
            [b'foo\nbar\r\nba\rz\n'])
54
        self.assertChunksToLines(
55
            [b'foobarbaz\n'], [b'foobarbaz\n'], alreadly_lines=True)
56
        self.assertChunksToLines(
57
            [b'foo\n', b'bar\n', b'\n', b'baz\n', b'\n', b'\n'],
58
            [b'foo\nbar\n\nbaz\n\n\n'])
59
        self.assertChunksToLines(
60
            [b'foobarbaz'], [b'foobarbaz'], alreadly_lines=True)
61
        self.assertChunksToLines([b'foobarbaz'], [b'foo', b'bar', b'baz'])
3890.2.17 by John Arbash Meinel
Add a few more corner cases, some suggested by Robert.
62
63
    def test_newlines(self):
6684.1.2 by Martin
Make _chunks_to_lines pass for Python 3
64
        self.assertChunksToLines([b'\n'], [b'\n'], alreadly_lines=True)
65
        self.assertChunksToLines([b'\n'], [b'', b'\n', b''])
66
        self.assertChunksToLines([b'\n'], [b'\n', b''])
67
        self.assertChunksToLines([b'\n'], [b'', b'\n'])
68
        self.assertChunksToLines([b'\n', b'\n', b'\n'], [b'\n\n\n'])
69
        self.assertChunksToLines([b'\n', b'\n', b'\n'], [b'\n', b'\n', b'\n'],
3890.2.17 by John Arbash Meinel
Add a few more corner cases, some suggested by Robert.
70
                                 alreadly_lines=True)
3890.2.8 by John Arbash Meinel
Move everything into properly parameterized tests.
71
72
    def test_lines_to_lines(self):
6684.1.2 by Martin
Make _chunks_to_lines pass for Python 3
73
        self.assertChunksToLines([b'foo\n', b'bar\r\n', b'ba\rz\n'],
74
                                 [b'foo\n', b'bar\r\n', b'ba\rz\n'],
3890.2.8 by John Arbash Meinel
Move everything into properly parameterized tests.
75
                                 alreadly_lines=True)
76
77
    def test_no_final_newline(self):
6684.1.2 by Martin
Make _chunks_to_lines pass for Python 3
78
        self.assertChunksToLines([b'foo\n', b'bar\r\n', b'ba\rz'],
79
                                 [b'foo\nbar\r\nba\rz'])
80
        self.assertChunksToLines([b'foo\n', b'bar\r\n', b'ba\rz'],
81
                                 [b'foo\n', b'bar\r\n', b'ba\rz'],
3890.2.8 by John Arbash Meinel
Move everything into properly parameterized tests.
82
                                 alreadly_lines=True)
6684.1.2 by Martin
Make _chunks_to_lines pass for Python 3
83
        self.assertChunksToLines((b'foo\n', b'bar\r\n', b'ba\rz'),
84
                                 (b'foo\n', b'bar\r\n', b'ba\rz'),
3890.2.8 by John Arbash Meinel
Move everything into properly parameterized tests.
85
                                 alreadly_lines=True)
86
        self.assertChunksToLines([], [], alreadly_lines=True)
6684.1.2 by Martin
Make _chunks_to_lines pass for Python 3
87
        self.assertChunksToLines([b'foobarbaz'], [b'foobarbaz'],
3890.2.8 by John Arbash Meinel
Move everything into properly parameterized tests.
88
                                 alreadly_lines=True)
6684.1.2 by Martin
Make _chunks_to_lines pass for Python 3
89
        self.assertChunksToLines([], [b''])
3890.2.8 by John Arbash Meinel
Move everything into properly parameterized tests.
90
91
    def test_mixed(self):
6684.1.2 by Martin
Make _chunks_to_lines pass for Python 3
92
        self.assertChunksToLines([b'foo\n', b'bar\r\n', b'ba\rz'],
93
                                 [b'foo\n', b'bar\r\nba\r', b'z'])
94
        self.assertChunksToLines([b'foo\n', b'bar\r\n', b'ba\rz'],
95
                                 [b'foo\nb', b'a', b'r\r\nba\r', b'z'])
96
        self.assertChunksToLines([b'foo\n', b'bar\r\n', b'ba\rz'],
97
                                 [b'foo\nbar\r\nba', b'\r', b'z'])
3890.2.8 by John Arbash Meinel
Move everything into properly parameterized tests.
98
6684.1.2 by Martin
Make _chunks_to_lines pass for Python 3
99
        self.assertChunksToLines([b'foo\n', b'bar\r\n', b'ba\rz'],
100
                                 [b'foo\n', b'', b'bar\r\nba', b'\r', b'z'])
101
        self.assertChunksToLines([b'foo\n', b'bar\r\n', b'ba\rz\n'],
102
                                 [b'foo\n', b'bar\r\n', b'ba\rz\n', b''])
103
        self.assertChunksToLines([b'foo\n', b'bar\r\n', b'ba\rz\n'],
104
                                 [b'foo\n', b'bar', b'\r\n', b'ba\rz\n'])
3890.2.8 by John Arbash Meinel
Move everything into properly parameterized tests.
105
106
    def test_not_lines(self):
107
        # We should raise a TypeError, not crash
108
        self.assertRaises(TypeError, self.module.chunks_to_lines,
109
                          object())
110
        self.assertRaises(TypeError, self.module.chunks_to_lines,
111
                          [object()])
112
        self.assertRaises(TypeError, self.module.chunks_to_lines,
6684.1.2 by Martin
Make _chunks_to_lines pass for Python 3
113
                          [b'foo', object()])