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 |
|
|
4913.3.5
by John Arbash Meinel
Handle the fact that osutils requires the feature to be available. |
32 |
# test_osutils depends on this feature being around. We can't just use the one
|
33 |
# generated by load_tests, because if we only load osutils but not this module,
|
|
34 |
# then that code never gets run
|
|
|
5967.12.1
by Martin Pool
Move all test features into bzrlib.tests.features |
35 |
compiled_chunkstolines_feature = features.ModuleAvailableFeature( |
|
6622.1.34
by Jelmer Vernooij
Rename brzlib => breezy. |
36 |
'breezy._chunks_to_lines_pyx') |
|
4913.3.5
by John Arbash Meinel
Handle the fact that osutils requires the feature to be available. |
37 |
|
|
3890.2.8
by John Arbash Meinel
Move everything into properly parameterized tests. |
38 |
|
39 |
class TestChunksToLines(tests.TestCase): |
|
40 |
||
41 |
module = None # Filled in by test parameterization |
|
42 |
||
43 |
def assertChunksToLines(self, lines, chunks, alreadly_lines=False): |
|
44 |
result = self.module.chunks_to_lines(chunks) |
|
45 |
self.assertEqual(lines, result) |
|
46 |
if alreadly_lines: |
|
47 |
self.assertIs(chunks, result) |
|
48 |
||
49 |
def test_fulltext_chunk_to_lines(self): |
|
|
6684.1.2
by Martin
Make _chunks_to_lines pass for Python 3 |
50 |
self.assertChunksToLines( |
51 |
[b'foo\n', b'bar\r\n', b'ba\rz\n'], |
|
52 |
[b'foo\nbar\r\nba\rz\n']) |
|
53 |
self.assertChunksToLines( |
|
54 |
[b'foobarbaz\n'], [b'foobarbaz\n'], alreadly_lines=True) |
|
55 |
self.assertChunksToLines( |
|
56 |
[b'foo\n', b'bar\n', b'\n', b'baz\n', b'\n', b'\n'], |
|
57 |
[b'foo\nbar\n\nbaz\n\n\n']) |
|
58 |
self.assertChunksToLines( |
|
59 |
[b'foobarbaz'], [b'foobarbaz'], alreadly_lines=True) |
|
60 |
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. |
61 |
|
62 |
def test_newlines(self): |
|
|
6684.1.2
by Martin
Make _chunks_to_lines pass for Python 3 |
63 |
self.assertChunksToLines([b'\n'], [b'\n'], alreadly_lines=True) |
64 |
self.assertChunksToLines([b'\n'], [b'', b'\n', b'']) |
|
65 |
self.assertChunksToLines([b'\n'], [b'\n', b'']) |
|
66 |
self.assertChunksToLines([b'\n'], [b'', b'\n']) |
|
67 |
self.assertChunksToLines([b'\n', b'\n', b'\n'], [b'\n\n\n']) |
|
68 |
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. |
69 |
alreadly_lines=True) |
|
3890.2.8
by John Arbash Meinel
Move everything into properly parameterized tests. |
70 |
|
71 |
def test_lines_to_lines(self): |
|
|
6684.1.2
by Martin
Make _chunks_to_lines pass for Python 3 |
72 |
self.assertChunksToLines([b'foo\n', b'bar\r\n', b'ba\rz\n'], |
73 |
[b'foo\n', b'bar\r\n', b'ba\rz\n'], |
|
|
3890.2.8
by John Arbash Meinel
Move everything into properly parameterized tests. |
74 |
alreadly_lines=True) |
75 |
||
76 |
def test_no_final_newline(self): |
|
|
6684.1.2
by Martin
Make _chunks_to_lines pass for Python 3 |
77 |
self.assertChunksToLines([b'foo\n', b'bar\r\n', b'ba\rz'], |
78 |
[b'foo\nbar\r\nba\rz']) |
|
79 |
self.assertChunksToLines([b'foo\n', b'bar\r\n', b'ba\rz'], |
|
80 |
[b'foo\n', b'bar\r\n', b'ba\rz'], |
|
|
3890.2.8
by John Arbash Meinel
Move everything into properly parameterized tests. |
81 |
alreadly_lines=True) |
|
6684.1.2
by Martin
Make _chunks_to_lines pass for Python 3 |
82 |
self.assertChunksToLines((b'foo\n', b'bar\r\n', b'ba\rz'), |
83 |
(b'foo\n', b'bar\r\n', b'ba\rz'), |
|
|
3890.2.8
by John Arbash Meinel
Move everything into properly parameterized tests. |
84 |
alreadly_lines=True) |
85 |
self.assertChunksToLines([], [], alreadly_lines=True) |
|
|
6684.1.2
by Martin
Make _chunks_to_lines pass for Python 3 |
86 |
self.assertChunksToLines([b'foobarbaz'], [b'foobarbaz'], |
|
3890.2.8
by John Arbash Meinel
Move everything into properly parameterized tests. |
87 |
alreadly_lines=True) |
|
6684.1.2
by Martin
Make _chunks_to_lines pass for Python 3 |
88 |
self.assertChunksToLines([], [b'']) |
|
3890.2.8
by John Arbash Meinel
Move everything into properly parameterized tests. |
89 |
|
90 |
def test_mixed(self): |
|
|
6684.1.2
by Martin
Make _chunks_to_lines pass for Python 3 |
91 |
self.assertChunksToLines([b'foo\n', b'bar\r\n', b'ba\rz'], |
92 |
[b'foo\n', b'bar\r\nba\r', b'z']) |
|
93 |
self.assertChunksToLines([b'foo\n', b'bar\r\n', b'ba\rz'], |
|
94 |
[b'foo\nb', b'a', b'r\r\nba\r', b'z']) |
|
95 |
self.assertChunksToLines([b'foo\n', b'bar\r\n', b'ba\rz'], |
|
96 |
[b'foo\nbar\r\nba', b'\r', b'z']) |
|
|
3890.2.8
by John Arbash Meinel
Move everything into properly parameterized tests. |
97 |
|
|
6684.1.2
by Martin
Make _chunks_to_lines pass for Python 3 |
98 |
self.assertChunksToLines([b'foo\n', b'bar\r\n', b'ba\rz'], |
99 |
[b'foo\n', b'', b'bar\r\nba', b'\r', b'z']) |
|
100 |
self.assertChunksToLines([b'foo\n', b'bar\r\n', b'ba\rz\n'], |
|
101 |
[b'foo\n', b'bar\r\n', b'ba\rz\n', b'']) |
|
102 |
self.assertChunksToLines([b'foo\n', b'bar\r\n', b'ba\rz\n'], |
|
103 |
[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. |
104 |
|
105 |
def test_not_lines(self): |
|
106 |
# We should raise a TypeError, not crash
|
|
107 |
self.assertRaises(TypeError, self.module.chunks_to_lines, |
|
108 |
object()) |
|
109 |
self.assertRaises(TypeError, self.module.chunks_to_lines, |
|
110 |
[object()]) |
|
111 |
self.assertRaises(TypeError, self.module.chunks_to_lines, |
|
|
6684.1.2
by Martin
Make _chunks_to_lines pass for Python 3 |
112 |
[b'foo', object()]) |