/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
3890.2.8 by John Arbash Meinel
Move everything into properly parameterized tests.
1
# Copyright (C) 2008 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
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
20
from bzrlib import tests
21
22
23
def load_tests(standard_tests, module, loader):
4913.3.1 by John Arbash Meinel
Implement a permute_for_extension helper.
24
    suite, _ = tests.permute_tests_for_extension(standard_tests, loader,
25
        'bzrlib._chunks_to_lines_py', 'bzrlib._chunks_to_lines_pyx')
26
    return suite
3890.2.8 by John Arbash Meinel
Move everything into properly parameterized tests.
27
28
29
class TestChunksToLines(tests.TestCase):
30
31
    module = None # Filled in by test parameterization
32
33
    def assertChunksToLines(self, lines, chunks, alreadly_lines=False):
34
        result = self.module.chunks_to_lines(chunks)
35
        self.assertEqual(lines, result)
36
        if alreadly_lines:
37
            self.assertIs(chunks, result)
38
39
    def test_fulltext_chunk_to_lines(self):
40
        self.assertChunksToLines(['foo\n', 'bar\r\n', 'ba\rz\n'],
41
                                 ['foo\nbar\r\nba\rz\n'])
42
        self.assertChunksToLines(['foobarbaz\n'], ['foobarbaz\n'],
43
                                 alreadly_lines=True)
3890.2.15 by John Arbash Meinel
Update to do a single iteration over the chunks.
44
        self.assertChunksToLines(['foo\n', 'bar\n', '\n', 'baz\n', '\n', '\n'],
45
                                 ['foo\nbar\n\nbaz\n\n\n'])
3890.2.17 by John Arbash Meinel
Add a few more corner cases, some suggested by Robert.
46
        self.assertChunksToLines(['foobarbaz'], ['foobarbaz'],
47
                                 alreadly_lines=True)
48
        self.assertChunksToLines(['foobarbaz'], ['foo', 'bar', 'baz'])
49
50
    def test_newlines(self):
51
        self.assertChunksToLines(['\n'], ['\n'], alreadly_lines=True)
52
        self.assertChunksToLines(['\n'], ['', '\n', ''])
53
        self.assertChunksToLines(['\n'], ['\n', ''])
54
        self.assertChunksToLines(['\n'], ['', '\n'])
55
        self.assertChunksToLines(['\n', '\n', '\n'], ['\n\n\n'])
56
        self.assertChunksToLines(['\n', '\n', '\n'], ['\n', '\n', '\n'],
57
                                 alreadly_lines=True)
3890.2.8 by John Arbash Meinel
Move everything into properly parameterized tests.
58
59
    def test_lines_to_lines(self):
60
        self.assertChunksToLines(['foo\n', 'bar\r\n', 'ba\rz\n'],
61
                                 ['foo\n', 'bar\r\n', 'ba\rz\n'],
62
                                 alreadly_lines=True)
63
64
    def test_no_final_newline(self):
65
        self.assertChunksToLines(['foo\n', 'bar\r\n', 'ba\rz'],
66
                                 ['foo\nbar\r\nba\rz'])
67
        self.assertChunksToLines(['foo\n', 'bar\r\n', 'ba\rz'],
68
                                 ['foo\n', 'bar\r\n', 'ba\rz'],
69
                                 alreadly_lines=True)
70
        self.assertChunksToLines(('foo\n', 'bar\r\n', 'ba\rz'),
71
                                 ('foo\n', 'bar\r\n', 'ba\rz'),
72
                                 alreadly_lines=True)
73
        self.assertChunksToLines([], [], alreadly_lines=True)
74
        self.assertChunksToLines(['foobarbaz'], ['foobarbaz'],
75
                                 alreadly_lines=True)
76
        self.assertChunksToLines([], [''])
77
78
    def test_mixed(self):
79
        self.assertChunksToLines(['foo\n', 'bar\r\n', 'ba\rz'],
80
                                 ['foo\n', 'bar\r\nba\r', 'z'])
81
        self.assertChunksToLines(['foo\n', 'bar\r\n', 'ba\rz'],
82
                                 ['foo\nb', 'a', 'r\r\nba\r', 'z'])
83
        self.assertChunksToLines(['foo\n', 'bar\r\n', 'ba\rz'],
84
                                 ['foo\nbar\r\nba', '\r', 'z'])
85
86
        self.assertChunksToLines(['foo\n', 'bar\r\n', 'ba\rz'],
87
                                 ['foo\n', '', 'bar\r\nba', '\r', 'z'])
88
        self.assertChunksToLines(['foo\n', 'bar\r\n', 'ba\rz\n'],
89
                                 ['foo\n', 'bar\r\n', 'ba\rz\n', ''])
3890.2.11 by John Arbash Meinel
A bit more tweaking of the pyrex version. Shave off another 10% by
90
        self.assertChunksToLines(['foo\n', 'bar\r\n', 'ba\rz\n'],
91
                                 ['foo\n', 'bar', '\r\n', 'ba\rz\n'])
3890.2.8 by John Arbash Meinel
Move everything into properly parameterized tests.
92
93
    def test_not_lines(self):
94
        # We should raise a TypeError, not crash
95
        self.assertRaises(TypeError, self.module.chunks_to_lines,
96
                          object())
97
        self.assertRaises(TypeError, self.module.chunks_to_lines,
98
                          [object()])
99
        self.assertRaises(TypeError, self.module.chunks_to_lines,
100
                          ['foo', object()])