/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 bzrlib/tests/test__chunks_to_lines.py

  • Committer: Andrew Bennetts
  • Date: 2010-04-13 04:33:55 UTC
  • mfrom: (5147 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5149.
  • Revision ID: andrew.bennetts@canonical.com-20100413043355-lg3id0uwtju0k3zs
MergeĀ lp:bzr.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2008, 2009, 2010 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 chunks_to_lines."""
 
19
 
 
20
from bzrlib import tests
 
21
 
 
22
 
 
23
def load_tests(standard_tests, module, loader):
 
24
    suite, _ = tests.permute_tests_for_extension(
 
25
        standard_tests, loader, 'bzrlib._chunks_to_lines_py',
 
26
        'bzrlib._chunks_to_lines_pyx')
 
27
    return suite
 
28
 
 
29
# test_osutils depends on this feature being around. We can't just use the one
 
30
# generated by load_tests, because if we only load osutils but not this module,
 
31
# then that code never gets run
 
32
compiled_chunkstolines_feature = tests.ModuleAvailableFeature(
 
33
                                    'bzrlib._chunks_to_lines_pyx')
 
34
 
 
35
 
 
36
class TestChunksToLines(tests.TestCase):
 
37
 
 
38
    module = None # Filled in by test parameterization
 
39
 
 
40
    def assertChunksToLines(self, lines, chunks, alreadly_lines=False):
 
41
        result = self.module.chunks_to_lines(chunks)
 
42
        self.assertEqual(lines, result)
 
43
        if alreadly_lines:
 
44
            self.assertIs(chunks, result)
 
45
 
 
46
    def test_fulltext_chunk_to_lines(self):
 
47
        self.assertChunksToLines(['foo\n', 'bar\r\n', 'ba\rz\n'],
 
48
                                 ['foo\nbar\r\nba\rz\n'])
 
49
        self.assertChunksToLines(['foobarbaz\n'], ['foobarbaz\n'],
 
50
                                 alreadly_lines=True)
 
51
        self.assertChunksToLines(['foo\n', 'bar\n', '\n', 'baz\n', '\n', '\n'],
 
52
                                 ['foo\nbar\n\nbaz\n\n\n'])
 
53
        self.assertChunksToLines(['foobarbaz'], ['foobarbaz'],
 
54
                                 alreadly_lines=True)
 
55
        self.assertChunksToLines(['foobarbaz'], ['foo', 'bar', 'baz'])
 
56
 
 
57
    def test_newlines(self):
 
58
        self.assertChunksToLines(['\n'], ['\n'], alreadly_lines=True)
 
59
        self.assertChunksToLines(['\n'], ['', '\n', ''])
 
60
        self.assertChunksToLines(['\n'], ['\n', ''])
 
61
        self.assertChunksToLines(['\n'], ['', '\n'])
 
62
        self.assertChunksToLines(['\n', '\n', '\n'], ['\n\n\n'])
 
63
        self.assertChunksToLines(['\n', '\n', '\n'], ['\n', '\n', '\n'],
 
64
                                 alreadly_lines=True)
 
65
 
 
66
    def test_lines_to_lines(self):
 
67
        self.assertChunksToLines(['foo\n', 'bar\r\n', 'ba\rz\n'],
 
68
                                 ['foo\n', 'bar\r\n', 'ba\rz\n'],
 
69
                                 alreadly_lines=True)
 
70
 
 
71
    def test_no_final_newline(self):
 
72
        self.assertChunksToLines(['foo\n', 'bar\r\n', 'ba\rz'],
 
73
                                 ['foo\nbar\r\nba\rz'])
 
74
        self.assertChunksToLines(['foo\n', 'bar\r\n', 'ba\rz'],
 
75
                                 ['foo\n', 'bar\r\n', 'ba\rz'],
 
76
                                 alreadly_lines=True)
 
77
        self.assertChunksToLines(('foo\n', 'bar\r\n', 'ba\rz'),
 
78
                                 ('foo\n', 'bar\r\n', 'ba\rz'),
 
79
                                 alreadly_lines=True)
 
80
        self.assertChunksToLines([], [], alreadly_lines=True)
 
81
        self.assertChunksToLines(['foobarbaz'], ['foobarbaz'],
 
82
                                 alreadly_lines=True)
 
83
        self.assertChunksToLines([], [''])
 
84
 
 
85
    def test_mixed(self):
 
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'],
 
89
                                 ['foo\nb', 'a', 'r\r\nba\r', 'z'])
 
90
        self.assertChunksToLines(['foo\n', 'bar\r\n', 'ba\rz'],
 
91
                                 ['foo\nbar\r\nba', '\r', 'z'])
 
92
 
 
93
        self.assertChunksToLines(['foo\n', 'bar\r\n', 'ba\rz'],
 
94
                                 ['foo\n', '', 'bar\r\nba', '\r', 'z'])
 
95
        self.assertChunksToLines(['foo\n', 'bar\r\n', 'ba\rz\n'],
 
96
                                 ['foo\n', 'bar\r\n', 'ba\rz\n', ''])
 
97
        self.assertChunksToLines(['foo\n', 'bar\r\n', 'ba\rz\n'],
 
98
                                 ['foo\n', 'bar', '\r\n', 'ba\rz\n'])
 
99
 
 
100
    def test_not_lines(self):
 
101
        # We should raise a TypeError, not crash
 
102
        self.assertRaises(TypeError, self.module.chunks_to_lines,
 
103
                          object())
 
104
        self.assertRaises(TypeError, self.module.chunks_to_lines,
 
105
                          [object()])
 
106
        self.assertRaises(TypeError, self.module.chunks_to_lines,
 
107
                          ['foo', object()])