~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_rio.py

(jameinel) Allow 'bzr serve' to interpret SIGHUP as a graceful shutdown.
 (bug #795025) (John A Meinel)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2007, 2009, 2010, 2011 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
"""Tests for rio serialization
18
18
 
22
22
but this depends on the transport.
23
23
"""
24
24
 
25
 
import cStringIO
26
 
import os
27
25
import re
28
 
import sys
29
26
from tempfile import TemporaryFile
30
27
 
31
28
from bzrlib import (
32
29
    rio,
33
30
    )
34
 
from bzrlib.tests import TestCaseInTempDir, TestCase
35
 
from bzrlib.rio import (RioWriter, Stanza, read_stanza, read_stanzas, rio_file,
36
 
                        RioReader)
 
31
from bzrlib.tests import TestCase
 
32
from bzrlib.rio import (
 
33
    RioReader,
 
34
    Stanza,
 
35
    read_stanza,
 
36
    read_stanzas,
 
37
    rio_file,
 
38
    )
37
39
 
38
40
 
39
41
class TestRio(TestCase):
54
56
        # these aren't enforced at construction time
55
57
        ## self.assertRaises(ValueError,
56
58
        ##        Stanza, complex=42 + 3j)
57
 
        ## self.assertRaises(ValueError, 
 
59
        ## self.assertRaises(ValueError,
58
60
        ##        Stanza, several=range(10))
59
61
 
60
62
    def test_empty_value(self):
123
125
    def test_repeated_field(self):
124
126
        """Repeated field in rio"""
125
127
        s = Stanza()
126
 
        for k, v in [('a', '10'), ('b', '20'), ('a', '100'), ('b', '200'), 
 
128
        for k, v in [('a', '10'), ('b', '20'), ('a', '100'), ('b', '200'),
127
129
                     ('a', '1000'), ('b', '2000')]:
128
130
            s.add(k, v)
129
131
        s2 = read_stanza(s.to_lines())
141
143
    def test_blank_line(self):
142
144
        s = Stanza(none='', one='\n', two='\n\n')
143
145
        self.assertEqualDiff(s.to_string(), """\
144
 
none: 
145
 
one: 
 
146
none:\x20
 
147
one:\x20
146
148
\t
147
 
two: 
 
149
two:\x20
148
150
\t
149
151
\t
150
152
""")
154
156
    def test_whitespace_value(self):
155
157
        s = Stanza(space=' ', tabs='\t\t\t', combo='\n\t\t\n')
156
158
        self.assertEqualDiff(s.to_string(), """\
157
 
combo: 
 
159
combo:\x20
158
160
\t\t\t
159
161
\t
160
 
space:  
 
162
space:\x20\x20
161
163
tabs: \t\t\t
162
164
""")
163
165
        s2 = read_stanza(s.to_lines())
166
168
 
167
169
    def test_quoted(self):
168
170
        """rio quoted string cases"""
169
 
        s = Stanza(q1='"hello"', 
170
 
                   q2=' "for', 
 
171
        s = Stanza(q1='"hello"',
 
172
                   q2=' "for',
171
173
                   q3='\n\n"for"\n',
172
174
                   q4='for\n"\nfor',
173
175
                   q5='\n',
174
 
                   q6='"', 
 
176
                   q6='"',
175
177
                   q7='""',
176
178
                   q8='\\',
177
179
                   q9='\\"\\"',
187
189
        s = read_stanza([])
188
190
        self.assertEqual(s, None)
189
191
        self.assertTrue(s is None)
190
 
        
 
192
 
 
193
    def test_read_nul_byte(self):
 
194
        """File consisting of a nul byte causes an error."""
 
195
        self.assertRaises(ValueError, read_stanza, ['\0'])
 
196
 
 
197
    def test_read_nul_bytes(self):
 
198
        """File consisting of many nul bytes causes an error."""
 
199
        self.assertRaises(ValueError, read_stanza, ['\0' * 100])
 
200
 
191
201
    def test_read_iter(self):
192
202
        """Read several stanzas from file"""
193
203
        tmpf = TemporaryFile()
204
214
        reader = read_stanzas(tmpf)
205
215
        read_iter = iter(reader)
206
216
        stuff = list(reader)
207
 
        self.assertEqual(stuff, 
 
217
        self.assertEqual(stuff,
208
218
                [ Stanza(version_header='1'),
209
219
                  Stanza(name="foo", val='123'),
210
220
                  Stanza(name="bar", val='129319'), ])
259
269
        tmpf.write('''\
260
270
s: "one"
261
271
 
262
 
s: 
 
272
s:\x20
263
273
\t"one"
264
274
\t
265
275
 
269
279
 
270
280
s: """
271
281
 
272
 
s: 
 
282
s:\x20
273
283
\t
274
284
 
275
285
s: \\
276
286
 
277
 
s: 
 
287
s:\x20
278
288
\t\\
279
289
\t\\\\
280
290
\t